mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
- add conditionals tests
This commit is contained in:
parent
f2dc7a9daf
commit
3a776890f8
1 changed files with 100 additions and 0 deletions
100
spec/conditionals/test.rb
Normal file
100
spec/conditionals/test.rb
Normal file
|
@ -0,0 +1,100 @@
|
|||
require "test_utils"
|
||||
|
||||
describe "conditionals" do
|
||||
extend LogStash::RSpec
|
||||
|
||||
describe "simple" do
|
||||
config <<-CONFIG
|
||||
filter {
|
||||
mutate { add_field => { "always" => "awesome" } }
|
||||
if [foo] == "bar" {
|
||||
mutate { add_field => { "hello" => "world" } }
|
||||
} elsif [bar] == "baz" {
|
||||
mutate { add_field => { "fancy" => "pants" } }
|
||||
} else {
|
||||
mutate { add_field => { "free" => "hugs" } }
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
sample({"foo" => "bar"}) do
|
||||
insist { subject["always"] } == "awesome"
|
||||
insist { subject["hello"] } == "world"
|
||||
insist { subject["fancy"] }.nil?
|
||||
insist { subject["free"] }.nil?
|
||||
end
|
||||
|
||||
sample({"notfoo" => "bar"}) do
|
||||
insist { subject["always"] } == "awesome"
|
||||
insist { subject["hello"] }.nil?
|
||||
insist { subject["fancy"] }.nil?
|
||||
insist { subject["free"] } == "hugs"
|
||||
end
|
||||
|
||||
sample({"bar" => "baz"}) do
|
||||
insist { subject["always"] } == "awesome"
|
||||
insist { subject["hello"] }.nil?
|
||||
insist { subject["fancy"] } == "pants"
|
||||
insist { subject["free"] }.nil?
|
||||
end
|
||||
end
|
||||
|
||||
describe "nested" do
|
||||
config <<-CONFIG
|
||||
filter {
|
||||
if [nest] == 123 {
|
||||
mutate { add_field => { "always" => "awesome" } }
|
||||
if [foo] == "bar" {
|
||||
mutate { add_field => { "hello" => "world" } }
|
||||
} elsif [bar] == "baz" {
|
||||
mutate { add_field => { "fancy" => "pants" } }
|
||||
} else {
|
||||
mutate { add_field => { "free" => "hugs" } }
|
||||
}
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
sample("foo" => "bar", "nest" => 124) do
|
||||
insist { subject["always"] }.nil?
|
||||
insist { subject["hello"] }.nil?
|
||||
insist { subject["fancy"] }.nil?
|
||||
insist { subject["free"] }.nil?
|
||||
end
|
||||
|
||||
sample("foo" => "bar", "nest" => 123) do
|
||||
insist { subject["always"] } == "awesome"
|
||||
insist { subject["hello"] } == "world"
|
||||
insist { subject["fancy"] }.nil?
|
||||
insist { subject["free"] }.nil?
|
||||
end
|
||||
|
||||
sample("notfoo" => "bar", "nest" => 123) do
|
||||
insist { subject["always"] } == "awesome"
|
||||
insist { subject["hello"] }.nil?
|
||||
insist { subject["fancy"] }.nil?
|
||||
insist { subject["free"] } == "hugs"
|
||||
end
|
||||
|
||||
sample("bar" => "baz", "nest" => 123) do
|
||||
insist { subject["always"] } == "awesome"
|
||||
insist { subject["hello"] }.nil?
|
||||
insist { subject["fancy"] } == "pants"
|
||||
insist { subject["free"] }.nil?
|
||||
end
|
||||
end
|
||||
|
||||
describe "comparing two fields" do
|
||||
config <<-CONFIG
|
||||
filter {
|
||||
if [foo] == [bar] {
|
||||
mutate { add_tag => woot }
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
sample("foo" => 123, "bar" => 123) do
|
||||
insist { subject["tags"] }.include?("woot")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue