Skip to content

Commit

Permalink
add gsub tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fetep committed Jul 7, 2012
1 parent 04ad0c3 commit 3383837
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/logstash/filters/test_mutate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,53 @@ def config(cfg)
"Field 'foo' should now be an float (1234.10), but is " \
" a #{event["foo"].class.inspect} (#{event["foo"].inspect})")
end # convert one field

test "gsub on a String" do
config "gsub" => ["test", "foo", "bar"]

event = LogStash::Event.new
event.type = @typename
event["test"] = "test foo test"

@filter.filter(event)
assert_equal("test bar test", event["test"])
end

test "gsub on an Array of Strings" do
config "gsub" => ["test", "foo", "bar"]

event = LogStash::Event.new
event.type = @typename
event["test"] = ["test foo test", "test2 foo test2"]

@filter.filter(event)
assert_equal(["test bar test", "test2 bar test2"], event["test"])
end

test "gsub on an Array of non-Strings" do
config "gsub" => ["test", "foo", "bar"]

event = LogStash::Event.new
event.type = @typename
test_data = [{"foo" => "test foo test"}]
event["test"] = test_data

@filter.filter(event)
assert_equal(test_data, event["test"])
end

test "gsub on multiple fields" do
config "gsub" => ["test", "foo", "bar",
"test2", "foo", "bar",
]

event = LogStash::Event.new
event.type = @typename
event["test"] = "test foo test"
event["test2"] = "test2 foo test2"

@filter.filter(event)
assert_equal("test bar test", event["test"])
assert_equal("test2 bar test2", event["test2"])
end
end # Test 'mutate' filter

0 comments on commit 3383837

Please sign in to comment.