spec/elasticsearch/transport/client_spec.rb in elasticsearch-transport-7.13.3 vs spec/elasticsearch/transport/client_spec.rb in elasticsearch-transport-7.14.0.pre
- old
+ new
@@ -22,14 +22,10 @@
described_class.new.tap do |_client|
allow(_client).to receive(:__build_connections)
end
end
- it 'is aliased as Elasticsearch::Client' do
- expect(Elasticsearch::Client.new).to be_a(described_class)
- end
-
it 'has a default transport' do
expect(client.transport).to be_a(Elasticsearch::Transport::Client::DEFAULT_TRANSPORT_CLASS)
end
it 'preserves the Faraday default user agent header' do
@@ -229,17 +225,18 @@
end
end
describe 'adapter' do
context 'when no adapter is specified' do
- let(:adapter) do
- client.transport.connections.all.first.connection.builder.adapter
- end
+ fork do
+ let(:client) { described_class.new }
+ let(:adapter) { client.transport.connections.all.first.connection.builder.adapter }
- it 'uses Faraday NetHttp' do
- expect(adapter).to eq Faraday::Adapter::NetHttp
- end
+ it 'uses Faraday NetHttp' do
+ expect(adapter).to eq Faraday::Adapter::NetHttp
+ end
+ end unless jruby?
end
context 'when the adapter is patron' do
let(:adapter) do
client.transport.connections.all.first.connection.builder.adapter
@@ -1414,18 +1411,18 @@
context 'when using an API call' do
let(:client) { described_class.new(host: hosts) }
it 'doesnae raise an ArgumentError' do
- expect { client.search(opaque_id: 'no_error') }.not_to raise_error
+ expect { client.perform_request('GET', '_search', opaque_id: 'no_error') }.not_to raise_error
end
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.perform_request('GET', '_search', {}, nil, 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', {}, nil, { opaque_id: 'opaque_id' })
end
end
end
context 'when using the API Compatibility Header' do
@@ -1498,11 +1495,11 @@
let(:client) { described_class.new(host: hosts) }
let(:headers) { { 'user-agent' => 'my ruby app' } }
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.perform_request('GET', '_search', {}, nil, headers) }.not_to raise_error
expect(client).to have_received(:perform_request)
.with('GET', '_search', {}, nil, headers)
end
end
@@ -1512,20 +1509,20 @@
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'}}
+ 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)
+ client.perform_request('GET', '_search', {}, nil, param_headers)
end
end
end
context 'when the client connects to Elasticsearch' do
@@ -1558,24 +1555,21 @@
let(:client) do
described_class.new({ host: hosts, logger: logger }.merge!(transport_options: transport_options).merge!(options))
end
context 'when a request is made' do
-
let!(:response) do
client.perform_request('GET', '_cluster/health')
end
it 'connects to the cluster' do
expect(response.body['number_of_nodes']).to be >= (1)
end
end
describe '#initialize' do
-
context 'when options are specified' do
-
let(:transport_options) do
{ headers: { accept: 'application/yaml', content_type: 'application/yaml' } }
end
let(:response) do
@@ -1587,13 +1581,12 @@
expect(response.headers['content-type']).to eq('application/yaml')
end
end
context 'when a block is provided' do
-
let(:client) do
- Elasticsearch::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
+ described_class.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
client.headers['Accept'] = 'application/yaml'
end
end
let(:response) do
@@ -1605,11 +1598,11 @@
expect(response.headers['content-type']).to eq('application/yaml')
end
context 'when the Faraday adapter is set in the block' do
let(:client) do
- Elasticsearch::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
+ described_class.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
client.adapter(:net_http_persistent)
end
end
let(:handler_name) do
@@ -1819,15 +1812,16 @@
end unless jruby?
end
end
context 'when using Curb as the transport', unless: jruby? do
-
let(:client) do
- described_class.new(hosts: ELASTICSEARCH_HOSTS,
- compression: true,
- transport_class: Elasticsearch::Transport::Transport::HTTP::Curb)
+ described_class.new(
+ hosts: ELASTICSEARCH_HOSTS,
+ compression: true,
+ transport_class: Elasticsearch::Transport::Transport::HTTP::Curb
+ )
end
it 'compresses the request and decompresses the response' do
expect(client.perform_request('GET', '/').body).to be_a(Hash)
end
@@ -1840,11 +1834,10 @@
expect(client.transport.connections[0].connection.headers['User-Agent'])
end
end
context 'when using Manticore as the transport', if: jruby? do
-
let(:client) do
described_class.new(hosts: ELASTICSEARCH_HOSTS,
compression: true,
transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore)
end
@@ -1854,13 +1847,11 @@
end
end
end
describe '#perform_request' do
-
context 'when a request is made' do
-
before do
client.perform_request('DELETE', '_all')
client.perform_request('DELETE', 'myindex') rescue
client.perform_request('PUT', 'myindex', {}, { settings: { number_of_shards: 2, number_of_replicas: 0 } })
client.perform_request('PUT', 'myindex/mydoc/1', { routing: 'XYZ', timeout: '1s' }, { foo: 'bar' })
@@ -1879,20 +1870,18 @@
expect(response.body['_source']).to eq('foo' => 'bar')
end
end
context 'when an invalid url is specified' do
-
it 'raises an exception' do
expect {
client.perform_request('GET', 'myindex/mydoc/1?routing=FOOBARBAZ')
}.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
end
end
context 'when the \'ignore\' parameter is specified' do
-
let(:response) do
client.perform_request('PUT', '_foobar', ignore: 400)
end
it 'exposes the status in the response' do
@@ -1925,11 +1914,11 @@
client.perform_request('GET', '_nodes/_local').body['nodes'].to_a[0][1]['name']
end
end
let(:node_names) do
- client.nodes.stats['nodes'].collect do |name, stats|
+ client.perform_request('GET', '_nodes/stats').body('nodes').collect do |name, stats|
stats['name']
end
end
let(:expected_names) do
@@ -1944,10 +1933,9 @@
# end
end
end
context 'when patron is used as an adapter', unless: jruby? do
-
before do
require 'patron'
end
let(:options) do