Skip to content

Commit

Permalink
Add test and fix failed test
Browse files Browse the repository at this point in the history
Plugins that override `filter_stream` don't need check,
because they may not call `filter` or `filter_with_time`
  • Loading branch information
ganmacs committed Aug 8, 2016
1 parent b81b98c commit 0353283
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
2 changes: 2 additions & 0 deletions test/compat/test_calls_super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ def shutdown; end
end
class DummyGoodFilter < Fluent::Filter
def configure(conf); super; end
def filter(tag, time, record); end
def start; super; end
def before_shutdown; super; end
def shutdown; super; end
end
class DummyBadFilter < Fluent::Filter
def configure(conf); super; end
def filter(tag, time, record); end
def start; end
def before_shutdown; end
def shutdown; end
Expand Down
54 changes: 48 additions & 6 deletions test/test_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,57 @@ def emit(klass, msgs, conf = '')
end

sub_test_case 'configure' do
test 'check default' do
assert_nothing_raised { create_driver }
test 'check to implement `filter` method' do
klass = Class.new(Fluent::Filter) do |c|
def filter(tag, time, record); end
end

assert_nothing_raised do
klass.new
end
end

test 'check to implement `filter_with_time` method' do
klass = Class.new(Fluent::Filter) do |c|
def filter_with_time(tag, time, record); end
end

assert_nothing_raised do
klass.new
end
end

test 'DO NOT check when implement `filter_stream`' do
klass = Class.new(Fluent::Filter) do |c|
def filter_stream(tag, es); end
end

assert_nothing_raised do
klass.new
end
end
end

sub_test_case 'filter' do
test 'NotImplementedError' do
not_implemented_filter = Class.new(Fluent::Filter)
assert_raise(NotImplementedError) { emit(not_implemented_filter, ['foo']) }
klass = Class.new(Fluent::Filter)

assert_raise NotImplementedError do
klass.new
end
end

test 'duplicated method implementation' do
klass = Class.new(Fluent::Filter) do |c|
def filter(tag, time, record); end
def filter_with_time(tag, time, record); end
end

assert_raise do
klass.new
end
end
end

sub_test_case 'filter' do
test 'null filter' do
null_filter = Class.new(Fluent::Filter) do |c|
def filter(tag, time, record)
Expand Down Expand Up @@ -61,6 +101,7 @@ def filter(tag, time, record)
def filter_stream(tag, es)
MultiEventStream.new
end
def filter(tag, time, record); record; end
end
es = emit(null_filter, ['foo'])
assert_equal(0, es.instance_variable_get(:@record_array).size)
Expand All @@ -71,6 +112,7 @@ def filter_stream(tag, es)
def filter_stream(tag, es)
es
end
def filter(tag, time, record); record; end
end
es = emit(pass_filter, ['foo'])
assert_equal(1, es.instance_variable_get(:@record_array).size)
Expand Down

0 comments on commit 0353283

Please sign in to comment.