Skip to content

Commit fa81adc

Browse files
committed
[Client] Updates tests
1 parent 2c0fc1c commit fa81adc

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

elasticsearch/spec/unit/headers_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
2727
expect { client.search(headers: headers) }.not_to raise_error
2828
expect(client).to have_received(:perform_request)
29-
.with('GET', '_search', {}, nil, headers)
29+
.with('GET', '_search', {}, nil, headers)
3030
end
3131
end
3232

@@ -35,17 +35,19 @@
3535
described_class.new(
3636
host: 'http://localhost:9200',
3737
transport_options: { headers: instance_headers }
38-
)
38+
).tap do |client|
39+
client.instance_variable_set('@verified', true)
40+
end
3941
end
4042
let(:instance_headers) { { set_in_instantiation: 'header value' } }
41-
let(:param_headers) {{'user-agent' => 'My Ruby Tests', 'set-on-method-call' => 'header value'}}
43+
let(:param_headers) { { 'user-agent' => 'My Ruby Tests', 'set-on-method-call' => 'header value' } }
4244

4345
it 'performs the request with the header' do
4446
expected_headers = client.transport.connections.connections.first.connection.headers.merge(param_headers)
4547

4648
expect_any_instance_of(Faraday::Connection)
4749
.to receive(:run_request)
48-
.with(:get, "http://localhost:9200/_search", nil, expected_headers) { OpenStruct.new(body: '')}
50+
.with(:get, 'http://localhost:9200/_search', nil, expected_headers) { OpenStruct.new(body: '') }
4951

5052
client.search(headers: param_headers)
5153
end

elasticsearch/spec/unit/opaque_id_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
describe Elasticsearch::Client do
2121
let(:transport) { client.instance_variable_get('@transport') }
22-
let(:client) { described_class.new }
22+
let(:client) { described_class.new.tap { |cl| cl.instance_variable_set('@verified', true) } }
2323

2424
before do
2525
allow(transport).to receive(:perform_request) { OpenStruct.new(body: '') }
@@ -29,20 +29,20 @@
2929
it 'uses x-opaque-id on a request' do
3030
client.search(opaque_id: '12345')
3131
expect(transport).to have_received(:perform_request)
32-
.with('GET', '_search', {}, nil, { 'X-Opaque-Id' => '12345' })
32+
.with('GET', '_search', {}, nil, { 'X-Opaque-Id' => '12345' })
3333
end
3434
end
3535

3636
context 'when an x-opaque-id prefix is set on initialization' do
3737
let(:prefix) { 'elastic_cloud' }
3838
let(:client) do
39-
described_class.new(opaque_id_prefix: prefix)
39+
described_class.new(opaque_id_prefix: prefix).tap { |cl| cl.instance_variable_set('@verified', true) }
4040
end
4141

4242
it 'uses x-opaque-id on a request' do
4343
expect { client.search(opaque_id: '12345') }.not_to raise_error
4444
expect(transport).to have_received(:perform_request)
45-
.with('GET', '_search', {}, nil, { 'X-Opaque-Id' => 'elastic_cloud12345' })
45+
.with('GET', '_search', {}, nil, { 'X-Opaque-Id' => 'elastic_cloud12345' })
4646
end
4747
end
4848
end

0 commit comments

Comments
 (0)