-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: don't use deprecated way of capturing logs
`capture_log` is for older versions as well as the following. https://github.com/fluent/fluentd/blob/6c649d189b5cf65ccfce58f6952a31b24c775e72/lib/fluent/test/helpers.rb#L110-L122 We should use `Driver::logs` instead. In addition, this fixes the following points. * Update `helper.rb` by the default plugin template, since it was updated very long ago and there is no need to be different from the template. * Assert the entire log message (without the timestamp and the log level), since this is easier to see the diff of the expected and the actual when the assertion fails. Signed-off-by: Daijiro Fukuda <[email protected]>
- Loading branch information
Showing
3 changed files
with
23 additions
and
36 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,13 @@ | ||
require 'rubygems' | ||
require 'bundler' | ||
$LOAD_PATH.unshift(File.expand_path("../../", __FILE__)) | ||
require "test-unit" | ||
require "fluent/test" | ||
require "fluent/test/helpers" | ||
|
||
require 'test/unit' | ||
require 'test/unit/rr' | ||
Test::Unit::TestCase.include(Fluent::Test::Helpers) | ||
Test::Unit::TestCase.extend(Fluent::Test::Helpers) | ||
|
||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
|
||
require 'fluent/test' | ||
|
||
class Test::Unit::TestCase | ||
def capture_log(log) | ||
if defined?(Fluent::Test::TestLogger) and log.is_a?(Fluent::Test::TestLogger) # v0.14 | ||
yield | ||
log.out.logs.join("\n") | ||
else | ||
begin | ||
tmp = log.out | ||
log.out = StringIO.new | ||
yield | ||
return log.out.string | ||
ensure | ||
log.out = tmp | ||
end | ||
end | ||
def normalize_logs(logs) | ||
logs.collect do |log| | ||
log.gsub(/\A\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-+]\d{4} \[info\]: /, "") | ||
end | ||
end |
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
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