1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
# frozen_string_literal: true
Shindo.tests('Excon::Utils') do
tests('#connection_uri') do
expected_uri = 'unix:///tmp/some.sock'
tests('using UNIX scheme').returns(expected_uri) do
connection = Excon.new('unix:///some/path', socket: '/tmp/some.sock')
Excon::Utils.connection_uri(connection.data)
end
tests('using HTTP scheme') do
expected_uri = 'http://foo.com'
tests('without default port').returns(expected_uri) do
connection = Excon.new('http://foo.com/some/path')
Excon::Utils.connection_uri(connection.data)
end
expected_uri = 'http://foo.com:80'
tests('include_default_port adds default port').returns(expected_uri) do
connection = Excon.new('http://foo.com/some/path', include_default_port: true)
Excon::Utils.connection_uri(connection.data)
end
expected_uri = 'http://foo.com'
tests('!include_default_port has no port value').returns(expected_uri) do
connection = Excon.new('http://foo.com/some/path', include_default_port: false)
Excon::Utils.connection_uri(connection.data)
end
expected_uri = 'http://foo.com'
tests('omit_default_port has no port value').returns(expected_uri) do
connection = Excon.new('http://foo.com/some/path', omit_default_port: true)
Excon::Utils.connection_uri(connection.data)
end
end
end
tests('#request_uri') do
tests('using UNIX scheme') do
expected_uri = 'unix:///tmp/some.sock/some/path'
tests('without query').returns(expected_uri) do
connection = Excon.new('unix:/', :socket => '/tmp/some.sock')
params = { :path => '/some/path' }
Excon::Utils.request_uri(connection.data.merge(params))
end
expected_uri = 'unix:///tmp/some.sock/some/path?bar=that&foo=this'
tests('with query').returns(expected_uri) do
connection = Excon.new('unix:/', :socket => '/tmp/some.sock')
params = { :path => '/some/path', :query => { :foo => 'this', :bar => 'that' } }
Excon::Utils.request_uri(connection.data.merge(params))
end
end
tests('using HTTP scheme') do
expected_uri = 'http://foo.com/some/path'
tests('without query').returns(expected_uri) do
connection = Excon.new('http://foo.com')
params = { :path => '/some/path' }
Excon::Utils.request_uri(connection.data.merge(params))
end
expected_uri = 'http://foo.com/some/path?bar=that&foo=this'
tests('with query').returns(expected_uri) do
connection = Excon.new('http://foo.com')
params = { :path => '/some/path', :query => { :foo => 'this', :bar => 'that' } }
Excon::Utils.request_uri(connection.data.merge(params))
end
end
test('detecting default ports') do
tests('http default port').returns true do
datum = {
scheme: 'http',
port: 80
}
Excon::Utils.default_port?(datum)
end
tests('http nonstandard port').returns false do
datum = {
scheme: 'http',
port: 9292
}
Excon::Utils.default_port?(datum)
end
tests('https standard port').returns true do
datum = {
scheme: 'https',
port: 443
}
Excon::Utils.default_port?(datum)
end
tests('https nonstandard port').returns false do
datum = {
scheme: 'https',
port: 8443
}
Excon::Utils.default_port?(datum)
end
tests('unix socket').returns false do
datum = {
scheme: 'unix'
}
Excon::Utils.default_port?(datum)
end
end
end
tests('#escape_uri').returns('/hello%20excon') do
Excon::Utils.escape_uri('/hello excon')
end
tests('#unescape_uri').returns('/hello excon') do
Excon::Utils.unescape_uri('/hello%20excon')
end
tests('#unescape_form').returns('message=We love excon!') do
Excon::Utils.unescape_form('message=We+love+excon!')
end
tests('#split_header_value').returns(["value"]) do
Excon::Utils.split_header_value("value")
end
tests('#split_header_value').returns(["value1", "value2"]) do
Excon::Utils.split_header_value("value1, value2")
end
tests('#split_header_value').returns(["text/html;q=0.5", "application/json; version=1"]) do
Excon::Utils.split_header_value("text/html;q=0.5, application/json; version=1")
end
tests('#split_header_value').returns(["foo/bar;key=\"A,B,C\""]) do
Excon::Utils.split_header_value("foo/bar;key=\"A,B,C\"")
end
tests('#split_header_value').returns([]) do
# previous implementation would hang on this, so test is here to prevent regression
Timeout.timeout(0.1) do
Excon::Utils.split_header_value("uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\",")
end
end
end
|