spec/out_grepcounter_spec.rb in fluent-plugin-grepcounter-0.1.1 vs spec/out_grepcounter_spec.rb in fluent-plugin-grepcounter-0.1.2
- old
+ new
@@ -1,8 +1,15 @@
# encoding: UTF-8
require_relative 'spec_helper'
+class Fluent::Test::OutputTestDriver
+ def emit_with_tag(record, time=Time.now, tag = nil)
+ @tag = tag if tag
+ emit(record, time)
+ end
+end
+
describe Fluent::GrepCounterOutput do
before { Fluent::Test.setup }
CONFIG = %[
input_key message
]
@@ -200,23 +207,47 @@
end
it { emit }
end
context 'aggregate all' do
+ let(:emit) do
+ driver.run { messages.each {|message| driver.emit_with_tag({'message' => message}, time, 'foo.bar') } }
+ driver.run { messages.each {|message| driver.emit_with_tag({'message' => message}, time, 'foo.bar2') } }
+ driver.instance.flush_emit(0)
+ end
+
let(:config) do
CONFIG + %[
regexp WARN
aggregate all
output_tag count
]
end
before do
Fluent::Engine.stub(:now).and_return(time)
- Fluent::Engine.should_receive(:emit).with("count", time, {"count"=>3,
- "message"=>["2013/01/13T07:02:13.232645 WARN POST /auth","2013/01/13T07:02:21.542145 WARN GET /favicon.ico","2013/01/13T07:02:43.632145 WARN POST /login"],
+ Fluent::Engine.should_receive(:emit).with("count", time, {"count"=>3*2,
+ "message"=>["2013/01/13T07:02:13.232645 WARN POST /auth","2013/01/13T07:02:21.542145 WARN GET /favicon.ico","2013/01/13T07:02:43.632145 WARN POST /login"]*2,
})
end
it { emit }
+ end
+
+ context 'replace_invalid_sequence' do
+ let(:config) do
+ CONFIG + %[
+ regexp WARN
+ replace_invalid_sequence true
+ ]
+ end
+ let(:messages) do
+ [
+ "\xff".force_encoding('UTF-8'),
+ ]
+ end
+ before do
+ Fluent::Engine.stub(:now).and_return(time)
+ end
+ it { expect { emit }.not_to raise_error(ArgumentError) }
end
end
end