refactor insist usage as a dependency

Fixes #2319
This commit is contained in:
Pere Urbon-Bayes 2015-01-06 18:19:00 +01:00 committed by Jordan Sissel
parent 7209eaec03
commit 45b39d6cb6
11 changed files with 266 additions and 272 deletions

View file

@ -69,7 +69,6 @@ Gem::Specification.new do |gem|
# These are runtime-deps so you can do 'java -jar logstash.jar rspec <test>' # These are runtime-deps so you can do 'java -jar logstash.jar rspec <test>'
gem.add_runtime_dependency "rspec", "~> 2.14.0" #(MIT license) gem.add_runtime_dependency "rspec", "~> 2.14.0" #(MIT license)
gem.add_runtime_dependency "insist", "1.0.0" #(Apache 2.0 license)
gem.add_runtime_dependency "logstash-devutils" gem.add_runtime_dependency "logstash-devutils"

View file

@ -63,24 +63,24 @@ describe "conditionals in filter" do
CONFIG CONFIG
sample({"foo" => "bar"}) do sample({"foo" => "bar"}) do
insist { subject["always"] } == "awesome" expect(subject["always"]).to eq("awesome")
insist { subject["hello"] } == "world" expect(subject["hello"]).to eq("world")
insist { subject["fancy"] }.nil? expect(subject["fancy"]).to be_nil
insist { subject["free"] }.nil? expect(subject["free"]).to be_nil
end end
sample({"notfoo" => "bar"}) do sample({"notfoo" => "bar"}) do
insist { subject["always"] } == "awesome" expect(subject["always"]).to eq("awesome")
insist { subject["hello"] }.nil? expect(subject["hello"]).to be_nil
insist { subject["fancy"] }.nil? expect(subject["fancy"]).to be_nil
insist { subject["free"] } == "hugs" expect(subject["free"]).to eq("hugs")
end end
sample({"bar" => "baz"}) do sample({"bar" => "baz"}) do
insist { subject["always"] } == "awesome" expect(subject["always"]).to eq("awesome")
insist { subject["hello"] }.nil? expect(subject["hello"]).to be_nil
insist { subject["fancy"] } == "pants" expect(subject["fancy"]).to eq("pants")
insist { subject["free"] }.nil? expect(subject["free"]).to be_nil
end end
end end
@ -101,31 +101,31 @@ describe "conditionals in filter" do
CONFIG CONFIG
sample("foo" => "bar", "nest" => 124) do sample("foo" => "bar", "nest" => 124) do
insist { subject["always"] }.nil? expect(subject["always"]).to be_nil
insist { subject["hello"] }.nil? expect(subject["hello"]).to be_nil
insist { subject["fancy"] }.nil? expect(subject["fancy"]).to be_nil
insist { subject["free"] }.nil? expect(subject["free"]).to be_nil
end end
sample("foo" => "bar", "nest" => 123) do sample("foo" => "bar", "nest" => 123) do
insist { subject["always"] } == "awesome" expect(subject["always"]).to eq("awesome")
insist { subject["hello"] } == "world" expect(subject["hello"]).to eq("world")
insist { subject["fancy"] }.nil? expect(subject["fancy"]).to be_nil
insist { subject["free"] }.nil? expect(subject["free"]).to be_nil
end end
sample("notfoo" => "bar", "nest" => 123) do sample("notfoo" => "bar", "nest" => 123) do
insist { subject["always"] } == "awesome" expect(subject["always"]).to eq("awesome")
insist { subject["hello"] }.nil? expect(subject["hello"]).to be_nil
insist { subject["fancy"] }.nil? expect(subject["fancy"]).to be_nil
insist { subject["free"] } == "hugs" expect(subject["free"]).to eq("hugs")
end end
sample("bar" => "baz", "nest" => 123) do sample("bar" => "baz", "nest" => 123) do
insist { subject["always"] } == "awesome" expect(subject["always"]).to eq("awesome")
insist { subject["hello"] }.nil? expect(subject["hello"]).to be_nil
insist { subject["fancy"] } == "pants" expect(subject["fancy"]).to eq("pants")
insist { subject["free"] }.nil? expect(subject["free"]).to be_nil
end end
end end
@ -139,7 +139,7 @@ describe "conditionals in filter" do
CONFIG CONFIG
sample("foo" => 123, "bar" => 123) do sample("foo" => 123, "bar" => 123) do
insist { subject["tags"] }.include?("woot") expect(subject["tags"] ).to include("woot")
end end
end end
@ -168,12 +168,12 @@ describe "conditionals in filter" do
CONFIG CONFIG
sample("foo" => "foo", "foobar" => "foobar", "greeting" => "hello world") do sample("foo" => "foo", "foobar" => "foobar", "greeting" => "hello world") do
insist { subject["tags"] }.include?("field in field") expect(subject["tags"]).to include("field in field")
insist { subject["tags"] }.include?("field in string") expect(subject["tags"]).to include("field in string")
insist { subject["tags"] }.include?("string in field") expect(subject["tags"]).to include("string in field")
insist { subject["tags"] }.include?("field in list") expect(subject["tags"]).to include("field in list")
reject { subject["tags"] }.include?("shouldnotexist") expect(subject["tags"]).not_to include("shouldnotexist")
insist { subject["tags"] }.include?("shouldexist") expect(subject["tags"]).to include("shouldexist")
end end
end end
@ -191,107 +191,107 @@ describe "conditionals in filter" do
sample("foo" => "foo", "somelist" => [ "one", "two" ], "foobar" => "foobar", "greeting" => "hello world", "tags" => [ "fancypantsy" ]) do sample("foo" => "foo", "somelist" => [ "one", "two" ], "foobar" => "foobar", "greeting" => "hello world", "tags" => [ "fancypantsy" ]) do
# verify the original exists # verify the original exists
insist { subject["tags"] }.include?("fancypantsy") expect(subject["tags"]).to include("fancypantsy")
insist { subject["tags"] }.include?("baz") expect(subject["tags"]).to include("baz")
reject { subject["tags"] }.include?("foo") expect(subject["tags"]).not_to include("foo")
insist { subject["tags"] }.include?("notfoo") expect(subject["tags"]).to include("notfoo")
insist { subject["tags"] }.include?("notsomelist") expect(subject["tags"]).to include("notsomelist")
reject { subject["tags"] }.include?("somelist") expect(subject["tags"]).not_to include("somelist")
insist { subject["tags"] }.include?("no string in missing field") expect(subject["tags"]).to include("no string in missing field")
end end
end end
describe "operators" do describe "operators" do
conditional "[message] == 'sample'" do conditional "[message] == 'sample'" do
sample("sample") { insist { subject["tags"] }.include?("success") } sample("sample") { expect(subject["tags"] ).to include("success") }
sample("different") { insist { subject["tags"] }.include?("failure") } sample("different") { expect(subject["tags"] ).to include("failure") }
end end
conditional "[message] != 'sample'" do conditional "[message] != 'sample'" do
sample("sample") { insist { subject["tags"] }.include?("failure") } sample("sample") { expect(subject["tags"] ).to include("failure") }
sample("different") { insist { subject["tags"] }.include?("success") } sample("different") { expect(subject["tags"] ).to include("success") }
end end
conditional "[message] < 'sample'" do conditional "[message] < 'sample'" do
sample("apple") { insist { subject["tags"] }.include?("success") } sample("apple") { expect(subject["tags"] ).to include("success") }
sample("zebra") { insist { subject["tags"] }.include?("failure") } sample("zebra") { expect(subject["tags"] ).to include("failure") }
end end
conditional "[message] > 'sample'" do conditional "[message] > 'sample'" do
sample("zebra") { insist { subject["tags"] }.include?("success") } sample("zebra") { expect(subject["tags"] ).to include("success") }
sample("apple") { insist { subject["tags"] }.include?("failure") } sample("apple") { expect(subject["tags"] ).to include("failure") }
end end
conditional "[message] <= 'sample'" do conditional "[message] <= 'sample'" do
sample("apple") { insist { subject["tags"] }.include?("success") } sample("apple") { expect(subject["tags"] ).to include("success") }
sample("zebra") { insist { subject["tags"] }.include?("failure") } sample("zebra") { expect(subject["tags"] ).to include("failure") }
sample("sample") { insist { subject["tags"] }.include?("success") } sample("sample") { expect(subject["tags"] ).to include("success") }
end end
conditional "[message] >= 'sample'" do conditional "[message] >= 'sample'" do
sample("zebra") { insist { subject["tags"] }.include?("success") } sample("zebra") { expect(subject["tags"] ).to include("success") }
sample("sample") { insist { subject["tags"] }.include?("success") } sample("sample") { expect(subject["tags"] ).to include("success") }
sample("apple") { insist { subject["tags"] }.include?("failure") } sample("apple") { expect(subject["tags"] ).to include("failure") }
end end
conditional "[message] =~ /sample/" do conditional "[message] =~ /sample/" do
sample("apple") { insist { subject["tags"] }.include?("failure") } sample("apple") { expect(subject["tags"] ).to include("failure") }
sample("sample") { insist { subject["tags"] }.include?("success") } sample("sample") { expect(subject["tags"] ).to include("success") }
sample("some sample") { insist { subject["tags"] }.include?("success") } sample("some sample") { expect(subject["tags"] ).to include("success") }
end end
conditional "[message] !~ /sample/" do conditional "[message] !~ /sample/" do
sample("apple") { insist { subject["tags"] }.include?("success") } sample("apple") { expect(subject["tags"]).to include("success") }
sample("sample") { insist { subject["tags"] }.include?("failure") } sample("sample") { expect(subject["tags"]).to include("failure") }
sample("some sample") { insist { subject["tags"] }.include?("failure") } sample("some sample") { expect(subject["tags"]).to include("failure") }
end end
end end
describe "negated expressions" do describe "negated expressions" do
conditional "!([message] == 'sample')" do conditional "!([message] == 'sample')" do
sample("sample") { reject { subject["tags"] }.include?("success") } sample("sample") { expect(subject["tags"]).not_to include("success") }
sample("different") { reject { subject["tags"] }.include?("failure") } sample("different") { expect(subject["tags"]).not_to include("failure") }
end end
conditional "!([message] != 'sample')" do conditional "!([message] != 'sample')" do
sample("sample") { reject { subject["tags"] }.include?("failure") } sample("sample") { expect(subject["tags"]).not_to include("failure") }
sample("different") { reject { subject["tags"] }.include?("success") } sample("different") { expect(subject["tags"]).not_to include("success") }
end end
conditional "!([message] < 'sample')" do conditional "!([message] < 'sample')" do
sample("apple") { reject { subject["tags"] }.include?("success") } sample("apple") { expect(subject["tags"]).not_to include("success") }
sample("zebra") { reject { subject["tags"] }.include?("failure") } sample("zebra") { expect(subject["tags"]).not_to include("failure") }
end end
conditional "!([message] > 'sample')" do conditional "!([message] > 'sample')" do
sample("zebra") { reject { subject["tags"] }.include?("success") } sample("zebra") { expect(subject["tags"]).not_to include("success") }
sample("apple") { reject { subject["tags"] }.include?("failure") } sample("apple") { expect(subject["tags"]).not_to include("failure") }
end end
conditional "!([message] <= 'sample')" do conditional "!([message] <= 'sample')" do
sample("apple") { reject { subject["tags"] }.include?("success") } sample("apple") { expect(subject["tags"]).not_to include("success") }
sample("zebra") { reject { subject["tags"] }.include?("failure") } sample("zebra") { expect(subject["tags"]).not_to include("failure") }
sample("sample") { reject { subject["tags"] }.include?("success") } sample("sample") { expect(subject["tags"]).not_to include("success") }
end end
conditional "!([message] >= 'sample')" do conditional "!([message] >= 'sample')" do
sample("zebra") { reject { subject["tags"] }.include?("success") } sample("zebra") { expect(subject["tags"]).not_to include("success") }
sample("sample") { reject { subject["tags"] }.include?("success") } sample("sample") { expect(subject["tags"]).not_to include("success") }
sample("apple") { reject { subject["tags"] }.include?("failure") } sample("apple") { expect(subject["tags"]).not_to include("failure") }
end end
conditional "!([message] =~ /sample/)" do conditional "!([message] =~ /sample/)" do
sample("apple") { reject { subject["tags"] }.include?("failure") } sample("apple") { expect(subject["tags"]).not_to include("failure") }
sample("sample") { reject { subject["tags"] }.include?("success") } sample("sample") { expect(subject["tags"]).not_to include("success") }
sample("some sample") { reject { subject["tags"] }.include?("success") } sample("some sample") { expect(subject["tags"]).not_to include("success") }
end end
conditional "!([message] !~ /sample/)" do conditional "!([message] !~ /sample/)" do
sample("apple") { reject { subject["tags"] }.include?("success") } sample("apple") { expect(subject["tags"]).not_to include("success") }
sample("sample") { reject { subject["tags"] }.include?("failure") } sample("sample") { expect(subject["tags"]).not_to include("failure") }
sample("some sample") { reject { subject["tags"] }.include?("failure") } sample("some sample") { expect(subject["tags"]).not_to include("failure") }
end end
end end
@ -299,47 +299,47 @@ describe "conditionals in filter" do
describe "value as an expression" do describe "value as an expression" do
# testing that a field has a value should be true. # testing that a field has a value should be true.
conditional "[message]" do conditional "[message]" do
sample("apple") { insist { subject["tags"] }.include?("success") } sample("apple") { expect(subject["tags"]).to include("success") }
sample("sample") { insist { subject["tags"] }.include?("success") } sample("sample") { expect(subject["tags"]).to include("success") }
sample("some sample") { insist { subject["tags"] }.include?("success") } sample("some sample") { expect(subject["tags"]).to include("success") }
end end
# testing that a missing field has a value should be false. # testing that a missing field has a value should be false.
conditional "[missing]" do conditional "[missing]" do
sample("apple") { insist { subject["tags"] }.include?("failure") } sample("apple") { expect(subject["tags"]).to include("failure") }
sample("sample") { insist { subject["tags"] }.include?("failure") } sample("sample") { expect(subject["tags"]).to include("failure") }
sample("some sample") { insist { subject["tags"] }.include?("failure") } sample("some sample") { expect(subject["tags"]).to include("failure") }
end end
end end
describe "logic operators" do describe "logic operators" do
describe "and" do describe "and" do
conditional "[message] and [message]" do conditional "[message] and [message]" do
sample("whatever") { insist { subject["tags"] }.include?("success") } sample("whatever") { expect(subject["tags"]).to include("success") }
end end
conditional "[message] and ![message]" do conditional "[message] and ![message]" do
sample("whatever") { insist { subject["tags"] }.include?("failure") } sample("whatever") { expect(subject["tags"]).to include("failure") }
end end
conditional "![message] and [message]" do conditional "![message] and [message]" do
sample("whatever") { insist { subject["tags"] }.include?("failure") } sample("whatever") { expect(subject["tags"]).to include("failure") }
end end
conditional "![message] and ![message]" do conditional "![message] and ![message]" do
sample("whatever") { insist { subject["tags"] }.include?("failure") } sample("whatever") { expect(subject["tags"]).to include("failure") }
end end
end end
describe "or" do describe "or" do
conditional "[message] or [message]" do conditional "[message] or [message]" do
sample("whatever") { insist { subject["tags"] }.include?("success") } sample("whatever") { expect(subject["tags"]).to include("success") }
end end
conditional "[message] or ![message]" do conditional "[message] or ![message]" do
sample("whatever") { insist { subject["tags"] }.include?("success") } sample("whatever") { expect(subject["tags"]).to include("success") }
end end
conditional "![message] or [message]" do conditional "![message] or [message]" do
sample("whatever") { insist { subject["tags"] }.include?("success") } sample("whatever") { expect(subject["tags"]).to include("success") }
end end
conditional "![message] or ![message]" do conditional "![message] or ![message]" do
sample("whatever") { insist { subject["tags"] }.include?("failure") } sample("whatever") { expect(subject["tags"]).to include("failure") }
end end
end end
end end
@ -347,19 +347,19 @@ describe "conditionals in filter" do
describe "field references" do describe "field references" do
conditional "[field with space]" do conditional "[field with space]" do
sample("field with space" => "hurray") do sample("field with space" => "hurray") do
insist { subject["tags"].include?("success") } expect(subject["tags"]).to include("success")
end end
end end
conditional "[field with space] == 'hurray'" do conditional "[field with space] == 'hurray'" do
sample("field with space" => "hurray") do sample("field with space" => "hurray") do
insist { subject["tags"].include?("success") } expect(subject["tags"]).to include("success")
end end
end end
conditional "[nested field][reference with][some spaces] == 'hurray'" do conditional "[nested field][reference with][some spaces] == 'hurray'" do
sample({"nested field" => { "reference with" => { "some spaces" => "hurray" } } }) do sample({"nested field" => { "reference with" => { "some spaces" => "hurray" } } }) do
insist { subject["tags"].include?("success") } expect(subject["tags"]).to include("success")
end end
end end
end end
@ -381,16 +381,16 @@ describe "conditionals in filter" do
CONFIG CONFIG
sample({"type" => "original"}) do sample({"type" => "original"}) do
insist { subject }.is_a?(Array) expect(subject).to be_an(Array)
insist { subject.length } == 2 expect(subject.length).to eq(2)
insist { subject[0]["type"] } == "original" expect(subject[0]["type"]).to eq("original")
insist { subject[0]["cond1"] } == "true" expect(subject[0]["cond1"]).to eq("true")
insist { subject[0]["cond2"] } == nil expect(subject[0]["cond2"]).to eq(nil)
insist { subject[1]["type"] } == "clone" expect(subject[1]["type"]).to eq("clone")
# insist { subject[1]["cond1"] } == nil # expect(subject[1]["cond1"]).to eq(nil)
# insist { subject[1]["cond2"] } == "true" # expect(subject[1]["cond2"]).to eq("true")
end end
end end
end end

View file

@ -16,7 +16,7 @@ describe LogStashConfigParser do
} }
)) ))
reject { config }.nil? expect(config).not_to be_nil
end end
it "should permit empty plugin sections" do it "should permit empty plugin sections" do
@ -26,6 +26,6 @@ describe LogStashConfigParser do
} }
)) ))
reject { config }.nil? expect(config).not_to be_nil
end end
end end

View file

@ -1,7 +1,6 @@
# encoding: utf-8 # encoding: utf-8
require "logstash/event" require "logstash/event"
require "insist"
describe LogStash::Event do describe LogStash::Event do
subject do subject do
@ -30,63 +29,63 @@ describe LogStash::Event do
context "[]=" do context "[]=" do
it "should raise an exception if you attempt to set @timestamp to a value type other than a Time object" do it "should raise an exception if you attempt to set @timestamp to a value type other than a Time object" do
insist { subject["@timestamp"] = "crash!" }.raises(TypeError) expect{subject["@timestamp"] = "crash!"}.to raise_error(TypeError)
end end
it "should assign simple fields" do it "should assign simple fields" do
insist { subject["foo"] }.nil? expect(subject["foo"]).to be_nil
insist { subject["foo"] = "bar" } == "bar" expect(subject["foo"] = "bar").to eq("bar")
insist { subject["foo"] } == "bar" expect(subject["foo"]).to eq("bar")
end end
it "should overwrite simple fields" do it "should overwrite simple fields" do
insist { subject["foo"] }.nil? expect(subject["foo"]).to be_nil
insist { subject["foo"] = "bar"} == "bar" expect(subject["foo"] = "bar").to eq("bar")
insist { subject["foo"] } == "bar" expect(subject["foo"]).to eq("bar")
insist { subject["foo"] = "baz"} == "baz" expect(subject["foo"] = "baz").to eq("baz")
insist { subject["foo"] } == "baz" expect(subject["foo"]).to eq("baz")
end end
it "should assign deep fields" do it "should assign deep fields" do
insist { subject["[foo][bar]"] }.nil? expect(subject["[foo][bar]"]).to be_nil
insist { subject["[foo][bar]"] = "baz"} == "baz" expect(subject["[foo][bar]"] = "baz").to eq("baz")
insist { subject["[foo][bar]"] } == "baz" expect(subject["[foo][bar]"]).to eq("baz")
end end
it "should overwrite deep fields" do it "should overwrite deep fields" do
insist { subject["[foo][bar]"] }.nil? expect(subject["[foo][bar]"]).to be_nil
insist { subject["[foo][bar]"] = "baz"} == "baz" expect(subject["[foo][bar]"] = "baz").to eq("baz")
insist { subject["[foo][bar]"] } == "baz" expect(subject["[foo][bar]"]).to eq("baz")
insist { subject["[foo][bar]"] = "zab"} == "zab" expect(subject["[foo][bar]"] = "zab").to eq("zab")
insist { subject["[foo][bar]"] } == "zab" expect(subject["[foo][bar]"]).to eq("zab")
end end
end end
context "#sprintf" do context "#sprintf" do
it "should report a unix timestamp for %{+%s}" do it "should report a unix timestamp for %{+%s}" do
insist { subject.sprintf("%{+%s}") } == "1356998400" expect(subject.sprintf("%{+%s}")).to eq("1356998400")
end end
it "should report a time with %{+format} syntax", :if => RUBY_ENGINE == "jruby" do it "should report a time with %{+format} syntax", :if => RUBY_ENGINE == "jruby" do
insist { subject.sprintf("%{+YYYY}") } == "2013" expect(subject.sprintf("%{+YYYY}")).to eq("2013")
insist { subject.sprintf("%{+MM}") } == "01" expect(subject.sprintf("%{+MM}")).to eq("01")
insist { subject.sprintf("%{+HH}") } == "00" expect(subject.sprintf("%{+HH}")).to eq("00")
end end
it "should report fields with %{field} syntax" do it "should report fields with %{field} syntax" do
insist { subject.sprintf("%{type}") } == "sprintf" expect(subject.sprintf("%{type}")).to eq("sprintf")
insist { subject.sprintf("%{message}") } == subject["message"] expect(subject.sprintf("%{message}")).to eq(subject["message"])
end end
it "should print deep fields" do it "should print deep fields" do
insist { subject.sprintf("%{[j][k1]}") } == "v" expect(subject.sprintf("%{[j][k1]}")).to eq("v")
insist { subject.sprintf("%{[j][k2][0]}") } == "w" expect(subject.sprintf("%{[j][k2][0]}")).to eq("w")
end end
it "should be able to take a non-string for the format" do it "should be able to take a non-string for the format" do
insist { subject.sprintf(2) } == "2" expect(subject.sprintf(2)).to eq("2")
end end
it "should allow to use the metadata when calling #sprintf" do it "should allow to use the metadata when calling #sprintf" do
@ -100,18 +99,18 @@ describe LogStash::Event do
context "#[]" do context "#[]" do
it "should fetch data" do it "should fetch data" do
insist { subject["type"] } == "sprintf" expect(subject["type"]).to eq("sprintf")
end end
it "should fetch fields" do it "should fetch fields" do
insist { subject["a"] } == "b" expect(subject["a"]).to eq("b")
insist { subject['c']['d'] } == "f" expect(subject['c']['d']).to eq("f")
end end
it "should fetch deep fields" do it "should fetch deep fields" do
insist { subject["[j][k1]"] } == "v" expect(subject["[j][k1]"]).to eq("v")
insist { subject["[c][d]"] } == "f" expect(subject["[c][d]"]).to eq("f")
insist { subject['[f][g][h]'] } == "i" expect(subject['[f][g][h]']).to eq("i")
insist { subject['[j][k3][4]'] } == "m" expect(subject['[j][k3][4]']).to eq("m")
insist { subject['[j][5]'] } == 7 expect(subject['[j][5]']).to eq(7)
end end
@ -134,11 +133,11 @@ describe LogStash::Event do
) )
subject.overwrite(new_event) subject.overwrite(new_event)
insist { subject["message"] } == "foo bar" expect(subject["message"]).to eq("foo bar")
insist { subject["type"] } == "new" expect(subject["type"]).to eq("new")
["tags", "source", "a", "c", "f", "j"].each do |field| ["tags", "source", "a", "c", "f", "j"].each do |field|
insist { subject[field] } == nil expect(subject[field]).to be_nil
end end
end end
end end
@ -146,22 +145,22 @@ describe LogStash::Event do
context "#append" do context "#append" do
it "should append strings to an array" do it "should append strings to an array" do
subject.append(LogStash::Event.new("message" => "another thing")) subject.append(LogStash::Event.new("message" => "another thing"))
insist { subject["message"] } == [ "hello world", "another thing" ] expect(subject["message"]).to eq([ "hello world", "another thing" ])
end end
it "should concatenate tags" do it "should concatenate tags" do
subject.append(LogStash::Event.new("tags" => [ "tag2" ])) subject.append(LogStash::Event.new("tags" => [ "tag2" ]))
insist { subject["tags"] } == [ "tag1", "tag2" ] expect(subject["tags"]).to eq([ "tag1", "tag2" ])
end end
context "when event field is nil" do context "when event field is nil" do
it "should add single value as string" do it "should add single value as string" do
subject.append(LogStash::Event.new({"field1" => "append1"})) subject.append(LogStash::Event.new({"field1" => "append1"}))
insist { subject[ "field1" ] } == "append1" expect(subject[ "field1" ]).to eq("append1")
end end
it "should add multi values as array" do it "should add multi values as array" do
subject.append(LogStash::Event.new({"field1" => [ "append1","append2" ]})) subject.append(LogStash::Event.new({"field1" => [ "append1","append2" ]}))
insist { subject[ "field1" ] } == [ "append1","append2" ] expect(subject[ "field1" ]).to eq([ "append1","append2" ])
end end
end end
@ -170,19 +169,19 @@ describe LogStash::Event do
it "should append string to values, if different from current" do it "should append string to values, if different from current" do
subject.append(LogStash::Event.new({"field1" => "append1"})) subject.append(LogStash::Event.new({"field1" => "append1"}))
insist { subject[ "field1" ] } == [ "original1", "append1" ] expect(subject[ "field1" ]).to eq([ "original1", "append1" ])
end end
it "should not change value, if appended value is equal current" do it "should not change value, if appended value is equal current" do
subject.append(LogStash::Event.new({"field1" => "original1"})) subject.append(LogStash::Event.new({"field1" => "original1"}))
insist { subject[ "field1" ] } == "original1" expect(subject[ "field1" ]).to eq("original1")
end end
it "should concatenate values in an array" do it "should concatenate values in an array" do
subject.append(LogStash::Event.new({"field1" => [ "append1" ]})) subject.append(LogStash::Event.new({"field1" => [ "append1" ]}))
insist { subject[ "field1" ] } == [ "original1", "append1" ] expect(subject[ "field1" ]).to eq([ "original1", "append1" ])
end end
it "should join array, removing duplicates" do it "should join array, removing duplicates" do
subject.append(LogStash::Event.new({"field1" => [ "append1","original1" ]})) subject.append(LogStash::Event.new({"field1" => [ "append1","original1" ]}))
insist { subject[ "field1" ] } == [ "original1", "append1" ] expect(subject[ "field1" ]).to eq([ "original1", "append1" ])
end end
end end
context "when event field is an array" do context "when event field is an array" do
@ -190,15 +189,15 @@ describe LogStash::Event do
it "should append string values to array, if not present in array" do it "should append string values to array, if not present in array" do
subject.append(LogStash::Event.new({"field1" => "append1"})) subject.append(LogStash::Event.new({"field1" => "append1"}))
insist { subject[ "field1" ] } == [ "original1", "original2", "append1" ] expect(subject[ "field1" ]).to eq([ "original1", "original2", "append1" ])
end end
it "should not append string values, if the array already contains it" do it "should not append string values, if the array already contains it" do
subject.append(LogStash::Event.new({"field1" => "original1"})) subject.append(LogStash::Event.new({"field1" => "original1"}))
insist { subject[ "field1" ] } == [ "original1", "original2" ] expect(subject[ "field1" ]).to eq([ "original1", "original2" ])
end end
it "should join array, removing duplicates" do it "should join array, removing duplicates" do
subject.append(LogStash::Event.new({"field1" => [ "append1","original1" ]})) subject.append(LogStash::Event.new({"field1" => [ "append1","original1" ]}))
insist { subject[ "field1" ] } == [ "original1", "original2", "append1" ] expect(subject[ "field1" ]).to eq([ "original1", "original2", "append1" ])
end end
end end
end end
@ -209,7 +208,7 @@ describe LogStash::Event do
data = { "@timestamp" => "2013-12-21T07:25:06.605Z" } data = { "@timestamp" => "2013-12-21T07:25:06.605Z" }
event = LogStash::Event.new(data) event = LogStash::Event.new(data)
insist { event["@timestamp"] }.is_a?(LogStash::Timestamp) expect(event["@timestamp"]).to be_a(LogStash::Timestamp)
duration = 0 duration = 0
[warmup, count].each do |i| [warmup, count].each do |i|
@ -263,15 +262,15 @@ describe LogStash::Event do
it "should coerce timestamp" do it "should coerce timestamp" do
t = Time.iso8601("2014-06-12T00:12:17.114Z") t = Time.iso8601("2014-06-12T00:12:17.114Z")
expect(LogStash::Timestamp).to receive(:coerce).exactly(3).times.and_call_original expect(LogStash::Timestamp).to receive(:coerce).exactly(3).times.and_call_original
insist{LogStash::Event.new("@timestamp" => t).timestamp.to_i} == t.to_i expect(LogStash::Event.new("@timestamp" => t).timestamp.to_i).to eq(t.to_i)
insist{LogStash::Event.new("@timestamp" => LogStash::Timestamp.new(t)).timestamp.to_i} == t.to_i expect(LogStash::Event.new("@timestamp" => LogStash::Timestamp.new(t)).timestamp.to_i).to eq(t.to_i)
insist{LogStash::Event.new("@timestamp" => "2014-06-12T00:12:17.114Z").timestamp.to_i} == t.to_i expect(LogStash::Event.new("@timestamp" => "2014-06-12T00:12:17.114Z").timestamp.to_i).to eq(t.to_i)
end end
it "should assign current time when no timestamp" do it "should assign current time when no timestamp" do
ts = LogStash::Timestamp.now ts = LogStash::Timestamp.now
expect(LogStash::Timestamp).to receive(:now).and_return(ts) expect(LogStash::Timestamp).to receive(:now).and_return(ts)
insist{LogStash::Event.new({}).timestamp.to_i} == ts.to_i expect(LogStash::Event.new({}).timestamp.to_i).to eq(ts.to_i)
end end
it "should tag and warn for invalid value" do it "should tag and warn for invalid value" do
@ -281,14 +280,14 @@ describe LogStash::Event do
expect(logger).to receive(:warn).twice expect(logger).to receive(:warn).twice
event = LogStash::Event.new("@timestamp" => :foo) event = LogStash::Event.new("@timestamp" => :foo)
insist{event.timestamp.to_i} == ts.to_i expect(event.timestamp.to_i).to eq(ts.to_i)
insist{event["tags"]} == [LogStash::Event::TIMESTAMP_FAILURE_TAG] expect(event["tags"]).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG])
insist{event[LogStash::Event::TIMESTAMP_FAILURE_FIELD]} == :foo expect(event[LogStash::Event::TIMESTAMP_FAILURE_FIELD]).to eq(:foo)
event = LogStash::Event.new("@timestamp" => 666) event = LogStash::Event.new("@timestamp" => 666)
insist{event.timestamp.to_i} == ts.to_i expect(event.timestamp.to_i).to eq(ts.to_i)
insist{event["tags"]} == [LogStash::Event::TIMESTAMP_FAILURE_TAG] expect(event["tags"]).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG])
insist{event[LogStash::Event::TIMESTAMP_FAILURE_FIELD]} == 666 expect(event[LogStash::Event::TIMESTAMP_FAILURE_FIELD]).to eq(666)
end end
it "should tag and warn for invalid string format" do it "should tag and warn for invalid string format" do
@ -298,9 +297,9 @@ describe LogStash::Event do
expect(logger).to receive(:warn) expect(logger).to receive(:warn)
event = LogStash::Event.new("@timestamp" => "foo") event = LogStash::Event.new("@timestamp" => "foo")
insist{event.timestamp.to_i} == ts.to_i expect(event.timestamp.to_i).to eq(ts.to_i)
insist{event["tags"]} == [LogStash::Event::TIMESTAMP_FAILURE_TAG] expect(event["tags"]).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG])
insist{event[LogStash::Event::TIMESTAMP_FAILURE_FIELD]} == "foo" expect(event[LogStash::Event::TIMESTAMP_FAILURE_FIELD]).to eq("foo")
end end
end end
@ -312,7 +311,7 @@ describe LogStash::Event do
) )
json = new_event.to_json json = new_event.to_json
insist { json } == "{\"@timestamp\":\"2014-09-23T19:26:15.832Z\",\"message\":\"foo bar\",\"@version\":\"1\"}" expect(json).to eq( "{\"@timestamp\":\"2014-09-23T19:26:15.832Z\",\"message\":\"foo bar\",\"@version\":\"1\"}")
end end
it "should support to_json and ignore arguments" do it "should support to_json and ignore arguments" do
@ -322,7 +321,7 @@ describe LogStash::Event do
) )
json = new_event.to_json(:foo => 1, :bar => "baz") json = new_event.to_json(:foo => 1, :bar => "baz")
insist { json } == "{\"@timestamp\":\"2014-09-23T19:26:15.832Z\",\"message\":\"foo bar\",\"@version\":\"1\"}" expect(json).to eq( "{\"@timestamp\":\"2014-09-23T19:26:15.832Z\",\"message\":\"foo bar\",\"@version\":\"1\"}")
end end
end end
@ -331,14 +330,14 @@ describe LogStash::Event do
subject { LogStash::Event.new("hello" => "world", "@metadata" => { "fancy" => "pants" }) } subject { LogStash::Event.new("hello" => "world", "@metadata" => { "fancy" => "pants" }) }
it "should not include metadata in to_hash" do it "should not include metadata in to_hash" do
reject { subject.to_hash.keys }.include?("@metadata") expect(subject.to_hash.keys).not_to include("@metadata")
# 'hello', '@timestamp', and '@version' # 'hello', '@timestamp', and '@version'
insist { subject.to_hash.keys.count } == 3 expect(subject.to_hash.keys.count).to eq(3)
end end
it "should still allow normal field access" do it "should still allow normal field access" do
insist { subject["hello"] } == "world" expect(subject["hello"]).to eq("world")
end end
end end
@ -348,44 +347,44 @@ describe LogStash::Event do
subject { LogStash::Event.new("normal" => "normal") } subject { LogStash::Event.new("normal" => "normal") }
before do before do
# Verify the test is configured correctly. # Verify the test is configured correctly.
insist { fieldref }.start_with?("[@metadata]") expect(fieldref).to start_with("[@metadata]")
# Set it. # Set it.
subject[fieldref] = value subject[fieldref] = value
end end
it "should still allow normal field access" do it "should still allow normal field access" do
insist { subject["normal"] } == "normal" expect(subject["normal"]).to eq("normal")
end end
it "should allow getting" do it "should allow getting" do
insist { subject[fieldref] } == value expect(subject[fieldref]).to eq(value)
end end
it "should be hidden from .to_json" do it "should be hidden from .to_json" do
require "json" require "json"
obj = JSON.parse(subject.to_json) obj = JSON.parse(subject.to_json)
reject { obj }.include?("@metadata") expect(obj).not_to include("@metadata")
end end
it "should be hidden from .to_hash" do it "should be hidden from .to_hash" do
reject { subject.to_hash }.include?("@metadata") expect(subject.to_hash).not_to include("@metadata")
end end
it "should be accessible through #to_hash_with_metadata" do it "should be accessible through #to_hash_with_metadata" do
obj = subject.to_hash_with_metadata obj = subject.to_hash_with_metadata
insist { obj }.include?("@metadata") expect(obj).to include("@metadata")
insist { obj["@metadata"]["foo"]["bar"] } == value expect(obj["@metadata"]["foo"]["bar"]).to eq(value)
end end
end end
context "with no metadata" do context "with no metadata" do
subject { LogStash::Event.new("foo" => "bar") } subject { LogStash::Event.new("foo" => "bar") }
it "should have no metadata" do it "should have no metadata" do
insist { subject["@metadata"] }.empty? expect(subject["@metadata"]).to be_empty
end end
it "should still allow normal field access" do it "should still allow normal field access" do
insist { subject["foo"] } == "bar" expect(subject["foo"]).to eq("bar")
end end
end end

View file

@ -98,19 +98,19 @@ describe LogStash::Pipeline do
pipeline = TestPipeline.new(test_config_without_output_workers) pipeline = TestPipeline.new(test_config_without_output_workers)
pipeline.run pipeline.run
insist { pipeline.outputs.size } == 1 expect(pipeline.outputs.size ).to eq(1)
insist { pipeline.outputs.first.worker_plugins.size } == 1 expect(pipeline.outputs.first.worker_plugins.size ).to eq(1)
insist { pipeline.outputs.first.worker_plugins.first.num_teardowns } == 1 expect(pipeline.outputs.first.worker_plugins.first.num_teardowns ).to eq(1)
end end
it "should call output teardown correctly with output workers" do it "should call output teardown correctly with output workers" do
pipeline = TestPipeline.new(test_config_with_output_workers) pipeline = TestPipeline.new(test_config_with_output_workers)
pipeline.run pipeline.run
insist { pipeline.outputs.size } == 1 expect(pipeline.outputs.size ).to eq(1)
insist { pipeline.outputs.first.num_teardowns } == 0 expect(pipeline.outputs.first.num_teardowns).to eq(0)
pipeline.outputs.first.worker_plugins.each do |plugin| pipeline.outputs.first.worker_plugins.each do |plugin|
insist { plugin.num_teardowns } == 1 expect(plugin.num_teardowns ).to eq(1)
end end
end end
end end

View file

@ -1,5 +1,3 @@
require "insist"
describe "web tests" do describe "web tests" do
context "rack rubygem" do context "rack rubygem" do
it "must be available" do it "must be available" do

View file

@ -8,6 +8,6 @@ describe "LogStash::Inputs::Base#fix_streaming_codecs" do
plain = LogStash::Codecs::Plain.new("charset" => "CP1252") plain = LogStash::Codecs::Plain.new("charset" => "CP1252")
tcp = LogStash::Inputs::Tcp.new("codec" => plain, "port" => 3333) tcp = LogStash::Inputs::Tcp.new("codec" => plain, "port" => 3333)
tcp.instance_eval { fix_streaming_codecs } tcp.instance_eval { fix_streaming_codecs }
insist { tcp.codec.charset } == "CP1252" expect(tcp.codec.charset).to eq("CP1252")
end end
end end

View file

@ -11,45 +11,45 @@ describe LogStash::Util::Accessors, :if => true do
str = "hello" str = "hello"
data = { "hello" => "world" } data = { "hello" => "world" }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.get(str) } == data[str] expect(accessors.get(str)).to eq(data[str])
end end
it "should get value of key with spaces" do it "should get value of key with spaces" do
str = "hel lo" str = "hel lo"
data = { "hel lo" => "world" } data = { "hel lo" => "world" }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.get(str) } == data[str] expect(accessors.get(str)).to eq(data[str])
end end
it "should get value of numeric key string" do it "should get value of numeric key string" do
str = "1" str = "1"
data = { "1" => "world" } data = { "1" => "world" }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.get(str) } == data[str] expect(accessors.get(str)).to eq(data[str])
end end
it "should handle delete" do it "should handle delete" do
str = "simple" str = "simple"
data = { "simple" => "things" } data = { "simple" => "things" }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.del(str) } == "things" expect(accessors.del(str)).to eq("things")
insist { data }.empty? expect(data).to be_empty
end end
it "should set string value" do it "should set string value" do
str = "simple" str = "simple"
data = {} data = {}
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.set(str, "things") } == "things" expect(accessors.set(str, "things")).to eq("things")
insist { data } == { "simple" => "things" } expect(data).to eq({ "simple" => "things" })
end end
it "should set array value" do it "should set array value" do
str = "simple" str = "simple"
data = {} data = {}
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.set(str, ["foo", "bar"]) } == ["foo", "bar"] expect(accessors.set(str, ["foo", "bar"])).to eq(["foo", "bar"])
insist { data } == { "simple" => ["foo", "bar"]} expect(data).to eq({ "simple" => ["foo", "bar"]})
end end
end end
@ -59,118 +59,118 @@ describe LogStash::Util::Accessors, :if => true do
str = "[hello]" str = "[hello]"
data = { "hello" => "world" } data = { "hello" => "world" }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.get(str) } == "world" expect(accessors.get(str)).to eq("world")
end end
it "should get shallow string value of key with spaces" do it "should get shallow string value of key with spaces" do
str = "[hel lo]" str = "[hel lo]"
data = { "hel lo" => "world" } data = { "hel lo" => "world" }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.get(str) } == "world" expect(accessors.get(str)).to eq("world")
end end
it "should get shallow string value of numeric key string" do it "should get shallow string value of numeric key string" do
str = "[1]" str = "[1]"
data = { "1" => "world" } data = { "1" => "world" }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.get(str) } == "world" expect(accessors.get(str)).to eq("world")
end end
it "should get deep string value" do it "should get deep string value" do
str = "[hello][world]" str = "[hello][world]"
data = { "hello" => { "world" => "foo", "bar" => "baz" } } data = { "hello" => { "world" => "foo", "bar" => "baz" } }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.get(str) } == data["hello"]["world"] expect(accessors.get(str)).to eq(data["hello"]["world"])
end end
it "should return nil when getting a non-existant field (with no side-effects on original data)" do it "should return nil when getting a non-existant field (with no side-effects on original data)" do
str = "[hello][world]" str = "[hello][world]"
data = {} data = {}
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.get(str) }.nil? expect(accessors.get(str)).to be_nil
insist { data } == {} expect(data).to be_empty
insist { accessors.set(str, "foo") } == "foo" expect(accessors.set(str, "foo")).to eq("foo")
insist { data } == { "hello" => {"world" => "foo"} } expect(data).to eq({ "hello" => {"world" => "foo"} })
end end
it "should handle delete" do it "should handle delete" do
str = "[hello][world]" str = "[hello][world]"
data = { "hello" => { "world" => "foo", "bar" => "baz" } } data = { "hello" => { "world" => "foo", "bar" => "baz" } }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.del(str) } == "foo" expect(accessors.del(str)).to eq("foo")
# Make sure the "world" key is removed. # Make sure the "world" key is removed.
insist { data["hello"] } == { "bar" => "baz" } expect(data["hello"]).to eq({ "bar" => "baz" })
end end
it "should set shallow string value" do it "should set shallow string value" do
str = "[hello]" str = "[hello]"
data = {} data = {}
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.set(str, "foo") } == "foo" expect(accessors.set(str, "foo")).to eq("foo")
insist { data } == { "hello" => "foo" } expect(data).to eq({ "hello" => "foo" })
end end
it "should strict_set shallow string value" do it "should strict_set shallow string value" do
str = "[hello]" str = "[hello]"
data = {} data = {}
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.strict_set(str, "foo") } == "foo" expect(accessors.strict_set(str, "foo")).to eq("foo")
insist { data } == { "hello" => "foo" } expect(data).to eq({ "hello" => "foo"})
end end
it "should set deep string value" do it "should set deep string value" do
str = "[hello][world]" str = "[hello][world]"
data = {} data = {}
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.set(str, "foo") } == "foo" expect(accessors.set(str, "foo")).to eq("foo")
insist { data } == { "hello" => { "world" => "foo" } } expect(data).to eq({ "hello" => { "world" => "foo" } })
end end
it "should set deep array value" do it "should set deep array value" do
str = "[hello][world]" str = "[hello][world]"
data = {} data = {}
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.set(str, ["foo", "bar"]) } == ["foo", "bar"] expect(accessors.set(str, ["foo", "bar"])).to eq(["foo", "bar"])
insist { data } == { "hello" => { "world" => ["foo", "bar"] } } expect(data).to eq({ "hello" => { "world" => ["foo", "bar"] } })
end end
it "should strict_set deep array value" do it "should strict_set deep array value" do
str = "[hello][world]" str = "[hello][world]"
data = {} data = {}
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.strict_set(str, ["foo", "bar"]) } == ["foo", "bar"] expect(accessors.strict_set(str, ["foo", "bar"]) ).to eq(["foo", "bar"])
insist { data } == { "hello" => { "world" => ["foo", "bar"] } } expect(data).to eq({ "hello" => { "world" => ["foo", "bar"] } })
end end
it "should set element within array value" do it "should set element within array value" do
str = "[hello][0]" str = "[hello][0]"
data = {"hello" => ["foo", "bar"]} data = {"hello" => ["foo", "bar"]}
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.set(str, "world") } == "world" expect(accessors.set(str, "world") ).to eq("world")
insist { data } == {"hello" => ["world", "bar"]} expect(data).to eq({"hello" => ["world", "bar"]})
end end
it "should retrieve array item" do it "should retrieve array item" do
data = { "hello" => { "world" => ["a", "b"], "bar" => "baz" } } data = { "hello" => { "world" => ["a", "b"], "bar" => "baz" } }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.get("[hello][world][0]") } == data["hello"]["world"][0] expect(accessors.get("[hello][world][0]")).to eq(data["hello"]["world"][0])
insist { accessors.get("[hello][world][1]") } == data["hello"]["world"][1] expect(accessors.get("[hello][world][1]")).to eq(data["hello"]["world"][1])
end end
it "should retrieve array item containing hash" do it "should retrieve array item containing hash" do
data = { "hello" => { "world" => [ { "a" => 123 }, { "b" => 345 } ], "bar" => "baz" } } data = { "hello" => { "world" => [ { "a" => 123 }, { "b" => 345 } ], "bar" => "baz" } }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.get("[hello][world][0][a]") } == data["hello"]["world"][0]["a"] expect(accessors.get("[hello][world][0][a]")).to eq(data["hello"]["world"][0]["a"])
insist { accessors.get("[hello][world][1][b]") } == data["hello"]["world"][1]["b"] expect(accessors.get("[hello][world][1][b]")).to eq(data["hello"]["world"][1]["b"])
end end
it "should handle delete of array element" do it "should handle delete of array element" do
str = "[geocoords][0]" str = "[geocoords][0]"
data = { "geocoords" => [4, 2] } data = { "geocoords" => [4, 2] }
accessors = LogStash::Util::Accessors.new(data) accessors = LogStash::Util::Accessors.new(data)
insist { accessors.del(str) } == 4 expect(accessors.del(str)).to eq(4)
insist { data } == { "geocoords" => [2] } expect(data).to eq({ "geocoords" => [2] })
end end end end
context "using invalid encoding" do context "using invalid encoding" do

View file

@ -11,9 +11,9 @@ describe LogStash::Util::Charset do
it "should return untouched data" do it "should return untouched data" do
["foobar", "κόσμε"].each do |data| ["foobar", "κόσμε"].each do |data|
insist { data.encoding.name } == "UTF-8" expect(data.encoding.name).to eq("UTF-8")
insist { subject.convert(data) } == data expect(subject.convert(data)).to eq(data)
insist { subject.convert(data).encoding.name } == "UTF-8" expect(subject.convert(data).encoding.name).to eq("UTF-8")
end end
end end
end end
@ -27,12 +27,12 @@ describe LogStash::Util::Charset do
it "should escape invalid sequences" do it "should escape invalid sequences" do
["foo \xED\xB9\x81\xC3", "bar \xAD"].each do |data| ["foo \xED\xB9\x81\xC3", "bar \xAD"].each do |data|
insist { data.encoding.name } == "UTF-8" expect(data.encoding.name).to eq("UTF-8")
insist { data.valid_encoding? } == false expect(data.valid_encoding?).to eq(false)
expect(logger).to receive(:warn).exactly(2).times expect(logger).to receive(:warn).exactly(2).times
#logger.should_receive(:warn).twice #logger.should_receive(:warn).twice
insist { subject.convert(data) } == data.inspect[1..-2] expect(subject.convert(data)).to eq(data.inspect[1..-2])
insist { subject.convert(data).encoding.name } == "UTF-8" expect(subject.convert(data).encoding.name).to eq("UTF-8")
end end
end end
@ -47,11 +47,11 @@ describe LogStash::Util::Charset do
["\xE0 Montr\xE9al", "à Montréal"], ["\xE0 Montr\xE9al", "à Montréal"],
] ]
samples.map{|(a, b)| [a.force_encoding("ISO-8859-1"), b]}.each do |(a, b)| samples.map{|(a, b)| [a.force_encoding("ISO-8859-1"), b]}.each do |(a, b)|
insist { a.encoding.name } == "ISO-8859-1" expect(a.encoding.name).to eq("ISO-8859-1")
insist { b.encoding.name } == "UTF-8" expect(b.encoding.name).to eq("UTF-8")
insist { a.valid_encoding? } == true expect(a.valid_encoding?).to eq(true)
insist { subject.convert(a).encoding.name } == "UTF-8" expect(subject.convert(a).encoding.name).to eq("UTF-8")
insist { subject.convert(a) } == b expect(subject.convert(a)).to eq(b)
end end
end end
end end
@ -65,10 +65,10 @@ describe LogStash::Util::Charset do
["\xCE\xBA\xCF\x8C\xCF\x83\xCE\xBC\xCE\xB5", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"], ["\xCE\xBA\xCF\x8C\xCF\x83\xCE\xBC\xCE\xB5", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"],
] ]
samples.map{|(a, b)| [a.force_encoding("ASCII-8BIT"), b]}.each do |(a, b)| samples.map{|(a, b)| [a.force_encoding("ASCII-8BIT"), b]}.each do |(a, b)|
insist { a.encoding.name } == "ASCII-8BIT" expect(a.encoding.name).to eq("ASCII-8BIT")
insist { b.encoding.name } == "UTF-8" expect(b.encoding.name).to eq("UTF-8")
insist { subject.convert(a).encoding.name } == "UTF-8" expect(subject.convert(a).encoding.name).to eq("UTF-8")
insist { subject.convert(a) } == b expect(subject.convert(a)).to eq(b)
end end
end end
end end

View file

@ -9,7 +9,7 @@ describe LogStash::Util::FieldReference, :if => true do
str = "hello" str = "hello"
m = eval(subject.compile(str)) m = eval(subject.compile(str))
data = { "hello" => "world" } data = { "hello" => "world" }
insist { m.call(data) } == data[str] expect(m.call(data)).to eq(data[str])
end end
it "should handle delete in block" do it "should handle delete in block" do
@ -17,22 +17,22 @@ describe LogStash::Util::FieldReference, :if => true do
m = eval(subject.compile(str)) m = eval(subject.compile(str))
data = { "simple" => "things" } data = { "simple" => "things" }
m.call(data) { |obj, key| obj.delete(key) } m.call(data) { |obj, key| obj.delete(key) }
insist { data }.empty? expect(data).to be_empty
end end
it "should handle assignment in block" do it "should handle assignment in block" do
str = "simple" str = "simple"
m = eval(subject.compile(str)) m = eval(subject.compile(str))
data = {} data = {}
insist { m.call(data) { |obj, key| obj[key] = "things" }} == "things" expect(m.call(data) { |obj, key| obj[key] = "things" }).to eq("things")
insist { data } == { "simple" => "things" } expect(data).to eq({ "simple" => "things" })
end end
it "should handle assignment using set" do it "should handle assignment using set" do
str = "simple" str = "simple"
data = {} data = {}
insist { subject.set(str, "things", data) } == "things" expect(subject.set(str, "things", data)).to eq("things")
insist { data } == { "simple" => "things" } expect(data).to eq({ "simple" => "things" })
end end
end end
@ -42,14 +42,14 @@ describe LogStash::Util::FieldReference, :if => true do
str = "[hello]" str = "[hello]"
m = eval(subject.compile(str)) m = eval(subject.compile(str))
data = { "hello" => "world" } data = { "hello" => "world" }
insist { m.call(data) } == "world" expect(m.call(data)).to eq("world")
end end
it "should retrieve deep value" do it "should retrieve deep value" do
str = "[hello][world]" str = "[hello][world]"
m = eval(subject.compile(str)) m = eval(subject.compile(str))
data = { "hello" => { "world" => "foo", "bar" => "baz" } } data = { "hello" => { "world" => "foo", "bar" => "baz" } }
insist { m.call(data) } == data["hello"]["world"] expect(m.call(data)).to eq(data["hello"]["world"])
end end
it "should handle delete in block" do it "should handle delete in block" do
@ -59,38 +59,38 @@ describe LogStash::Util::FieldReference, :if => true do
m.call(data) { |obj, key| obj.delete(key) } m.call(data) { |obj, key| obj.delete(key) }
# Make sure the "world" key is removed. # Make sure the "world" key is removed.
insist { data["hello"] } == { "bar" => "baz" } expect(data["hello"]).to eq({ "bar" => "baz" })
end end
it "should not handle assignment in block" do it "should not handle assignment in block" do
str = "[hello][world]" str = "[hello][world]"
m = eval(subject.compile(str)) m = eval(subject.compile(str))
data = {} data = {}
insist { m.call(data) { |obj, key| obj[key] = "things" }}.nil? expect(m.call(data) { |obj, key| obj[key] = "things" }).to be_nil
insist { data } == { } expect(data).to be_empty
end end
it "should set shallow value" do it "should set shallow value" do
str = "[hello]" str = "[hello]"
data = {} data = {}
insist { subject.set(str, "foo", data) } == "foo" expect(subject.set(str, "foo", data)).to eq("foo")
insist { data } == { "hello" => "foo" } expect(data).to eq({ "hello" => "foo" })
end end
it "should set deep value" do it "should set deep value" do
str = "[hello][world]" str = "[hello][world]"
data = {} data = {}
insist { subject.set(str, "foo", data) } == "foo" expect(subject.set(str, "foo", data)).to eq("foo")
insist { data } == { "hello" => { "world" => "foo" } } expect(data).to eq({ "hello" => { "world" => "foo" } })
end end
it "should retrieve array item" do it "should retrieve array item" do
data = { "hello" => { "world" => ["a", "b"], "bar" => "baz" } } data = { "hello" => { "world" => ["a", "b"], "bar" => "baz" } }
m = eval(subject.compile("[hello][world][0]")) m = eval(subject.compile("[hello][world][0]"))
insist { m.call(data) } == data["hello"]["world"][0] expect(m.call(data)).to eq(data["hello"]["world"][0])
m = eval(subject.compile("[hello][world][1]")) m = eval(subject.compile("[hello][world][1]"))
insist { m.call(data) } == data["hello"]["world"][1] expect(m.call(data)).to eq(data["hello"]["world"][1])
end end
end end
end end

View file

@ -1,5 +1,3 @@
require "insist"
describe "logstash jar features", :if => (__FILE__ =~ /file:.*!/) do describe "logstash jar features", :if => (__FILE__ =~ /file:.*!/) do
let(:jar_root) { __FILE__.split("!").first + "!" } let(:jar_root) { __FILE__.split("!").first + "!" }
@ -9,12 +7,12 @@ describe "logstash jar features", :if => (__FILE__ =~ /file:.*!/) do
it "must contain GeoLiteCity.dat" do it "must contain GeoLiteCity.dat" do
path = File.join(jar_root, "GeoLiteCity.dat") path = File.join(jar_root, "GeoLiteCity.dat")
insist { File }.exists?(path) expect(File.exist?(path)).to be_true
end end
it "must contain vendor/ua-parser/regexes.yaml" do it "must contain vendor/ua-parser/regexes.yaml" do
path = File.join(jar_root, "vendor/ua-parser/regexes.yaml") path = File.join(jar_root, "vendor/ua-parser/regexes.yaml")
insist { File }.exists?(path) expect(File.exist?(path)).to be_true
end end
it "must successfully load aws-sdk (LOGSTASH-1718)" do it "must successfully load aws-sdk (LOGSTASH-1718)" do