Skip to content

Commit 8009fad

Browse files
committed
[CLIENT] Add tests showing IPv6 host specified when creating client
1 parent 1242567 commit 8009fad

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

elasticsearch-transport/spec/elasticsearch/transport/client_spec.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,30 @@
141141
expect(hosts[0][:port]).to be(9200)
142142
end
143143

144+
context 'when IPv6 format is used' do
145+
146+
around do |example|
147+
original_setting = Faraday.ignore_env_proxy
148+
Faraday.ignore_env_proxy = true
149+
example.run
150+
Faraday.ignore_env_proxy = original_setting
151+
end
152+
153+
let(:host) do
154+
'https://[2090:db8:85a3:9811::1f]:8080'
155+
end
156+
157+
it 'extracts the host' do
158+
expect(hosts[0][:host]).to eq('[2090:db8:85a3:9811::1f]')
159+
expect(hosts[0][:scheme]).to eq('https')
160+
expect(hosts[0][:port]).to be(8080)
161+
end
162+
163+
it 'creates the correct full url' do
164+
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://[2090:db8:85a3:9811::1f]:8080')
165+
end
166+
end
167+
144168
context 'when a path is specified' do
145169

146170
let(:host) do
@@ -222,6 +246,53 @@
222246
expect(hosts[0][:port]).to be(9200)
223247
end
224248

249+
context 'when IPv6 format is used' do
250+
251+
around do |example|
252+
original_setting = Faraday.ignore_env_proxy
253+
Faraday.ignore_env_proxy = true
254+
example.run
255+
Faraday.ignore_env_proxy = original_setting
256+
end
257+
258+
let(:host) do
259+
{ host: '[2090:db8:85a3:9811::1f]', scheme: 'https', port: '443' }
260+
end
261+
262+
it 'extracts the host' do
263+
expect(hosts[0][:host]).to eq('[2090:db8:85a3:9811::1f]')
264+
expect(hosts[0][:scheme]).to eq('https')
265+
expect(hosts[0][:port]).to be(443)
266+
end
267+
268+
it 'creates the correct full url' do
269+
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://[2090:db8:85a3:9811::1f]:443')
270+
end
271+
end
272+
273+
context 'when the host is localhost as a IPv6 address' do
274+
275+
around do |example|
276+
original_setting = Faraday.ignore_env_proxy
277+
Faraday.ignore_env_proxy = true
278+
example.run
279+
Faraday.ignore_env_proxy = original_setting
280+
end
281+
282+
let(:host) do
283+
{ host: '[::1]' }
284+
end
285+
286+
it 'extracts the host' do
287+
expect(hosts[0][:host]).to eq('[::1]')
288+
expect(hosts[0][:port]).to be(9200)
289+
end
290+
291+
it 'creates the correct full url' do
292+
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('http://[::1]:9200')
293+
end
294+
end
295+
225296
context 'when the port is specified as a String' do
226297

227298
let(:host) do

0 commit comments

Comments
 (0)