spec/lib/flapjack/gateways/web_spec.rb in flapjack-0.7.2 vs spec/lib/flapjack/gateways/web_spec.rb in flapjack-0.7.3

- old
+ new

@@ -32,20 +32,26 @@ Flapjack::Gateways::Web.instance_variable_set('@logger', @logger) Flapjack::Gateways::Web.start end def expect_stats - redis.should_receive(:keys).with('*').and_return(['a', 'b', 'c']) - redis.should_receive(:keys).with('check:*:*').and_return([]) - redis.should_receive(:zcard).with('failed_checks') + redis.should_receive(:dbsize).and_return(3) redis.should_receive(:keys).with('executive_instance:*').and_return(["executive_instance:foo-app-01"]) redis.should_receive(:hget).twice.and_return(Time.now.to_i - 60) redis.should_receive(:hgetall).twice.and_return({'all' => '8001', 'ok' => '8002'}, {'all' => '9001', 'ok' => '9002'}) redis.should_receive(:llen).with('events') end + def expect_check_stats + redis.should_receive(:keys).with('check:*:*').and_return([]) + redis.should_receive(:zcard).with('failed_checks') + end + + def expect_entity_stats + end + def expect_entity_check_status(ec) time = Time.now.to_i ec.should_receive(:state).and_return('ok') ec.should_receive(:last_update).and_return(time - (3 * 60 * 60)) @@ -60,16 +66,13 @@ # TODO add data, test that pages contain representations of it # (for the methods that access redis directly) it "shows a page listing all checks" do redis.should_receive(:keys).with('*:*:states').and_return(["#{entity_name}:#{check}:states"]) - redis.should_receive(:keys).with('check:*').and_return(["#{entity_name}:#{check}:states"]) - expect_stats + expect_check_stats - redis.should_receive(:zrange).with("failed_checks", 0, -1).and_return([]) - expect_entity_check_status(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) @@ -79,14 +82,13 @@ get '/checks_all' last_response.should be_ok end it "shows a page listing failing checks" do - redis.should_receive(:zrange).with('failed_checks', 0, -1).twice.and_return(["#{entity_name}:#{check}:states"]) - redis.should_receive(:keys).with('check:*').and_return(["#{entity_name}:#{check}:states"]) + redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"]) - expect_stats + expect_check_stats expect_entity_check_status(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) @@ -99,10 +101,12 @@ it "shows a page listing flapjack statistics" do redis.should_receive(:keys).with('check:*').and_return([]) redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"]) expect_stats + expect_check_stats + expect_entity_stats get '/self_stats' last_response.should be_ok end @@ -111,13 +115,11 @@ last_notifications = {:problem => time - ((3 * 60 * 60) + (5 * 60)), :recovery => time - (3 * 60 * 60), :acknowledgement => nil } - expect_stats - redis.should_receive(:keys).with('check:*').and_return([]) - redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return([]) + expect_check_stats entity_check.should_receive(:state).and_return('ok') entity_check.should_receive(:last_update).and_return(time - (3 * 60 * 60)) entity_check.should_receive(:last_change).and_return(time - (3 * 60 * 60)) entity_check.should_receive(:summary).and_return('all good') entity_check.should_receive(:last_notifications_of_each_type).and_return(last_notifications) @@ -233,13 +235,10 @@ last_response.status.should == 302 end it "shows a list of all known contacts" do Flapjack::Data::Contact.should_receive(:all) - redis.should_receive(:keys).with('check:*').and_return([]) - redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"]) - expect_stats get "/contacts" last_response.should be_ok end @@ -247,12 +246,9 @@ contact = mock('contact') contact.should_receive(:name).twice.and_return("Smithson Smith") contact.should_receive(:media).exactly(3).times.and_return({}) contact.should_receive(:entities).with(:checks => true).and_return([]) contact.should_receive(:notification_rules).and_return([]) - redis.should_receive(:keys).with('check:*').and_return([]) - redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"]) - expect_stats Flapjack::Data::Contact.should_receive(:find_by_id). with('0362', :redis => redis).and_return(contact) get "/contacts/0362"