require_relative '../helper' require 'fluent/test/driver/parser' require 'fluent/plugin/parser' class RegexpParserTest < ::Test::Unit::TestCase def setup Fluent::Test.setup end def internal_test_case(parser) text = '192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] [14/Feb/2013:12:00:00 +0900] "true /,/user HTTP/1.1" 200 777' parser.parse(text) { |time, record| assert_equal(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time) assert_equal({ 'user' => '-', 'flag' => true, 'code' => 200.0, 'size' => 777, 'date' => event_time('14/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), 'host' => '192.168.0.1', 'path' => ['/', '/user'] }, record) } end sub_test_case "Fluent::Compat::TextParser::RegexpParser" do def create_driver(regexp, conf = {}, initialize_conf: false) if initialize_conf Fluent::Test::Driver::Parser.new(Fluent::Compat::TextParser::RegexpParser.new(regexp, conf)) else # Fluent::Test::Driver::Parser.new(Fluent::Compat::TextParser::RegexpParser.new(regexp)).configure(conf) instance = Fluent::Compat::TextParser::RegexpParser.new(regexp) instance.configure(conf) d = Struct.new(:instance).new d.instance = instance d end end def test_parse_with_typed # Use Regexp.new instead of // literal to avoid different parser behaviour in 1.9 and 2.0 regexp = Regexp.new(%q!^(?[^ ]*) [^ ]* (?[^ ]*) \[(?