-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1691 from ryysud/fix-tsv-formatter
Add support to enable writing to new lines for tsv formatter
- Loading branch information
Showing
2 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require_relative '../helper' | ||
require 'fluent/test/driver/formatter' | ||
require 'fluent/plugin/formatter_tsv' | ||
|
||
class TSVFormatterTest < ::Test::Unit::TestCase | ||
def setup | ||
@time = event_time | ||
end | ||
|
||
def create_driver(conf = "") | ||
Fluent::Test::Driver::Formatter.new(Fluent::Plugin::TSVFormatter).configure(conf) | ||
end | ||
|
||
def tag | ||
"tag" | ||
end | ||
|
||
def record | ||
{'message' => 'awesome', 'greeting' => 'hello'} | ||
end | ||
|
||
def test_config_params | ||
d = create_driver( | ||
'keys' => 'message,greeting', | ||
) | ||
assert_equal ["message", "greeting"], d.instance.keys | ||
assert_equal "\t", d.instance.delimiter | ||
assert_equal true, d.instance.add_newline | ||
|
||
d = create_driver( | ||
'keys' => 'message,greeting', | ||
'delimiter' => ',', | ||
'add_newline' => false, | ||
) | ||
assert_equal ["message", "greeting"], d.instance.keys | ||
assert_equal ",", d.instance.delimiter | ||
assert_equal false, d.instance.add_newline | ||
end | ||
|
||
def test_format | ||
d = create_driver( | ||
'keys' => 'message,greeting', | ||
) | ||
formatted = d.instance.format(tag, @time, record) | ||
|
||
assert_equal("awesome\thello\n", formatted) | ||
end | ||
|
||
def test_format_without_newline | ||
d = create_driver( | ||
'keys' => 'message,greeting', | ||
'add_newline' => false, | ||
) | ||
formatted = d.instance.format(tag, @time, record) | ||
|
||
assert_equal("awesome\thello", formatted) | ||
end | ||
|
||
def test_format_with_customized_delimiters | ||
d = create_driver( | ||
'keys' => 'message,greeting', | ||
'delimiter' => ',', | ||
) | ||
formatted = d.instance.format(tag, @time, record) | ||
|
||
assert_equal("awesome,hello\n", formatted) | ||
end | ||
end |