mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
- Add JSON filter test coverage
This commit is contained in:
parent
54b3933049
commit
e8f1cf7d3e
1 changed files with 55 additions and 0 deletions
55
spec/filters/json.rb
Normal file
55
spec/filters/json.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
require "test_utils"
|
||||
require "logstash/filters/json"
|
||||
|
||||
describe LogStash::Filters::Json do
|
||||
extend LogStash::RSpec
|
||||
|
||||
describe "parse @message into @fields" do
|
||||
config <<-CONFIG
|
||||
filter {
|
||||
json {
|
||||
# Parse @message as JSON, store the results in the 'data' field'
|
||||
"@message" => "@fields"
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
sample '{ "hello": "world", "list": [ 1, 2, 3 ], "hash": { "k": "v" } }' do
|
||||
insist { subject["hello"] } == "world"
|
||||
insist { subject["list" ] } == [1,2,3]
|
||||
insist { subject["hash"] } == { "k" => "v" }
|
||||
end
|
||||
end
|
||||
|
||||
describe "parse @message into a target field" do
|
||||
config <<-CONFIG
|
||||
filter {
|
||||
json {
|
||||
# Parse @message as JSON, store the results in the 'data' field'
|
||||
"@message" => "data"
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
sample '{ "hello": "world", "list": [ 1, 2, 3 ], "hash": { "k": "v" } }' do
|
||||
insist { subject["data"]["hello"] } == "world"
|
||||
insist { subject["data"]["list" ] } == [1,2,3]
|
||||
insist { subject["data"]["hash"] } == { "k" => "v" }
|
||||
end
|
||||
end
|
||||
|
||||
describe "tag invalid json" do
|
||||
config <<-CONFIG
|
||||
filter {
|
||||
json {
|
||||
# Parse @message as JSON, store the results in the 'data' field'
|
||||
"@message" => "data"
|
||||
}
|
||||
}
|
||||
CONFIG
|
||||
|
||||
sample "invalid json" do
|
||||
insist { subject.tags }.include?("_jsonparsefailure")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue