spec/lib/flapjack/gateways/web_spec.rb in flapjack-0.7.14 vs spec/lib/flapjack/gateways/web_spec.rb in flapjack-0.7.15
- old
+ new
@@ -54,13 +54,13 @@
time = Time.now.to_i
ec.should_receive(:state).and_return('ok')
ec.should_receive(:last_update).and_return(time - (3 * 60 * 60))
ec.should_receive(:last_change).and_return(time - (3 * 60 * 60))
- ec.should_receive(:last_problem_notification).and_return(time - ((3 * 60 * 60) + (5 * 60)))
- ec.should_receive(:last_recovery_notification).and_return(time - (3 * 60 * 60))
- ec.should_receive(:last_acknowledgement_notification).and_return(nil)
+ ec.should_receive(:last_notification_for_state).with(:problem).and_return({:timestamp => time - ((3 * 60 * 60) + (5 * 60))})
+ ec.should_receive(:last_notification_for_state).with(:recovery).and_return({:timestamp => time - (3 * 60 * 60)})
+ ec.should_receive(:last_notification_for_state).with(:acknowledgement).and_return({:timestamp => nil})
ec.should_receive(:in_scheduled_maintenance?).and_return(false)
ec.should_receive(:in_unscheduled_maintenance?).and_return(false)
end
# TODO add data, test that pages contain representations of it
@@ -109,29 +109,33 @@
get '/self_stats'
last_response.should be_ok
end
it "shows the state of a check for an entity" do
- time = Time.now.to_i
+ time = Time.now
+ Time.should_receive(:now).exactly(4).times.and_return(time)
- last_notifications = {:problem => time - ((3 * 60 * 60) + (5 * 60)),
- :recovery => time - (3 * 60 * 60),
- :acknowledgement => nil }
+ last_notifications = {:problem => {:timestamp => time.to_i - ((3 * 60 * 60) + (5 * 60)), :summary => 'prob'},
+ :recovery => {:timestamp => time.to_i - (3 * 60 * 60), :summary => nil},
+ :acknowledgement => {:timestamp => nil, :summary => nil} }
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(:last_update).and_return(time.to_i - (3 * 60 * 60))
+ entity_check.should_receive(:last_change).and_return(time.to_i - (3 * 60 * 60))
entity_check.should_receive(:summary).and_return('all good')
entity_check.should_receive(:details).and_return('seriously, all very wonderful')
entity_check.should_receive(:last_notifications_of_each_type).and_return(last_notifications)
entity_check.should_receive(:maintenances).with(nil, nil, :scheduled => true).and_return([])
entity_check.should_receive(:failed?).and_return(false)
entity_check.should_receive(:current_maintenance).with(:scheduled => true).and_return(false)
entity_check.should_receive(:current_maintenance).with(:scheduled => false).and_return(false)
entity_check.should_receive(:contacts).and_return([])
+ entity_check.should_receive(:historical_states).
+ with(nil, time.to_i, :order => 'desc', :limit => 20).and_return([])
+
Flapjack::Data::Entity.should_receive(:find_by_name).
with(entity_name, :redis => redis).and_return(entity)
Flapjack::Data::EntityCheck.should_receive(:for_entity).
with(entity, 'ping', :redis => redis).and_return(entity_check)
@@ -163,13 +167,14 @@
with(entity_name, :redis => redis).and_return(entity)
Flapjack::Data::EntityCheck.should_receive(:for_entity).
with(entity, 'ping', :redis => redis).and_return(entity_check)
- entity_check.should_receive(:create_acknowledgement).
- with(an_instance_of(Hash))
+ Flapjack::Data::Event.should_receive(:create_acknowledgement).
+ with(entity_name, 'ping', :summary => "", :duration => (4 * 60 * 60),
+ :acknowledgement_id => '1234', :redis => redis)
- post "/acknowledgements/#{entity_name_esc}/ping"
+ post "/acknowledgements/#{entity_name_esc}/ping?acknowledgement_id=1234"
last_response.status.should == 302
end
it "creates a scheduled maintenance period for an entity check" do
t = Time.now.to_i