test/plugin/test_test.rb in fluent-plugin-notifier-0.3.0 vs test/plugin/test_test.rb in fluent-plugin-notifier-1.0.0

- old
+ new

@@ -1,8 +1,20 @@ require 'helper' +require 'fluent/test/helpers' class NotifierOutputTestTest < Test::Unit::TestCase + include Fluent::Test::Helpers + + def setup + @i = Fluent::Plugin::NotifierOutput.new + end + + def gen_conf(hash) + root = @i.configured_section_create(nil, config_element('root', '', {}, [config_element('test', '', hash)])) + root.test_configs.first + end + TEST_CONF1 = { 'check' => 'numeric', 'target_key' => 'field1', 'lower_threshold' => '1', 'upper_threshold' => '2', } TEST_CONF2 = { @@ -38,141 +50,141 @@ 'check' => 'tag', 'exclude_pattern' => 'pos', } def test_init - t = Fluent::NotifierOutput::Test.new(TEST_CONF1) - assert_equal :numeric, t.check - assert_equal 'field1', t.target_key - assert_equal 1.0, t.lower_threshold - assert_equal 2.0, t.upper_threshold + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF1)) + assert_equal(:numeric, t.check) + assert_equal('field1', t.target_key) + assert_equal(1.0, t.lower_threshold) + assert_equal(2.0, t.upper_threshold) - t = Fluent::NotifierOutput::Test.new(TEST_CONF4) - assert_equal :regexp, t.check - assert_equal 'field2', t.target_key - assert_equal /hoge/, t.include_pattern - assert_equal /pos/, t.exclude_pattern + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF4)) + assert_equal(:regexp, t.check) + assert_equal('field2', t.target_key) + assert_equal(/hoge/, t.include_pattern) + assert_equal(/pos/, t.exclude_pattern) - t = Fluent::NotifierOutput::Test.new(TEST_CONF7) - assert_equal :tag, t.check + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF7)) + assert_equal(:tag, t.check) assert_nil t.target_key - assert_equal /hoge/, t.include_pattern - assert_equal /pos/, t.exclude_pattern + assert_equal(/hoge/, t.include_pattern) + assert_equal(/pos/, t.exclude_pattern) end def test_numeric - t = Fluent::NotifierOutput::Test.new(TEST_CONF1) - assert_equal :numeric, t.check - assert_equal 'field1', t.target_key - assert_equal 1.0, t.lower_threshold - assert_equal 2.0, t.upper_threshold + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF1)) + assert_equal(:numeric, t.check) + assert_equal('field1', t.target_key) + assert_equal(1.0, t.lower_threshold) + assert_equal(2.0, t.upper_threshold) - assert_equal false, t.test('test', {'field2' => '0.5'}) - assert_equal false, t.test('test', {'field1' => '0.5'}) - assert_equal true, t.test('test', {'field1' => 1}) - assert_equal true, t.test('test', {'field1' => 1.999999999999999999999999999999}) - assert_equal true, t.test('test', {'field1' => 2.0}) - assert_equal false, t.test('test', {'field1' => '2.0000001'}) + assert_equal(false, t.test('test', {'field2' => '0.5'})) + assert_equal(false, t.test('test', {'field1' => '0.5'})) + assert_equal(true, t.test('test', {'field1' => 1})) + assert_equal(true, t.test('test', {'field1' => 1.999999999999999999999999999999})) + assert_equal(true, t.test('test', {'field1' => 2.0})) + assert_equal(false, t.test('test', {'field1' => '2.0000001'})) - t = Fluent::NotifierOutput::Test.new(TEST_CONF2) + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF2)) # TEST_CONF2 = { # 'check' => 'numeric', 'target_key' => 'field1', # 'lower_threshold' => '1', # } - assert_equal false, t.test('test', {'field2' => '0.5'}) - assert_equal false, t.test('test', {'field1' => '0.5'}) - assert_equal true, t.test('test', {'field1' => 1}) - assert_equal true, t.test('test', {'field1' => 1.999999999999999999999999999999}) - assert_equal true, t.test('test', {'field1' => 2.0}) - assert_equal true, t.test('test', {'field1' => '2.0000001'}) - assert_equal true, t.test('test', {'field1' => 10000.32}) + assert_equal(false, t.test('test', {'field2' => '0.5'})) + assert_equal(false, t.test('test', {'field1' => '0.5'})) + assert_equal(true, t.test('test', {'field1' => 1})) + assert_equal(true, t.test('test', {'field1' => 1.999999999999999999999999999999})) + assert_equal(true, t.test('test', {'field1' => 2.0})) + assert_equal(true, t.test('test', {'field1' => '2.0000001'})) + assert_equal(true, t.test('test', {'field1' => 10000.32})) - t = Fluent::NotifierOutput::Test.new(TEST_CONF3) + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF3)) # TEST_CONF3 = { # 'check' => 'numeric', 'target_key' => 'field1', # 'upper_threshold' => '2', # } - assert_equal false, t.test('test', {'field2' => '0.5'}) - assert_equal true, t.test('test', {'field1' => '0.5'}) - assert_equal true, t.test('test', {'field1' => 1}) - assert_equal true, t.test('test', {'field1' => 1.999999999999999999999999999999}) - assert_equal true, t.test('test', {'field1' => 2.0}) - assert_equal false, t.test('test', {'field1' => '2.0000001'}) - assert_equal false, t.test('test', {'field1' => 10000.32}) + assert_equal(false, t.test('test', {'field2' => '0.5'})) + assert_equal(true, t.test('test', {'field1' => '0.5'})) + assert_equal(true, t.test('test', {'field1' => 1})) + assert_equal(true, t.test('test', {'field1' => 1.999999999999999999999999999999})) + assert_equal(true, t.test('test', {'field1' => 2.0})) + assert_equal(false, t.test('test', {'field1' => '2.0000001'})) + assert_equal(false, t.test('test', {'field1' => 10000.32})) - assert_equal true, t.test('test', {'field1' => 0.0}) - assert_equal true, t.test('test', {'field1' => '-1'}) + assert_equal(true, t.test('test', {'field1' => 0.0})) + assert_equal(true, t.test('test', {'field1' => '-1'})) end def test_regexp - t = Fluent::NotifierOutput::Test.new(TEST_CONF4) - assert_equal :regexp, t.check - assert_equal 'field2', t.target_key - assert_equal /hoge/, t.include_pattern - assert_equal /pos/, t.exclude_pattern + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF4)) + assert_equal(:regexp, t.check) + assert_equal('field2', t.target_key) + assert_equal(/hoge/, t.include_pattern) + assert_equal(/pos/, t.exclude_pattern) - assert_equal false, t.test('test', {'field1' => 'hoge foo bar'}) - assert_equal false, t.test('test', {'field2' => ''}) - assert_equal true, t.test('test', {'field2' => 'hoge foo bar'}) - assert_equal false, t.test('test', {'field2' => 'hoge pos foo bar'}) - assert_equal false, t.test('test', {'field2' => 'pos foo bar'}) - assert_equal false, t.test('test', {'field2' => 'pos hoge foo bar'}) - assert_equal true, t.test('test', {'field2' => 'hoge foo bar hoge'}) + assert_equal(false, t.test('test', {'field1' => 'hoge foo bar'})) + assert_equal(false, t.test('test', {'field2' => ''})) + assert_equal(true, t.test('test', {'field2' => 'hoge foo bar'})) + assert_equal(false, t.test('test', {'field2' => 'hoge pos foo bar'})) + assert_equal(false, t.test('test', {'field2' => 'pos foo bar'})) + assert_equal(false, t.test('test', {'field2' => 'pos hoge foo bar'})) + assert_equal(true, t.test('test', {'field2' => 'hoge foo bar hoge'})) - t = Fluent::NotifierOutput::Test.new(TEST_CONF5) + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF5)) # TEST_CONF5 = { # 'check' => 'regexp', 'target_key' => 'field2', # 'include_pattern' => 'hoge', # } - assert_equal false, t.test('test', {'field1' => 'hoge foo bar'}) - assert_equal false, t.test('test', {'field2' => ''}) - assert_equal true, t.test('test', {'field2' => 'hoge foo bar'}) - assert_equal true, t.test('test', {'field2' => 'hoge pos foo bar'}) - assert_equal false, t.test('test', {'field2' => 'pos foo bar'}) - assert_equal true, t.test('test', {'field2' => 'pos hoge foo bar'}) - assert_equal true, t.test('test', {'field2' => 'hoge foo bar hoge'}) + assert_equal(false, t.test('test', {'field1' => 'hoge foo bar'})) + assert_equal(false, t.test('test', {'field2' => ''})) + assert_equal(true, t.test('test', {'field2' => 'hoge foo bar'})) + assert_equal(true, t.test('test', {'field2' => 'hoge pos foo bar'})) + assert_equal(false, t.test('test', {'field2' => 'pos foo bar'})) + assert_equal(true, t.test('test', {'field2' => 'pos hoge foo bar'})) + assert_equal(true, t.test('test', {'field2' => 'hoge foo bar hoge'})) - t = Fluent::NotifierOutput::Test.new(TEST_CONF6) + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF6)) # TEST_CONF6 = { # 'check' => 'regexp', 'target_key' => 'field2', # 'exclude_pattern' => 'pos', # } - assert_equal false, t.test('test', {'field1' => 'hoge foo bar'}) - assert_equal true, t.test('test', {'field2' => ''}) - assert_equal true, t.test('test', {'field2' => 'hoge foo bar'}) - assert_equal false, t.test('test', {'field2' => 'hoge pos foo bar'}) - assert_equal false, t.test('test', {'field2' => 'pos foo bar'}) - assert_equal false, t.test('test', {'field2' => 'pos hoge foo bar'}) - assert_equal true, t.test('test', {'field2' => 'hoge foo bar hoge'}) + assert_equal(false, t.test('test', {'field1' => 'hoge foo bar'})) + assert_equal(true, t.test('test', {'field2' => ''})) + assert_equal(true, t.test('test', {'field2' => 'hoge foo bar'})) + assert_equal(false, t.test('test', {'field2' => 'hoge pos foo bar'})) + assert_equal(false, t.test('test', {'field2' => 'pos foo bar'})) + assert_equal(false, t.test('test', {'field2' => 'pos hoge foo bar'})) + assert_equal(true, t.test('test', {'field2' => 'hoge foo bar hoge'})) end def test_tag - t = Fluent::NotifierOutput::Test.new(TEST_CONF7) + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF7)) # TEST_CONF7 = { # 'check' => 'tag', # 'include_pattern' => 'hoge', # 'exclude_pattern' => 'pos', # } - assert_equal false, t.test('test', {'field1' => 'hoge foo bar'}) - assert_equal true, t.test('test.hoge', {'field1' => 'hoge foo bar'}) - assert_equal false, t.test('test.hoge.pos', {'field1' => 'hoge foo bar'}) + assert_equal(false, t.test('test', {'field1' => 'hoge foo bar'})) + assert_equal(true, t.test('test.hoge', {'field1' => 'hoge foo bar'})) + assert_equal(false, t.test('test.hoge.pos', {'field1' => 'hoge foo bar'})) - t = Fluent::NotifierOutput::Test.new(TEST_CONF8) + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF8)) # TEST_CONF8 = { # 'check' => 'tag', # 'include_pattern' => 'hoge', # } - assert_equal false, t.test('test', {'field1' => 'hoge foo bar'}) - assert_equal true, t.test('test.hoge', {'field1' => 'hoge foo bar'}) - assert_equal true, t.test('test.hoge.pos', {'field1' => 'hoge foo bar'}) + assert_equal(false, t.test('test', {'field1' => 'hoge foo bar'})) + assert_equal(true, t.test('test.hoge', {'field1' => 'hoge foo bar'})) + assert_equal(true, t.test('test.hoge.pos', {'field1' => 'hoge foo bar'})) - t = Fluent::NotifierOutput::Test.new(TEST_CONF9) + t = Fluent::Plugin::NotifierOutput::Test.new(gen_conf(TEST_CONF9)) # TEST_CONF9 = { # 'check' => 'tag', # 'exclude_pattern' => 'pos', # } - assert_equal true, t.test('test', {'field1' => 'hoge foo bar'}) - assert_equal true, t.test('test.hoge', {'field1' => 'hoge foo bar'}) - assert_equal false, t.test('test.hoge.pos', {'field1' => 'hoge foo bar'}) + assert_equal(true, t.test('test', {'field1' => 'hoge foo bar'})) + assert_equal(true, t.test('test.hoge', {'field1' => 'hoge foo bar'})) + assert_equal(false, t.test('test.hoge.pos', {'field1' => 'hoge foo bar'})) end end