Skip to content

Commit 7f8120c

Browse files
authored
Merge pull request #226 from mashhurs/fix-unit-test-failures-of-223
Fix the unit test failures caused by #223
2 parents b920701 + ac9660b commit 7f8120c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

spec/inputs/elasticsearch_spec.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
let(:es_version) { "7.5.0" }
2222
let(:cluster_info) { {"version" => {"number" => es_version, "build_flavor" => build_flavor}, "tagline" => "You Know, for Search"} }
2323

24+
def elastic_ruby_v8_client_available?
25+
Elasticsearch::Transport
26+
false
27+
rescue NameError # NameError: uninitialized constant Elasticsearch::Transport if Elastic Ruby client is not available
28+
true
29+
end
30+
2431
before(:each) do
2532
Elasticsearch::Client.send(:define_method, :ping) { } # define no-action ping method
2633
allow_any_instance_of(Elasticsearch::Client).to receive(:info).and_return(cluster_info)
@@ -92,9 +99,11 @@
9299

93100
before do
94101
allow(Elasticsearch::Client).to receive(:new).and_return(es_client)
95-
allow(es_client).to receive(:info).and_raise(
96-
Elasticsearch::Transport::Transport::Errors::BadRequest.new
97-
)
102+
if elastic_ruby_v8_client_available?
103+
allow(es_client).to receive(:info).and_raise(Elastic::Transport::Transport::Errors::BadRequest.new)
104+
else
105+
allow(es_client).to receive(:info).and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest.new)
106+
end
98107
end
99108

100109
it "raises an exception" do
@@ -744,8 +753,13 @@ def synchronize_method!(object, method_name)
744753
it "should set host(s)" do
745754
plugin.register
746755
client = plugin.send(:client)
747-
748-
expect( client.transport.instance_variable_get(:@seeds) ).to eql [{
756+
target_field = :@seeds
757+
begin
758+
Elasticsearch::Transport::Client
759+
rescue
760+
target_field = :@hosts
761+
end
762+
expect( client.transport.instance_variable_get(target_field) ).to eql [{
749763
:scheme => "https",
750764
:host => "ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io",
751765
:port => 9243,

0 commit comments

Comments
 (0)