spec/out_grepcounter_spec.rb in fluent-plugin-grepcounter-0.4.2 vs spec/out_grepcounter_spec.rb in fluent-plugin-grepcounter-0.5.0
- old
+ new
@@ -16,12 +16,12 @@
let(:tag) { 'syslog.host1' }
let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::GrepCounterOutput, tag).configure(config) }
describe 'test configure' do
describe 'bad configuration' do
- context "lack of requirements" do
- let(:config) { '' }
+ context 'should not use classic style and new style together' do
+ let(:config) { %[input_key message\nregexp1 message foo] }
it { expect { driver }.to raise_error(Fluent::ConfigError) }
end
context 'invalid aggregate' do
let(:config) { CONFIG + %[aggregate foo] }
@@ -107,10 +107,26 @@
}))
end
it { emit }
end
+ context 'regexpN' do
+ let(:config) { %[ regexp1 message WARN ] }
+ before do
+ Fluent::Engine.stub(:now).and_return(time)
+ Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, expected.merge({
+ "count"=>3,
+ "message"=>[
+ {"message"=>"2013/01/13T07:02:13.232645 WARN POST /auth"},
+ {"message"=>"2013/01/13T07:02:21.542145 WARN GET /favicon.ico"},
+ {"message"=>"2013/01/13T07:02:43.632145 WARN POST /login"},
+ ],
+ }))
+ end
+ it { emit }
+ end
+
context 'exclude' do
let(:config) { CONFIG + %[regexp WARN \n exclude favicon] }
before do
Fluent::Engine.stub(:now).and_return(time)
Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, expected.merge({
@@ -122,10 +138,25 @@
}))
end
it { emit }
end
+ context 'excludeN' do
+ let(:config) { %[regexp1 message WARN \n exclude1 message favicon] }
+ before do
+ Fluent::Engine.stub(:now).and_return(time)
+ Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, expected.merge({
+ "count"=>2,
+ "message"=>[
+ {"message"=>"2013/01/13T07:02:13.232645 WARN POST /auth"},
+ {"message"=>"2013/01/13T07:02:43.632145 WARN POST /login"},
+ ],
+ }))
+ end
+ it { emit }
+ end
+
context "threshold and comparator (obsolete)" do
context '>= threshold' do
let(:config) { CONFIG + %[threshold 4] }
before do
Fluent::Engine.stub(:now).and_return(time)
@@ -299,15 +330,27 @@
Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, expected.merge("message" => message))
end
it { emit }
end
- context 'delimiter' do
+ context 'delimiter for old style (input_key)' do
# \\n shall be \n in config file
let(:config) { CONFIG + %[delimiter \\n] }
before do
Fluent::Engine.stub(:now).and_return(time)
message = expected["message"].join('\n')
+ Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, expected.merge("message" => message))
+ end
+ it { emit }
+ end
+
+ context 'delimiter for new style (regexpN or excludeN)' do
+ # \\n shall be \n in config file
+ let(:config) { %[regexp1 message .\ndelimiter \\n] }
+ before do
+ Fluent::Engine.stub(:now).and_return(time)
+ # I will think of good format later ...
+ message = "{\"message\"=>\"2013/01/13T07:02:11.124202 INFO GET /ping\"}\\n{\"message\"=>\"2013/01/13T07:02:13.232645 WARN POST /auth\"}\\n{\"message\"=>\"2013/01/13T07:02:21.542145 WARN GET /favicon.ico\"}\\n{\"message\"=>\"2013/01/13T07:02:43.632145 WARN POST /login\"}"
Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, expected.merge("message" => message))
end
it { emit }
end