diff --git a/Rakefile b/Rakefile index 88f6e80..061329c 100644 --- a/Rakefile +++ b/Rakefile @@ -9,3 +9,9 @@ Rake::TestTask.new(:test) do |test| end task :default => :test + +desc 'Open an irb session preloaded with the gem library' +task :console do + sh 'irb -rubygems -I lib -r"fluent/load"' +end +task :c => :console diff --git a/test/helper.rb b/test/helper.rb index 615c410..0b75b4a 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -16,4 +16,12 @@ require 'fluent/plugin/filter_flowcounter_simple' class Test::Unit::TestCase + def capture_log(log) + tmp = log.out + log.out = StringIO.new + yield + return log.out.string + ensure + log.out = tmp + end end diff --git a/test/plugin/test_filter_flowcounter_simple.rb b/test/plugin/test_filter_flowcounter_simple.rb index df6b4ee..609090f 100644 --- a/test/plugin/test_filter_flowcounter_simple.rb +++ b/test/plugin/test_filter_flowcounter_simple.rb @@ -24,9 +24,9 @@ def test_filter msgs << {'message'=> 'b' * 100} end d = create_driver - filtered, log = filter(d, msgs) + filtered, out = filter(d, msgs) assert_equal msgs, filtered - assert( log.include?("count:20"), log ) + assert( out.include?("count:20"), out ) end private @@ -39,20 +39,11 @@ def filter(d, msgs) d.filter(msg, @time) } } - log = capture_log(d.instance.output.log) do + out = capture_log(d.instance.output.log) do d.instance.flush_emit(0) end filtered = d.filtered_as_array filtered_msgs = filtered.map {|m| m[2] } - [filtered_msgs, log] + [filtered_msgs, out] end - - def capture_log(log) - tmp = log.out - log.out = StringIO.new - yield - return log.out.string - ensure - log.out = tmp - end -end if defined?(Fluent::Test::FilterTestDriver) +end if defined?(Fluent::Filter) diff --git a/test/plugin/test_out_flowcounter_simple.rb b/test/plugin/test_out_flowcounter_simple.rb index 3fff44f..1d01263 100644 --- a/test/plugin/test_out_flowcounter_simple.rb +++ b/test/plugin/test_out_flowcounter_simple.rb @@ -66,15 +66,4 @@ def test_comment out = capture_log(d1.instance.log) { d1.instance.flush_emit(60) } assert( out.include?("comment:foobar"), out ) end - - private - - def capture_log(log) - tmp = log.out - log.out = StringIO.new - yield - return log.out.string - ensure - log.out = tmp - end end