From 3464eba526a51e76812bf60092d563881832ad6d Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 21 Jun 2017 14:38:04 +0900 Subject: [PATCH] Follow w/o priority behavior change for rfc5424 --- test/test_parser.rb | 47 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/test/test_parser.rb b/test/test_parser.rb index 42cfa04f3c..ee6f22fde1 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -379,6 +379,7 @@ def test_parse_with_rfc5424_message @parser.configure( 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z', 'message_format' => 'rfc5424', + 'with_priority' => true, ) text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!' @parser.parse(text) do |time, record| @@ -388,6 +389,9 @@ def test_parse_with_rfc5424_message assert_equal "-", record["extradata"] assert_equal "Hi, from Fluentd!", record["message"] end + assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI, + @parser.instance.patterns['format']) + end def test_parse_with_rfc5424_message_and_without_priority @@ -410,6 +414,7 @@ def test_parse_with_rfc5424_message_and_without_priority def test_parse_with_rfc5424_message_without_time_format @parser.configure( 'message_format' => 'rfc5424', + 'with_priority' => true, ) text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!' @parser.instance.parse(text) do |time, record| @@ -425,6 +430,7 @@ def test_parse_with_rfc5424_structured_message @parser.configure( 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z', 'message_format' => 'rfc5424', + 'with_priority' => true, ) text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd!' @parser.parse(text) do |time, record| @@ -462,12 +468,15 @@ def test_auto_with_legacy_syslog_priority_message assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time) assert_equal(@expected.merge('pri' => 6), record) end + assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI, + @parser.instance.patterns['format']) end def test_parse_with_rfc5424_message @parser.configure( 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z', 'message_format' => 'auto', + 'with_priority' => true, ) text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!' @parser.parse(text) do |time, record| @@ -477,12 +486,15 @@ def test_parse_with_rfc5424_message assert_equal "-", record["extradata"] assert_equal "Hi, from Fluentd!", record["message"] end + assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI, + @parser.instance.patterns['format']) end def test_parse_with_rfc5424_structured_message @parser.configure( 'time_format' => '%Y-%m-%dT%H:%M:%S.%L%z', 'message_format' => 'auto', + 'with_priority' => true, ) text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd!' @parser.parse(text) do |time, record| @@ -493,6 +505,8 @@ def test_parse_with_rfc5424_structured_message record["extradata"] assert_equal "Hi, from Fluentd!", record["message"] end + assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI, + @parser.instance.patterns['format']) end def test_parse_with_both_message_type @@ -500,12 +514,16 @@ def test_parse_with_both_message_type 'time_format' => '%b %d %M:%S:%H', 'rfc5424_time_format' => '%Y-%m-%dT%H:%M:%S.%L%z', 'message_format' => 'auto', + 'with_priority' => true, ) - text = 'Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test' + text = '<1>Feb 28 12:00:00 192.168.0.1 fluentd[11111]: [error] Syslog test' @parser.parse(text) do |time, record| assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time) - assert_equal(@expected, record) + assert_equal(@expected.merge('pri' => 1), record) end + assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI, + @parser.instance.patterns['format']) + text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd!' @parser.parse(text) do |time, record| assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time) @@ -515,11 +533,17 @@ def test_parse_with_both_message_type record["extradata"] assert_equal "Hi, from Fluentd!", record["message"] end - text = 'Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test' + assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI, + @parser.instance.patterns['format']) + + text = '<1>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test' @parser.parse(text) do |time, record| assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time) - assert_equal(@expected, record) + assert_equal(@expected.merge('pri' => 1), record) end + assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI, + @parser.instance.patterns['format']) + text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!' @parser.parse(text) do |time, record| assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time) @@ -528,6 +552,9 @@ def test_parse_with_both_message_type assert_equal "-", record["extradata"] assert_equal "Hi, from Fluentd!", record["message"] end + assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI, + @parser.instance.patterns['format']) + end def test_parse_with_both_message_type_and_priority @@ -542,6 +569,9 @@ def test_parse_with_both_message_type_and_priority assert_equal(event_time("Feb 28 12:00:00", format: '%b %d %M:%S:%H'), time) assert_equal(@expected.merge('pri' => 6), record) end + assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI, + @parser.instance.patterns['format']) + text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd 11111 ID24224 [exampleSDID@20224 iut="3" eventSource="Application" eventID="11211"] Hi, from Fluentd!' @parser.parse(text) do |time, record| assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time) @@ -551,11 +581,17 @@ def test_parse_with_both_message_type_and_priority record["extradata"] assert_equal "Hi, from Fluentd!", record["message"] end + assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI, + @parser.instance.patterns['format']) + text = '<16>Feb 28 12:00:02 192.168.0.1 fluentd[11111]: [error] Syslog test' @parser.parse(text) do |time, record| assert_equal(event_time("Feb 28 12:00:02", format: '%b %d %M:%S:%H'), time) assert_equal(@expected.merge('pri' => 16), record) end + assert_equal(TextParser::SyslogParser::REGEXP_WITH_PRI, + @parser.instance.patterns['format']) + text = '<16>1 2017-02-06T13:14:15.003Z 192.168.0.1 fluentd - - - Hi, from Fluentd!' @parser.parse(text) do |time, record| assert_equal(event_time("2017-02-06T13:14:15.003Z", format: '%Y-%m-%dT%H:%M:%S.%L%z'), time) @@ -564,6 +600,9 @@ def test_parse_with_both_message_type_and_priority assert_equal "-", record["extradata"] assert_equal "Hi, from Fluentd!", record["message"] end + assert_equal(TextParser::SyslogParser::REGEXP_RFC5424_WITH_PRI, + @parser.instance.patterns['format']) + end end end