mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-13 00:02:57 -04:00
added tests for connection refused behaviour
This commit is contained in:
parent
e16ea30b14
commit
d29b198d68
@ -14,6 +14,7 @@ class HTTPTest < Minitest::Test
|
||||
include ResponseBody
|
||||
include IO
|
||||
include Timeouts
|
||||
include Errors
|
||||
|
||||
include Plugins::Proxy
|
||||
include Plugins::Authentication
|
||||
@ -24,7 +25,7 @@ class HTTPTest < Minitest::Test
|
||||
|
||||
private
|
||||
|
||||
def origin
|
||||
"http://#{httpbin}"
|
||||
def origin(orig=httpbin)
|
||||
"http://#{orig}"
|
||||
end
|
||||
end
|
||||
|
@ -12,6 +12,7 @@ class HTTPSTest < Minitest::Test
|
||||
include ResponseBody
|
||||
include IO
|
||||
include Timeouts
|
||||
include Errors
|
||||
|
||||
include Plugins::Proxy
|
||||
include Plugins::Authentication
|
||||
@ -22,7 +23,7 @@ class HTTPSTest < Minitest::Test
|
||||
|
||||
private
|
||||
|
||||
def origin
|
||||
"https://#{httpbin}"
|
||||
def origin(orig=httpbin)
|
||||
"https://#{orig}"
|
||||
end
|
||||
end
|
||||
|
21
test/support/requests/errors.rb
Normal file
21
test/support/requests/errors.rb
Normal file
@ -0,0 +1,21 @@
|
||||
module Requests
|
||||
module Errors
|
||||
|
||||
def test_connection_refused
|
||||
unavailable_host = URI(origin('localhost'))
|
||||
unavailable_host.port = next_available_port
|
||||
response = HTTPX.get(unavailable_host.to_s)
|
||||
assert response.is_a?(HTTPX::ErrorResponse), "response should contain errors"
|
||||
assert response.status =~ /Connection refused/, "connection should have been refused"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def next_available_port
|
||||
server = TCPServer.new('localhost', 0)
|
||||
server.addr[1]
|
||||
ensure
|
||||
server.close
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user