test/plugin/test_out_notifier.rb in fluent-plugin-notifier-0.3.0 vs test/plugin/test_out_notifier.rb in fluent-plugin-notifier-1.0.0
- old
+ new
@@ -37,89 +37,102 @@
tag alert
target_key_pattern ^message.*$
</def>
]
- def create_driver(conf=CONFIG,tag='test')
- Fluent::Test::OutputTestDriver.new(Fluent::NotifierOutput, tag).configure(conf)
+ def create_driver(conf = CONFIG)
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::NotifierOutput).configure(conf)
end
def test_configure
- d = create_driver
- assert_nil nil # no one exception raised
+ assert_nothing_raised do
+ create_driver
+ end
end
- def test_emit
+ test "notify 0 events when num1 < warn_threshold and no test conditions" do
d = create_driver
- d.run do
- d.emit({'num1' => 20, 'message' => 'INFO'})
+ d.run(default_tag: "test") do
+ d.feed({'num1' => 20, 'message' => 'INFO'})
end
- assert_equal 0, d.emits.size
+ assert_equal(0, d.events.size)
+ end
+ test "notify 0 events when num1 > warn_threshold but no test conditions are satisfied" do
d = create_driver
- d.run do
- d.emit({'num1' => 30, 'message' => 'INFO'})
+ d.run(default_tag: "test") do
+ d.feed({'num1' => 30, 'message' => 'INFO'})
end
- assert_equal 0, d.emits.size
+ assert_equal(0, d.events.size)
+ end
- d = create_driver(CONFIG, 'test.input')
- d.run do
- d.emit({'num1' => 30, 'message' => 'INFO', 'numfield' => '30', 'textfield' => 'TargetX'})
+ test "notify 1 event when num1 > warn_threshold and satisfy test conditions" do
+ d = create_driver
+ d.run(default_tag: "test.input") do
+ d.feed({'num1' => 30, 'message' => 'INFO', 'numfield' => '30', 'textfield' => 'TargetX'})
end
- assert_equal 1, d.emits.size
- assert_equal 'alert.warn', d.emits[0][0]
- assert_equal 'pattern1', d.emits[0][2]['pattern']
- assert_equal 'input', d.emits[0][2]['target_tag']
- assert_equal 'numeric_upward', d.emits[0][2]['check_type']
- assert_equal 'warn', d.emits[0][2]['level']
- assert_equal 25.0, d.emits[0][2]['threshold']
- assert_equal 30.0, d.emits[0][2]['value']
+ assert_equal(1, d.events.size)
+ assert_equal('alert.warn', d.events[0][0])
+ assert_equal('pattern1', d.events[0][2]['pattern'])
+ assert_equal('input', d.events[0][2]['target_tag'])
+ assert_equal('numeric_upward', d.events[0][2]['check_type'])
+ assert_equal('warn', d.events[0][2]['level'])
+ assert_equal(25.0, d.events[0][2]['threshold'])
+ assert_equal(30.0, d.events[0][2]['value'])
+ end
+ test "notify 2 events when num1 > crit_threshold and message match warn_regexp" do
d = create_driver
- d.run do
- d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '30', 'textfield' => 'TargetX'})
+ d.run(default_tag: "test") do
+ d.feed({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '30', 'textfield' => 'TargetX'})
end
- assert_equal 2, d.emits.size
- assert_equal 'alert.crit', d.emits[0][0]
- assert_equal 'pattern1', d.emits[0][2]['pattern']
- assert_equal 'test', d.emits[0][2]['target_tag']
- assert_equal 'numeric_upward', d.emits[0][2]['check_type']
- assert_equal 'crit', d.emits[0][2]['level']
- assert_equal 50.0, d.emits[0][2]['threshold']
- assert_equal 60.0, d.emits[0][2]['value']
- assert_equal 'alert', d.emits[1][0]
- assert_equal 'pattern2', d.emits[1][2]['pattern']
- assert_equal 'test', d.emits[1][2]['target_tag']
- assert_equal 'string_find', d.emits[1][2]['check_type']
- assert_equal 'warn', d.emits[1][2]['level']
- assert_equal '/WARNING/', d.emits[1][2]['regexp']
- assert_equal 'foo bar WARNING xxxxx', d.emits[1][2]['value']
+ assert_equal(2, d.events.size)
+ assert_equal('alert.crit', d.events[0][0])
+ assert_equal('pattern1', d.events[0][2]['pattern'])
+ assert_equal('test', d.events[0][2]['target_tag'])
+ assert_equal('numeric_upward', d.events[0][2]['check_type'])
+ assert_equal('crit', d.events[0][2]['level'])
+ assert_equal(50.0, d.events[0][2]['threshold'])
+ assert_equal(60.0, d.events[0][2]['value'])
+ assert_equal('alert', d.events[1][0])
+ assert_equal('pattern2', d.events[1][2]['pattern'])
+ assert_equal('test', d.events[1][2]['target_tag'])
+ assert_equal('string_find', d.events[1][2]['check_type'])
+ assert_equal('warn', d.events[1][2]['level'])
+ assert_equal('/WARNING/', d.events[1][2]['regexp'])
+ assert_equal('foo bar WARNING xxxxx', d.events[1][2]['value'])
+ end
+ test "notify 0 events when test conditions are not satisfied numfield < lower_threshold" do
d = create_driver
- d.run do
- d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '2.4', 'textfield' => 'TargetX'})
+ d.run(default_tag: "test") do
+ d.feed({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '2.4', 'textfield' => 'TargetX'})
end
- assert_equal 0, d.emits.size
+ assert_equal(0, d.events.size)
+ end
+ test "notify 0 events when test conditions are not satisfied textfield matches exclude_pattern" do
d = create_driver
- d.run do
- d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '20', 'textfield' => 'TargetC'})
+ d.run(default_tag: "test") do
+ d.feed({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '20', 'textfield' => 'TargetC'})
end
- assert_equal 0, d.emits.size
+ assert_equal(0, d.events.size)
+ end
+ test "notify 0 events when test conditions are not satisfied textfield is missing" do
d = create_driver
- d.run do
- d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '20'})
+ d.run(default_tag: "test") do
+ d.feed({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '20'})
end
- assert_equal 0, d.emits.size
+ assert_equal(0, d.events.size)
end
def test_emit_invalid_byte
invalid_utf8 = "\xff".force_encoding('UTF-8')
d = create_driver
- assert_nothing_raised {
- d.run do
- d.emit({'num1' => 60, 'message' => "foo bar WARNING #{invalid_utf8}", 'numfield' => '30', 'textfield' => 'TargetX'})
+ assert_nothing_raised do
+ d.run(default_tag: "test") do
+ d.feed({'num1' => 60, 'message' => "foo bar WARNING #{invalid_utf8}", 'numfield' => '30', 'textfield' => 'TargetX'})
end
- }
+ end
end
end