added tests for connection refused behaviour

This commit is contained in:
HoneyryderChuck 2018-03-23 14:45:03 +00:00
parent e16ea30b14
commit d29b198d68
3 changed files with 27 additions and 4 deletions

View File

@ -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

View File

@ -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

View 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