require_relative '../helper'
require 'timecop'
require 'fluent/test/driver/filter'
require 'fluent/plugin/filter_parser'
require 'flexmock/test_unit'
class ParserFilterTest < Test::Unit::TestCase
include FlexMock::TestCase
def setup
Fluent::Test.setup
@tag = 'test'
@default_time = Time.parse('2010-05-04 03:02:01 UTC')
Timecop.freeze(@default_time)
end
def teardown
super
Timecop.return
end
def assert_equal_parsed_time(expected, actual)
if expected.is_a?(Integer)
assert_equal(expected, actual.to_i)
else
assert_equal_event_time(expected, actual)
end
end
ParserError = Fluent::Plugin::Parser::ParserError
CONFIG = %[
key_name message
reserve_data true
@type regexp
expression /^(?.)(?.) (?
]
def create_driver(conf=CONFIG)
Fluent::Test::Driver::Filter.new(Fluent::Plugin::ParserFilter).configure(conf)
end
def test_configure
assert_raise(Fluent::ConfigError) {
create_driver('')
}
assert_raise(Fluent::ConfigError) {
create_driver %[
key_name foo
@type unknown_format_that_will_never_be_implemented
]
}
assert_nothing_raised {
create_driver %[
key_name foo
@type regexp
expression /(?.)/
]
}
assert_nothing_raised {
create_driver %[
key_name foo
@type json
]
}
assert_nothing_raised {
create_driver %[
key_name foo
format json
]
}
assert_nothing_raised {
create_driver %[
key_name foo
@type ltsv
]
}
assert_nothing_raised {
create_driver %[
key_name message
@type regexp
expression /^col1=(?.+) col2=(?.+)$/
]
}
d = create_driver %[
key_name foo
@type regexp
expression /(?.)/
]
assert_false d.instance.reserve_data
end
# CONFIG = %[
# remove_prefix test
# add_prefix parsed
# key_name message
# format /^(?.)(?.) (?