Created
February 21, 2013 13:11
-
-
Save reiki4040/5004644 to your computer and use it in GitHub Desktop.
fluent-plugin-parserにテスト追加中。
pattern not matchメッセージがとれない。。。標準出力、エラーではなく別の場所に出てるのかな。
pluginの中で、$log.warn で出してるところを取りたい。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def capture_stderr(&block) | |
original = $stderr | |
captured = $stderr = StringIO.new | |
begin | |
yield | |
ensure | |
$stderr = original | |
end | |
captured.string | |
end | |
def capture_stdout(&block) | |
original = $stdout | |
captured = $stdout = StringIO.new | |
begin | |
yield | |
ensure | |
$stdout = original | |
end | |
captured.string | |
end | |
CONFIG_UNMATCH_SILENTE_TRUE = %[ | |
type parser | |
tag silent | |
key_name data | |
format /^cal1=(?<cal1>.+) cal2=(?<cal2>.+)$/ | |
unmatch_silent false | |
] | |
def test_warning_unmatch_false | |
matches_line = "cal1=aaa cal2=bbb" | |
unmatches_line = "ccc ddd" | |
d = create_driver(CONFIG_UNMATCH_SILENTE_TRUE, 'test.in') | |
result = capture_stderr{ | |
assert_nothing_raised { | |
d.run do | |
d.emit({'data' => matches_line}, Time.now.to_i) | |
d.emit({'data' => unmatches_line}, Time.now.to_i) | |
end | |
} | |
} | |
result2 = capture_stderr{ | |
d.emit({'data' => unmatches_line}, Time.now.to_i) | |
} | |
# result, result2 are empty... expected 'pattern not match:...' | |
# same capture_stdout | |
emits = d.emits | |
assert_equal 1, emits.length | |
assert_equal 'aaa', emits[0][2]['cal1'] | |
assert_equal 'bbb', emits[0][2]['cal2'] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment