Skip to content

Commit 8714d88

Browse files
committed
Extended test suite to cover all the cases as in originating PR
1 parent 22bac47 commit 8714d88

File tree

1 file changed

+69
-24
lines changed

1 file changed

+69
-24
lines changed

spec/unit/outputs/elasticsearch_spec.rb

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -275,61 +275,106 @@
275275
let(:event_fields) {{}}
276276
let(:event) { LogStash::Event.new(event_fields)}
277277

278-
context "which contains version field" do
279-
# defines an event with version in the integration metadata section
280-
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"version" => "456"}}}) }
278+
context "when plugin's version is specified" do
279+
let(:options) { super().merge("version" => "123")}
281280

282-
context "when version is also specified in plugin settings" do
283-
let(:options) { super().merge("version" => "123")}
281+
context "when the event contains an integration metadata version" do
282+
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"version" => "456"}}}) }
284283

285-
it "takes precedence over the integration one" do
284+
it "plugin's version is used" do
286285
expect(subject.send(:event_action_tuple, event)[1]).to include(:version => "123")
287286
end
288287
end
289288

290-
context "when version is not defined in plugin settings" do
291-
it "must use the value from the integration's metadata" do
289+
context "when the event DOESN'T contains an integration metadata version" do
290+
it "plugin's version is used" do
291+
expect(subject.send(:event_action_tuple, event)[1]).to include(:version => "123")
292+
end
293+
end
294+
end
295+
296+
context "when plugin's version is NOT specified" do
297+
context "when the event contains an integration metadata version" do
298+
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"version" => "456"}}}) }
299+
300+
it "event's metadata version is used" do
292301
expect(subject.send(:event_action_tuple, event)[1]).to include(:version => "456")
293302
end
294303
end
304+
305+
context "when the event DOESN'T contain an integration metadata version" do
306+
it "plugin's default id mechanism is used" do
307+
expect(subject.send(:event_action_tuple, event)[1]).to include(:version => nil)
308+
end
309+
end
295310
end
296311

297-
context "which contains version_type field" do
298-
# defines an event with version_type in the integration metadata section
299-
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"version_type" => "external"}}}) }
312+
context "when plugin's version_type is specified" do
313+
let(:options) { super().merge("version_type" => "internal")}
300314

301-
context "when version_type is also specified in plugin settings" do
302-
let(:options) { super().merge("version_type" => "internal")}
315+
context "when the event contains an integration metadata version_type" do
316+
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"version_type" => "external"}}}) }
303317

304-
it "takes precedence over the integration one" do
318+
it "plugin's version_type is used" do
305319
expect(subject.send(:event_action_tuple, event)[1]).to include(:version_type => "internal")
306320
end
307321
end
308322

309-
context "when version_type is not defined in plugin settings" do
310-
it "must use the value from the integration's metadata" do
323+
context "when the event DOESN'T contains an integration metadata version_type" do
324+
it "plugin's version_type is used" do
325+
expect(subject.send(:event_action_tuple, event)[1]).to include(:version_type => "internal")
326+
end
327+
end
328+
end
329+
330+
context "when plugin's version_type is NOT specified" do
331+
context "when the event contains an integration metadata version_type" do
332+
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"version_type" => "external"}}}) }
333+
334+
it "event's metadata version_type is used" do
311335
expect(subject.send(:event_action_tuple, event)[1]).to include(:version_type => "external")
312336
end
313337
end
338+
339+
context "when the event DOESN'T contain an integration metadata version_type" do
340+
it "plugin's default id mechanism is used" do
341+
expect(subject.send(:event_action_tuple, event)[1]).to include(:version_type => nil)
342+
end
343+
end
314344
end
315345

316-
context "which contains routing field in its metadata" do
317-
# defines an event with routing in the integration metadata section
318-
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"routing" => "meta-document-routing"}}}) }
346+
context "when plugin's routing is specified" do
347+
let(:options) { super().merge("routing" => "settings_routing")}
319348

320-
context "when routing is specified in plugin settings" do
321-
let(:options) { super().merge("routing" => "settings_routing")}
349+
context "when the event contains an integration metadata routing" do
350+
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"routing" => "meta-document-routing"}}}) }
322351

323-
it "takes precedence over the integration one" do
352+
it "plugin's routing is used" do
324353
expect(subject.send(:event_action_tuple, event)[1]).to include(:routing => "settings_routing")
325354
end
326355
end
327356

328-
context "when routing is not defined in plugin settings" do
329-
it "must use the value from the integration's metadata" do
357+
context "when the event DOESN'T contains an integration metadata routing" do
358+
it "plugin's routing is used" do
359+
expect(subject.send(:event_action_tuple, event)[1]).to include(:routing => "settings_routing")
360+
end
361+
end
362+
end
363+
364+
context "when plugin's routing is NOT specified" do
365+
context "when the event contains an integration metadata routing" do
366+
let(:event) { LogStash::Event.new({"@metadata" => {"_ingest_document" => {"routing" => "meta-document-routing"}}}) }
367+
368+
it "event's metadata routing is used" do
330369
expect(subject.send(:event_action_tuple, event)[1]).to include(:routing => "meta-document-routing")
331370
end
332371
end
372+
373+
context "when the event DOESN'T contain an integration metadata routing" do
374+
it "plugin's default id mechanism is used" do
375+
expect(subject.send(:event_action_tuple, event)[1]).to include(:routing => nil)
376+
end
377+
end
333378
end
334379

335380
context "when plugin's index is specified" do

0 commit comments

Comments
 (0)