spec/out_grepcounter_spec.rb in fluent-plugin-grepcounter-0.0.1 vs spec/out_grepcounter_spec.rb in fluent-plugin-grepcounter-0.1.0.pre
- old
+ new
@@ -3,11 +3,10 @@
describe Fluent::GrepCounterOutput do
before { Fluent::Test.setup }
CONFIG = %[
input_key message
- regexp WARN
]
let(:tag) { 'syslog.host1' }
let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::GrepCounterOutput, tag).configure(config) }
describe 'test configure' do
@@ -15,30 +14,41 @@
context "lack of requirements" do
let(:config) { '' }
it { expect { driver }.to raise_error(Fluent::ConfigError) }
end
- context "check output_with_joined_delimiter" do
- let(:config) { CONFIG + %[ output_with_joined_delimiter \\n ] }
+ context 'invalid aggregate' do
+ let(:config) do
+ CONFIG + %[
+ aggregate foo
+ ]
+ end
it { expect { driver }.to raise_error(Fluent::ConfigError) }
end
+
+ context 'no tag for aggregate all' do
+ let(:config) do
+ CONFIG + %[
+ aggregate all
+ ]
+ end
+ it { expect { driver }.to raise_error(Fluent::ConfigError) }
+ end
end
describe 'good configuration' do
subject { driver.instance }
context "check default" do
let(:config) { CONFIG }
its(:input_key) { should == "message" }
its(:count_interval) { should == 5 }
- its(:regexp) { should == /WARN/ }
+ its(:regexp) { should be_nil }
its(:exclude) { should be_nil }
its(:threshold) { should == 1 }
- its(:output_tag) { should == 'count' }
- its(:add_tag_prefix) { should be_nil }
- its(:output_matched_message) { should be_false }
- its(:output_with_joined_delimiter) { should be_nil }
+ its(:output_tag) { should be_nil }
+ its(:add_tag_prefix) { should == 'count' }
end
end
end
describe 'test emit' do
@@ -58,48 +68,76 @@
context 'count_interval' do
pending
end
+ context 'default' do
+ let(:config) { CONFIG }
+ before do
+ Fluent::Engine.stub(:now).and_return(time)
+ Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, {"count"=>4,
+ "message"=>["2013/01/13T07:02:11.124202 INFO GET /ping","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"],
+ "input_tag" => tag,
+ "input_tag_last" => tag.split('.').last,
+ })
+ end
+ it { emit }
+ end
+
context 'regexp' do
let(:config) { CONFIG + %[ regexp WARN ] }
before do
Fluent::Engine.stub(:now).and_return(time)
- Fluent::Engine.should_receive(:emit).with("count", time, {"count"=>3, "input_tag"=>tag, "input_tag_last"=>tag.split(".").last})
+ Fluent::Engine.should_receive(:emit).with("count.#{tag}", 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"],
+ "input_tag" => tag,
+ "input_tag_last" => tag.split('.').last,
+ })
end
it { emit }
end
context 'exclude' do
let(:config) do
CONFIG + %[
+ regexp WARN
exclude favicon
]
end
before do
Fluent::Engine.stub(:now).and_return(time)
- Fluent::Engine.should_receive(:emit).with("count", time, {"count"=>2, "input_tag"=>tag, "input_tag_last"=>tag.split(".").last})
+ Fluent::Engine.should_receive(:emit).with("count.#{tag}", time, {"count"=>2,
+ "message"=>["2013/01/13T07:02:13.232645 WARN POST /auth","2013/01/13T07:02:43.632145 WARN POST /login"],
+ "input_tag" => tag,
+ "input_tag_last" => tag.split('.').last,
+ })
end
it { emit }
end
context 'threshold (less than or equal to)' do
let(:config) do
CONFIG + %[
+ regexp WARN
threshold 3
]
end
before do
Fluent::Engine.stub(:now).and_return(time)
- Fluent::Engine.should_receive(:emit).with("count", time, {"count"=>3, "input_tag"=>tag, "input_tag_last"=>tag.split(".").last})
+ Fluent::Engine.should_receive(:emit).with("count.#{tag}", 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"],
+ "input_tag" => tag,
+ "input_tag_last" => tag.split('.').last,
+ })
end
it { emit }
end
context 'threshold (greater)' do
let(:config) do
CONFIG + %[
+ regexp WARN
threshold 4
]
end
before do
Fluent::Engine.stub(:now).and_return(time)
@@ -109,61 +147,73 @@
end
context 'output_tag' do
let(:config) do
CONFIG + %[
+ regexp WARN
output_tag foo
]
end
before do
Fluent::Engine.stub(:now).and_return(time)
- Fluent::Engine.should_receive(:emit).with("foo", time, {"count"=>3, "input_tag"=>tag, "input_tag_last"=>tag.split(".").last})
+ Fluent::Engine.should_receive(:emit).with("foo", 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"],
+ "input_tag" => tag,
+ "input_tag_last" => tag.split('.').last,
+ })
end
it { emit }
end
context 'add_tag_prefix' do
let(:config) do
CONFIG + %[
+ regexp WARN
add_tag_prefix foo
]
end
before do
Fluent::Engine.stub(:now).and_return(time)
- Fluent::Engine.should_receive(:emit).with("foo.#{tag}", time, {"count"=>3, "input_tag"=>tag, "input_tag_last"=>tag.split(".").last})
+ Fluent::Engine.should_receive(:emit).with("foo.#{tag}", 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"],
+ "input_tag" => tag,
+ "input_tag_last" => tag.split('.').last,
+ })
end
it { emit }
end
- context 'output_matched_message' do
+ context 'output_delimiter' do
let(:config) do
+ # \\n shall be \n in config file
CONFIG + %[
- output_matched_message true
+ regexp WARN
+ output_delimiter \\n
]
end
before do
Fluent::Engine.stub(:now).and_return(time)
- Fluent::Engine.should_receive(:emit).with("count", time, {
- "count"=>3, "input_tag"=>tag, "input_tag_last"=>tag.split(".").last,
- "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.#{tag}", time, {"count"=>3,
+ "message"=>"2013/01/13T07:02:13.232645 WARN POST /auth\\n2013/01/13T07:02:21.542145 WARN GET /favicon.ico\\n2013/01/13T07:02:43.632145 WARN POST /login",
+ "input_tag" => tag,
+ "input_tag_last" => tag.split('.').last,
})
end
it { emit }
end
- context 'output_with_joined_delimiter' do
+ context 'aggregate all' do
let(:config) do
- # \\n shall be \n in config file
CONFIG + %[
- output_matched_message true
- output_with_joined_delimiter \\n
+ 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, "input_tag"=>tag, "input_tag_last"=>tag.split(".").last,
- "message"=>"2013/01/13T07:02:13.232645 WARN POST /auth\\n2013/01/13T07:02:21.542145 WARN GET /favicon.ico\\n2013/01/13T07:02:43.632145 WARN POST /login"
+ 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"],
})
end
it { emit }
end
end