Skip to content

Commit

Permalink
Add a test for fluent/plugin/output
Browse files Browse the repository at this point in the history
  • Loading branch information
ganmacs committed Aug 18, 2016
1 parent 5428755 commit 7487104
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/plugin/test_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ def try_write(chunk)
end

class OutputTest < Test::Unit::TestCase
class << self
def startup
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '../scripts'))
require 'fluent/plugin/out_test'
end

def shutdown
$LOAD_PATH.shift
end
end

def create_output(type=:full)
case type
when :bare then FluentPluginOutputTest::DummyBareOutput.new
Expand Down Expand Up @@ -477,6 +488,36 @@ def waiting(seconds)

i.stop; i.before_shutdown; i.shutdown; i.after_shutdown; i.close; i.terminate
end

test "Warn if primary type is different from secondary type and either primary or secondary has custom_format" do
o = create_output(:buffered)
mock(o.log).warn("secondary type should be same with primary one",
{ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" })

o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'test', 'name' => "cool"})]))
assert_not_nil o.instance_variable_get(:@secondary)
end

test "don't warn if primary type is same as secondary type" do
o = Fluent::Plugin::TestOutput.new
mock(o.log).warn("secondary type should be same with primary one",
{ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" }).never

o.configure(config_element('ROOT','',{'name' => "cool2"},
[config_element('secondary','',{'@type'=>'test', 'name' => "cool"}),
config_element('buffer','',{'@type'=>'memory'})]
))
assert_not_nil o.instance_variable_get(:@secondary)
end

test "don't warn if primary type is different from secondary type and both don't have custom_format" do
o = create_output(:standard)
mock(o.log).warn("secondary type should be same with primary one",
{ primary: o.class.to_s, secondary: "Fluent::Plugin::TestOutput" }).never

o.configure(config_element('ROOT','',{},[config_element('secondary','',{'@type'=>'test', 'name' => "cool"})]))
assert_not_nil o.instance_variable_get(:@secondary)
end
end

sub_test_case 'sync output feature' do
Expand Down

0 comments on commit 7487104

Please sign in to comment.