Convert test_base and test_xml

This commit is contained in:
Wiibaa 2012-09-15 15:14:16 +02:00
parent fac411af30
commit 3ae5b4a130
2 changed files with 215 additions and 3 deletions

View file

@ -19,4 +19,145 @@ describe LogStash::Filters::NOOP do
insist { subject["new_field"]} == ["new_value", "new_value_2"]
end
end
describe "type parsing" do
config <<-CONFIG
filter {
noop {
type => "noop"
add_tag => ["test"]
}
}
CONFIG
sample({"@type" => "noop"}) do
insist { subject.tags} == ["test"]
end
sample({"@type" => "not_noop"}) do
insist { subject.tags} == []
end
end
describe "tags parsing with one tag" do
config <<-CONFIG
filter {
noop {
type => "noop"
tags => ["t1"]
add_tag => ["test"]
}
}
CONFIG
sample({"@type" => "noop"}) do
insist { subject.tags} == []
end
sample({"@type" => "noop", "@tags" => ["t1", "t2"]}) do
insist { subject.tags} == ["t1", "t2", "test"]
end
end
describe "tags parsing with multiple tags" do
config <<-CONFIG
filter {
noop {
type => "noop"
tags => ["t1", "t2"]
add_tag => ["test"]
}
}
CONFIG
sample({"@type" => "noop"}) do
insist { subject.tags} == []
end
sample({"@type" => "noop", "@tags" => ["t1"]}) do
insist { subject.tags} == ["t1"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t2"]}) do
insist { subject.tags} == ["t1", "t2", "test"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t2", "t3"]}) do
insist { subject.tags} == ["t1", "t2", "t3", "test"]
end
end
describe "exclude_tags with 1 tag" do
config <<-CONFIG
filter {
noop {
type => "noop"
tags => ["t1"]
add_tag => ["test"]
exclude_tags => ["t2"]
}
}
CONFIG
sample({"@type" => "noop"}) do
insist { subject.tags} == []
end
sample({"@type" => "noop", "@tags" => ["t1"]}) do
insist { subject.tags} == ["t1", "test"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t2"]}) do
insist { subject.tags} == ["t1", "t2"]
end
end
describe "exclude_tags with >1 tags" do
config <<-CONFIG
filter {
noop {
type => "noop"
tags => ["t1"]
add_tag => ["test"]
exclude_tags => ["t2", "t3"]
}
}
CONFIG
sample({"@type" => "noop", "@tags" => ["t1", "t2", "t4"]}) do
insist { subject.tags} == ["t1", "t2", "t4"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t3", "t4"]}) do
insist { subject.tags} == ["t1", "t3", "t4"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t4", "t5"]}) do
insist { subject.tags} == ["t1", "t4", "t5", "test"]
end
end
describe "remove_tag" do
config <<-CONFIG
filter {
noop {
type => "noop"
tags => ["t1"]
remove_tag => ["t2", "t3"]
}
}
CONFIG
sample({"@type" => "noop", "@tags" => ["t4"]}) do
insist { subject.tags} == ["t4"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t2", "t3"]}) do
insist { subject.tags} == ["t1"]
end
sample({"@type" => "noop", "@tags" => ["t1", "t2"]}) do
insist { subject.tags} == ["t1"]
end
end
end

View file

@ -1,10 +1,81 @@
require "test_utils"
require "logstash/filters/xml"
describe LogStash::Filters::Mutate do
describe LogStash::Filters::Xml do
extend LogStash::RSpec
it "needs tests!" do
raise "I NEED TESTS"
it "needs MORE tests!" do
raise "I NEED MORE TESTS"
end
describe "parse standard xml" do
config <<-CONFIG
filter {
xml {
raw => "data"
}
}
CONFIG
sample({"@fields" => {"raw" => '<foo key="value"/>'}}) do
reject { subject.tags}.include?("_xmlparsefailure")
insist { subject["data"]} == {"key" => "value"}
end
#From parse xml with array as a value
sample({"@fields" => {"raw" => '<foo><key>value1</key><key>value2</key></foo>'}}) do
reject { subject.tags}.include?("_xmlparsefailure")
insist { subject["data"]} == {"key" => ["value1", "value2"]}
end
#From parse xml with hash as a value
sample({"@fields" => {"raw" => '<foo><key1><key2>value</key2></key1></foo>'}}) do
reject { subject.tags}.include?("_xmlparsefailure")
insist { subject["data"]} == {"key1" => [{"key2" => ["value"]}]}
end
#From bad xml
sample({"@fields" => {"raw" => '<foo /'}}) do
insist { subject.tags}.include?("_xmlparsefailure")
end
end
describe "parse standard xml but do not store" do
config <<-CONFIG
filter {
xml {
raw => "data"
store_xml => false
}
}
CONFIG
sample({"@fields" => {"raw" => '<foo key="value"/>'}}) do
reject { subject.tags}.include?("_xmlparsefailure")
insist { subject["data"]} == nil
end
end
describe "parse xml and store values with xpath" do
config <<-CONFIG
filter {
xml {
raw => "data"
xpath => [ "/foo/key/text()", "xpath_field" ]
}
}
CONFIG
# Single value
sample({"@fields" => {"raw" => '<foo><key>value</key></foo>'}}) do
reject { subject.tags}.include?("_xmlparsefailure")
insist { subject["xpath_field"]} == ["value"]
end
#Multiple values
sample({"@fields" => {"raw" => '<foo><key>value1</key><key>value2</key></foo>'}}) do
reject { subject.tags}.include?("_xmlparsefailure")
insist { subject["xpath_field"]} == ["value1","value2"]
end
end
end