From 1aa45a4f879b2f7b9cd4c6577f619e7608548806 Mon Sep 17 00:00:00 2001 From: Charly Koza Date: Tue, 11 Oct 2022 15:15:31 +0200 Subject: [PATCH] test: add test with leading underscore from field conflicting with GELF fields See https://github.com/logstash-plugins/logstash-input-gelf/issues/25 --- spec/inputs/gelf_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/inputs/gelf_spec.rb b/spec/inputs/gelf_spec.rb index b2e0e03..0fa2e53 100644 --- a/spec/inputs/gelf_spec.rb +++ b/spec/inputs/gelf_spec.rb @@ -238,4 +238,38 @@ def client_bootstrap(gelfclient, queue) end end end + + describe "when handling complex messages" do + let(:host) { "127.0.0.1" } + let(:port) { 12211 } + let(:chunksize) { 1420 } + let(:gelfclient) { GELF::Notifier.new(host, port, chunksize) } + + let(:config) { { "port" => port, "host" => host } } + let(:queue) { Queue.new } + + subject(:gelf_input) { described_class.new(config) } + + before(:each) do + subject.register + @runner = Thread.new { subject.run(queue) } + + client_bootstrap(gelfclient, queue) + end + + after(:each) do + subject.do_stop + @runner.kill + @runner.join + end + + it "should not overwrite inner gelf fields" do + message = "level field conflicting with internal GELF level field" + gelfclient.notify!("short_message" => message, "_level" => "foo") + e = queue.pop + expect(e.get("message")).to eq(message) + # TODO fixme, level should contain a number and _level should keep the leading underscore + expect(e.get("level")).to eq("foo") + end + end end