spec/lib/flapjack/gateways/web_spec.rb in flapjack-0.7.1 vs spec/lib/flapjack/gateways/web_spec.rb in flapjack-0.7.2
- old
+ new
@@ -17,10 +17,11 @@
let(:redis) { mock('redis') }
before(:all) do
Flapjack::Gateways::Web.class_eval {
set :raise_errors, true
+ set :show_exceptions, false
}
Flapjack::Gateways::Web.instance_variable_get('@middleware').delete_if {|m|
m[0] == Rack::FiberPool
}
end
@@ -31,14 +32,15 @@
Flapjack::Gateways::Web.instance_variable_set('@logger', @logger)
Flapjack::Gateways::Web.start
end
def expect_stats
- redis.should_receive(:keys).with('*').and_return([])
- redis.should_receive(:zcard).with('failed_checks')
+ redis.should_receive(:keys).with('*').and_return(['a', 'b', 'c'])
redis.should_receive(:keys).with('check:*:*').and_return([])
- redis.should_receive(:zscore).with('executive_instances', anything).and_return(Time.now.to_i)
+ redis.should_receive(:zcard).with('failed_checks')
+ 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
@@ -58,47 +60,49 @@
# 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
- redis.should_receive(:zrange).with("executive_instances", "0", "-1", :withscores => true)
+ 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)
Flapjack::Data::EntityCheck.should_receive(:for_entity).
with(entity, 'ping', :redis => redis).and_return(entity_check)
- get '/'
+ get '/checks_all'
last_response.should be_ok
end
it "shows a page listing failing checks" do
- redis.should_receive(:zrange).with("executive_instances", "0", "-1", :withscores => true)
- redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"])
+ 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"])
expect_stats
expect_entity_check_status(entity_check)
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)
- get '/failing'
+ get '/checks_failing'
last_response.should be_ok
end
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
- redis.should_receive(:zrange).with("executive_instances", "0", "-1", :withscores => true)
get '/self_stats'
last_response.should be_ok
end
@@ -107,10 +111,13 @@
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([])
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)
@@ -226,19 +233,26 @@
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
it "shows details of an individual contact found by id" do
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"