Sha256: 717cad8a58cdae65d63c5e8fc5aea3bb6cce218a1374f6b7895446f7ab9f6037

Contents?: true

Size: 1.69 KB

Versions: 251

Compression:

Stored size: 1.69 KB

Contents

require_relative '../helper'
require 'fluent/test/driver/parser'
require 'fluent/plugin/parser'

class Apache2ParserTest < ::Test::Unit::TestCase
  def setup
    Fluent::Test.setup
    @parser = Fluent::Test::Driver::Parser.new(Fluent::Plugin::Apache2Parser)
    @expected = {
      'user'    => nil,
      'method'  => 'GET',
      'code'    => 200,
      'size'    => 777,
      'host'    => '192.168.0.1',
      'path'    => '/',
      'referer' => nil,
      'agent'   => 'Opera/12.0'
    }
    @parser.configure({})
  end

  def test_parse
    @parser.instance.parse('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0"') { |time, record|
      assert_equal(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
      assert_equal(@expected, record)
    }
    assert_equal(Fluent::Plugin::Apache2Parser::REGEXP,
                 @parser.instance.patterns['format'])
    assert_equal(Fluent::Plugin::Apache2Parser::TIME_FORMAT,
                 @parser.instance.patterns['time_format'])
  end

  def test_parse_without_http_version
    @parser.instance.parse('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET /" 200 777 "-" "Opera/12.0"') { |time, record|
      assert_equal(event_time('28/Feb/2013:12:00:00 +0900', format: '%d/%b/%Y:%H:%M:%S %z'), time)
      assert_equal(@expected, record)
    }
  end

  def test_parse_with_escape_sequence
    @parser.instance.parse('192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET /\" HTTP/1.1" 200 777 "referer \\\ \"" "user agent \\\ \""') { |_, record|
      assert_equal('/\"', record['path'])
      assert_equal('referer \\\ \"', record['referer'])
      assert_equal('user agent \\\ \"', record['agent'])
    }
  end
end

Version data entries

251 entries across 251 versions & 7 rubygems

Version Path
fluentd-1.16.7-x64-mingw32 test/plugin/test_parser_apache2.rb
fluentd-1.16.7-x86-mingw32 test/plugin/test_parser_apache2.rb
fluentd-1.16.7-x64-mingw-ucrt test/plugin/test_parser_apache2.rb
fluentd-1.16.7 test/plugin/test_parser_apache2.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin/test_parser_apache2.rb
fluentd-1.16.6-x86-mingw32 test/plugin/test_parser_apache2.rb
fluentd-1.16.6-x64-mingw32 test/plugin/test_parser_apache2.rb
fluentd-1.16.6-x64-mingw-ucrt test/plugin/test_parser_apache2.rb
fluentd-1.16.6 test/plugin/test_parser_apache2.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin/test_parser_apache2.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin/test_parser_apache2.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/fluentd-1.17.0-x64-mingw-ucrt/test/plugin/test_parser_apache2.rb
fluentd-1.17.0-x86-mingw32 test/plugin/test_parser_apache2.rb
fluentd-1.17.0-x64-mingw-ucrt test/plugin/test_parser_apache2.rb
fluentd-1.17.0-x64-mingw32 test/plugin/test_parser_apache2.rb
fluentd-1.17.0 test/plugin/test_parser_apache2.rb
fluentd-1.16.5-x64-mingw-ucrt test/plugin/test_parser_apache2.rb
fluentd-1.16.5-x86-mingw32 test/plugin/test_parser_apache2.rb
fluentd-1.16.5-x64-mingw32 test/plugin/test_parser_apache2.rb
fluentd-1.16.5 test/plugin/test_parser_apache2.rb