Skip to content

Commit 93b2887

Browse files
committed
Fix the unit test cases caused by #191
1 parent d9f216b commit 93b2887

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

spec/filters/elasticsearch_spec.rb

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@
6060
allow(plugin).to receive(:get_client).and_return(filter_client)
6161
allow(filter_client).to receive(:serverless?).and_return(true)
6262
allow(filter_client).to receive(:client).and_return(es_client)
63-
allow(es_client).to receive(:info).with(a_hash_including(:headers => LogStash::Filters::ElasticsearchClient::DEFAULT_EAV_HEADER)).and_raise(
64-
Elasticsearch::Transport::Transport::Errors::BadRequest.new
65-
)
63+
begin
64+
allow(es_client).to receive(:info)
65+
.with(a_hash_including(
66+
:headers => LogStash::Filters::ElasticsearchClient::DEFAULT_EAV_HEADER))
67+
.and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest.new)
68+
rescue NameError # we get NameError: uninitialized constant Elasticsearch::Transport with 7.x
69+
allow(es_client).to receive(:info)
70+
.with(a_hash_including(
71+
:headers => LogStash::Filters::ElasticsearchClient::DEFAULT_EAV_HEADER))
72+
.and_raise(Elastic::Transport::Transport::Errors::BadRequest.new)
73+
end
6674
end
6775

6876
it "raises an exception when Elastic Api Version is not supported" do
@@ -103,7 +111,13 @@
103111

104112
before(:each) do
105113
allow(LogStash::Filters::ElasticsearchClient).to receive(:new).and_return(client)
106-
allow(client).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
114+
begin
115+
require "elasticsearch/transport/transport/http/manticore"
116+
allow(client).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
117+
rescue LoadError
118+
require "elastic/transport/transport/http/manticore"
119+
allow(client).to receive(:es_transport_client_type).and_return('elastic_transport')
120+
end
107121
allow(client).to receive(:search).and_return(response)
108122
allow(plugin).to receive(:test_connection!)
109123
allow(plugin).to receive(:setup_serverless)
@@ -348,7 +362,12 @@
348362

349363
before do
350364
allow(plugin).to receive(:get_client).and_return(client_double)
351-
allow(client_double).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
365+
begin
366+
require "elasticsearch/transport/transport/http/manticore"
367+
allow(client_double).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
368+
rescue LoadError
369+
allow(client_double).to receive(:es_transport_client_type).and_return('elastic_transport')
370+
end
352371
allow(client_double).to receive(:client).and_return(transport_double)
353372
end
354373

@@ -508,7 +527,13 @@ def wait_receive_request
508527
# this spec is a safeguard to trigger an assessment of thread-safety should
509528
# we choose a different transport adapter in the future.
510529
transport_class = extract_transport(client).options.fetch(:transport_class)
511-
expect(transport_class).to equal ::Elasticsearch::Transport::Transport::HTTP::Manticore
530+
begin
531+
::Elasticsearch::Transport::Transport::HTTP::Manticore
532+
expect(transport_class).to equal ::Elasticsearch::Transport::Transport::HTTP::Manticore
533+
rescue NameError
534+
allow(client).to receive(:es_transport_client_type).and_return("elastic_transport")
535+
expect(transport_class).to equal ::Elastic::Transport::Transport::HTTP::Manticore
536+
end
512537
end
513538

514539
it 'uses a client with sufficient connection pool size' do
@@ -823,7 +848,12 @@ def wait_receive_request
823848

824849
before(:each) do
825850
allow(LogStash::Filters::ElasticsearchClient).to receive(:new).and_return(client)
826-
allow(client).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
851+
begin
852+
require "elasticsearch/transport/transport/http/manticore"
853+
allow(client).to receive(:es_transport_client_type).and_return('elasticsearch_transport')
854+
rescue LoadError
855+
allow(client).to receive(:es_transport_client_type).and_return('elastic_transport')
856+
end
827857
allow(plugin).to receive(:test_connection!)
828858
allow(plugin).to receive(:setup_serverless)
829859
plugin.register
@@ -839,7 +869,7 @@ def wait_receive_request
839869
end
840870

841871
# @note can be removed once gem depends on elasticsearch >= 6.x
842-
def extract_transport(client) # on 7.x client.transport is a ES::Transport::Client
872+
def extract_transport(client) # on >7.x client.transport is a ES::Transport::Client
843873
client.transport.respond_to?(:transport) ? client.transport.transport : client.transport
844874
end
845875

0 commit comments

Comments
 (0)