Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate filter_grep to v0.14 API #1080

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/fluent/plugin/filter_grep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
require 'fluent/filter'
require 'fluent/config/error'

module Fluent
class GrepFilter < Filter
module Fluent::Plugin
class GrepFilter < Fluent::Plugin::Filter
Fluent::Plugin.register_filter('grep', self)

def initialize
Expand Down
25 changes: 15 additions & 10 deletions test/plugin/test_filter_grep.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative '../helper'
require 'fluent/test/driver/filter'
require 'fluent/plugin/filter_grep'

class GrepFilterTest < Test::Unit::TestCase
Expand All @@ -7,10 +8,11 @@ class GrepFilterTest < Test::Unit::TestCase
setup do
Fluent::Test.setup
@time = Fluent::Engine.now
@tag = 'test'
end

def create_driver(conf = '')
Test::FilterTestDriver.new(GrepFilter).configure(conf, true)
Fluent::Test::Driver::Filter.new(Fluent::Plugin::GrepFilter).configure(conf)
end

sub_test_case 'configure' do
Expand Down Expand Up @@ -45,19 +47,20 @@ def emit(config, msgs)
d = create_driver(config)
d.run {
msgs.each { |msg|
d.emit({'foo' => 'bar', 'message' => msg}, @time)
d.feed(@tag, @time, {'foo' => 'bar', 'message' => msg})
}
}.filtered
}
d.filtered
end

test 'empty config' do
es = emit('', messages)
assert_equal(4, es.instance_variable_get(:@record_array).size)
assert_equal(4, es.size)
end

test 'regexpN' do
es = emit('regexp1 message WARN', messages)
assert_equal(3, es.instance_variable_get(:@record_array).size)
assert_equal(3, es.size)
assert_block('only WARN logs') do
es.all? { |t, r|
!r['message'].include?('INFO')
Expand All @@ -67,7 +70,7 @@ def emit(config, msgs)

test 'excludeN' do
es = emit('exclude1 message favicon', messages)
assert_equal(3, es.instance_variable_get(:@record_array).size)
assert_equal(3, es.size)
assert_block('remove favicon logs') do
es.all? { |t, r|
!r['message'].include?('favicon')
Expand All @@ -93,8 +96,10 @@ def messages
sub_test_case 'grep non-string jsonable values' do
def emit(msg, config = 'regexp1 message 0')
d = create_driver(config)
d.emit({'foo' => 'bar', 'message' => msg}, @time)
d.run.filtered
d.run do
d.feed(@tag, @time, {'foo' => 'bar', 'message' => msg})
end
d.filtered
end

data(
Expand All @@ -104,12 +109,12 @@ def emit(msg, config = 'regexp1 message 0')
'float' => 0.1)
test "value" do |data|
es = emit(data)
assert_equal(1, es.instance_variable_get(:@record_array).size)
assert_equal(1, es.size)
end

test "value boolean" do
es = emit(true, %[regexp1 message true])
assert_equal(1, es.instance_variable_get(:@record_array).size)
assert_equal(1, es.size)
end
end
end