test/mixin/test_plaintextformatter.rb in fluent-mixin-plaintextformatter-0.2.3 vs test/mixin/test_plaintextformatter.rb in fluent-mixin-plaintextformatter-0.2.4
- old
+ new
@@ -173,10 +173,12 @@
# format
assert_equal "10000,foo foo baz\n", p.format('test.a', 1342163105, r)
end
def test_format_invalid_utf8_sequence
+ $log.clear
+
invalid_str = [0xFA, 0xFB].pack('CC').force_encoding('utf-8')
valid_str = [0xFF, 0xE3].pack("U*")
p1 = create_plugin_instance(Fluent::TestAOutput, %[
type testa
@@ -186,18 +188,67 @@
])
r1 = p1.format('tag', Fluent::Engine.now, {'foo' => valid_str, 'bar' => invalid_str + valid_str})
# #format should logs for this record (but we cannot test it...)
assert_equal '', r1
+ assert_equal :warn, $log.logs[0][0]
+ assert $log.logs[0][1] =~ /source sequence is illegal\/malformed utf-8, ignored/
+ assert_equal 'JSON::GeneratorError', $log.logs[0][2][:error_class].to_s
+
+ $log.clear
+
p2 = create_plugin_instance(Fluent::TestAOutput, %[
type testa
output_include_time true
output_include_tag true
output_data_type ltsv
])
r2 = p2.format('tag', Fluent::Engine.now, {'foo' => valid_str, 'bar' => invalid_str + valid_str})
# #format should logs for this record (but we cannot test it...)
assert_equal '', r2
+
+ assert_equal :warn, $log.logs[0][0]
+ assert $log.logs[0][1] =~ /^invalid byte sequence in UTF-8, ignored/
+ assert_equal 'ArgumentError', $log.logs[0][2][:error_class].to_s
+
+ $log.clear
+ end
+
+ def test_format_invalid_utf8_sequence_suppress_logs
+ $log.clear
+
+ invalid_str = [0xFA, 0xFB].pack('CC').force_encoding('utf-8')
+ valid_str = [0xFF, 0xE3].pack("U*")
+
+ p1 = create_plugin_instance(Fluent::TestAOutput, %[
+type testa
+output_include_time true
+output_include_tag true
+output_data_type json
+suppress_log_broken_string true
+])
+ r1 = p1.format('tag', Fluent::Engine.now, {'foo' => valid_str, 'bar' => invalid_str + valid_str})
+ # #format should logs for this record (but we cannot test it...)
+ assert_equal '', r1
+
+ assert_equal 0, $log.logs.size
+
+ $log.clear
+
+ p2 = create_plugin_instance(Fluent::TestAOutput, %[
+type testa
+output_include_time true
+output_include_tag true
+output_data_type ltsv
+suppress_log_broken_string true
+])
+ r2 = p2.format('tag', Fluent::Engine.now, {'foo' => valid_str, 'bar' => invalid_str + valid_str})
+ # #format should logs for this record (but we cannot test it...)
+ assert_equal '', r2
+
+ assert_equal 0, $log.logs.size
+
+ $log.clear
end
def test_field_separator_newline_ltsv
p = create_plugin_instance(Fluent::TestDOutput, "type testd\nutc\n")
r = {'foo' => 'foo foo baz', 'bar' => 10000}