spec/elasticsearch/transport/client_spec.rb in elasticsearch-transport-7.11.0.pre.1 vs spec/elasticsearch/transport/client_spec.rb in elasticsearch-transport-7.11.0
- old
+ new
@@ -1421,11 +1421,11 @@
it 'uses X-Opaque-Id in the header' do
allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
expect { client.search(opaque_id: 'opaque_id') }.not_to raise_error
expect(client).to have_received(:perform_request)
- .with('GET', '_search', { opaque_id: 'opaque_id' }, nil, {})
+ .with('GET', '_search', { opaque_id: 'opaque_id' }, nil, {})
end
end
end
context 'when Elasticsearch response includes a warning header' do
@@ -1460,10 +1460,31 @@
it 'performs the request with the header' do
allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
expect { client.search(headers: headers) }.not_to raise_error
expect(client).to have_received(:perform_request)
- .with('GET', '_search', {}, nil, headers)
+ .with('GET', '_search', {}, nil, headers)
+ end
+ end
+
+ context 'when a header is set on an endpoint request and on initialization' do
+ let!(:client) do
+ described_class.new(
+ host: hosts,
+ transport_options: { headers: instance_headers }
+ )
+ end
+ let(:instance_headers) { { set_in_instantiation: 'header value' } }
+ let(:param_headers) {{'user-agent' => 'My Ruby Tests', 'set-on-method-call' => 'header value'}}
+
+ it 'performs the request with the header' do
+ expected_headers = client.transport.connections.connections.first.connection.headers.merge(param_headers)
+
+ expect_any_instance_of(Faraday::Connection)
+ .to receive(:run_request)
+ .with(:get, "http://#{hosts[0]}/_search", nil, expected_headers) { OpenStruct.new(body: '')}
+
+ client.search(headers: param_headers)
end
end
end
context 'when the client connects to Elasticsearch' do