spec/out_stats_spec.rb in fluent-plugin-stats-0.3.4 vs spec/out_stats_spec.rb in fluent-plugin-stats-0.3.5

- old
+ new

@@ -57,11 +57,11 @@ subject { driver.instance } let(:config) { CONFIG } its(:interval) { should == 5 } its(:tag) { should be_nil } its(:add_tag_prefix) { should == 'stats' } - its(:aggregate) { should == 'tag' } + its(:aggregate) { should == 'in_tag' } end end end describe 'test emit' do @@ -89,12 +89,12 @@ min _min$ avg _avg$ ] end before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("stats.#{tag}", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("stats.#{tag}", time, { "4xx_count"=>6,"5xx_count"=>6,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0 }) end it { emit } end @@ -108,15 +108,15 @@ avg _avg$ zero_emit true ] end before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("stats.#{tag}", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("stats.#{tag}", time, { "4xx_count"=>6,"5xx_count"=>6,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0 }) - Fluent::Engine.should_receive(:emit).with("stats.#{tag}", time, { + expect(Fluent::Engine).to receive(:emit).with("stats.#{tag}", time, { "4xx_count"=>0,"5xx_count"=>0,"reqtime_max"=>0,"reqtime_min"=>0,"reqtime_avg"=>0.0 }) end it { emit; empty_emit } end @@ -129,12 +129,12 @@ min_keys reqtime_min avg_keys reqtime_avg,not_found ] end before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("stats.#{tag}", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("stats.#{tag}", time, { "4xx_count"=>6,"5xx_count"=>6,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0 }) end it { emit } end @@ -157,12 +157,12 @@ {"reqtime"=>1.000,"reqsize"=>10}, {"reqtime"=>2.000,"reqsize"=>20}, ] end before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("stats.#{tag}", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("stats.#{tag}", time, { "reqtime_sum"=>3.000,"reqtime_max"=>2.000,"reqtime_min"=>1.000,"reqtime_avg"=>1.500,"reqsize_sum"=>30 }) end it { emit } end @@ -173,12 +173,12 @@ tag foo sum _count$ ] end before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("foo", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("foo", time, { "4xx_count"=>6,"5xx_count"=>6 }) end it { emit } end @@ -190,12 +190,12 @@ sum _count$ ] end let(:tag) { 'foo.bar' } before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("foo.#{tag}", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("foo.#{tag}", time, { "4xx_count"=>6,"5xx_count"=>6 }) end it { emit } end @@ -207,12 +207,12 @@ sum _count$ ] end let(:tag) { 'foo.bar' } before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("bar", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("bar", time, { "4xx_count"=>6,"5xx_count"=>6 }) end it { emit } end @@ -224,12 +224,12 @@ sum _count$ ] end let(:tag) { 'foo.bar' } before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("#{tag}.foo", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("#{tag}.foo", time, { "4xx_count"=>6,"5xx_count"=>6 }) end it { emit } end @@ -241,18 +241,35 @@ sum _count$ ] end let(:tag) { 'foo.bar' } before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("foo", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("foo", time, { "4xx_count"=>6,"5xx_count"=>6 }) end it { emit } end + context 'remove_tag_slice' do + let(:config) do + CONFIG + %[ + remove_tag_slice 0..-2 + sum _count$ + ] + end + let(:tag) { 'foo.bar' } + before do + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("foo", time, { + "4xx_count"=>6,"5xx_count"=>6 + }) + end + it { emit } + end + context 'aggregate' do let(:emit) do driver.run { messages.each {|message| driver.emit_with_tag(message, time, 'foo.bar') } } driver.run { messages.each {|message| driver.emit_with_tag(message, time, 'foo.bar2') } } driver.instance.flush_emit @@ -268,19 +285,19 @@ min _min$ avg _avg$ ] end before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("foo", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("foo", time, { "4xx_count"=>12,"5xx_count"=>12,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0 }) end it { emit } end - context 'aggregate tag' do + context 'aggregate in_tag' do let(:config) do CONFIG + %[ aggregate tag add_tag_prefix stats sum _count$ @@ -288,20 +305,41 @@ min _min$ avg _avg$ ] end before do - Fluent::Engine.stub(:now).and_return(time) - Fluent::Engine.should_receive(:emit).with("stats.foo.bar", time, { + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("stats.foo.bar", time, { "4xx_count"=>6,"5xx_count"=>6,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0 }) - Fluent::Engine.should_receive(:emit).with("stats.foo.bar2", time, { + expect(Fluent::Engine).to receive(:emit).with("stats.foo.bar2", time, { "4xx_count"=>6,"5xx_count"=>6,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0 }) end it { emit } end + + context 'aggregate out_tag' do + let(:config) do + CONFIG + %[ + aggregate out_tag + remove_tag_slice 0..-2 + add_tag_prefix stats + sum _count$ + max _max$ + min _min$ + avg _avg$ + ] + end + before do + allow(Fluent::Engine).to receive(:now).and_return(time) + expect(Fluent::Engine).to receive(:emit).with("stats.foo", time, { + "4xx_count"=>12,"5xx_count"=>12,"reqtime_max"=>6,"reqtime_min"=>1,"reqtime_avg"=>3.0 + }) + end + it { emit } + end end describe "store_file" do let(:store_file) do dirname = "tmp" @@ -331,12 +369,12 @@ driver.instance.start loaded_matches = driver.instance.matches loaded_saved_at = driver.instance.saved_at loaded_saved_duration = driver.instance.saved_duration - loaded_matches.should == stored_matches - loaded_saved_at.should == stored_saved_at - loaded_saved_duration.should == stored_saved_duration + expect(loaded_matches).to eql(stored_matches) + expect(loaded_saved_at).to eql(stored_saved_at) + expect(loaded_saved_duration).to eql(stored_saved_duration) end end end end