spec/lib/flapjack/gateways/web_spec.rb in flapjack-0.7.34 vs spec/lib/flapjack/gateways/web_spec.rb in flapjack-0.7.35
- old
+ new
@@ -19,13 +19,10 @@
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
before(:each) do
Flapjack::RedisPool.should_receive(:new).and_return(redis)
Flapjack::Gateways::Web.instance_variable_set('@config', {})
@@ -38,10 +35,12 @@
redis.should_receive(:keys).with('executive_instance:*').and_return(["executive_instance:foo-app-01"])
redis.should_receive(:hget).once.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')
+ redis.should_receive(:zrange).with('current_entities', 0, -1).and_return(['foo-app-01.example.com'])
+ redis.should_receive(:zrange).with('current_checks:foo-app-01.example.com', 0, -1, {:withscores => true}).and_return([['ping', 1382329923.0]])
end
def expect_check_stats
Flapjack::Data::EntityCheck.should_receive(:count_all).
with(:redis => redis).and_return(1)
@@ -85,11 +84,11 @@
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 '/checks_all'
+ aget '/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).and_return(["#{entity_name}:#{check}"])
@@ -104,22 +103,22 @@
Flapjack::Data::EntityCheck.should_receive(:find_all_failing_by_entity).
with(:redis => redis).and_return({entity_name => [check]})
Flapjack::Data::EntityCheck.should_receive(:for_entity).
with(entity, 'ping', :redis => redis).and_return(entity_check)
- get '/checks_failing'
+ aget '/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}"])
expect_stats
expect_check_stats
expect_entity_stats
- get '/self_stats'
+ aget '/self_stats'
last_response.should be_ok
end
it "shows the state of a check for an entity" do
time = Time.now
@@ -150,29 +149,29 @@
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 "/check?entity=#{entity_name_esc}&check=ping"
+ aget "/check?entity=#{entity_name_esc}&check=ping"
last_response.should be_ok
# TODO test instance variables set to appropriate values
end
it "returns 404 if an unknown entity is requested" do
Flapjack::Data::Entity.should_receive(:find_by_name).
with(entity_name_esc, :redis => redis).and_return(nil)
- get "/check?entity=#{entity_name_esc}&check=ping"
+ aget "/check?entity=#{entity_name_esc}&check=ping"
last_response.should be_not_found
end
# TODO shouldn't create actual entity record
it "returns 404 if no entity check is passed" do
Flapjack::Data::Entity.should_receive(:find_by_name).
with(entity_name, :redis => redis).and_return(entity)
- get "/check?entity=#{entity_name_esc}"
+ aget "/check?entity=#{entity_name_esc}"
last_response.should be_not_found
end
it "creates an acknowledgement for an entity check" do
Flapjack::Data::Entity.should_receive(:find_by_name).
@@ -183,11 +182,11 @@
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?acknowledgement_id=1234"
+ apost "/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
@@ -206,11 +205,11 @@
with(entity, 'ping', :redis => redis).and_return(entity_check)
entity_check.should_receive(:create_scheduled_maintenance).
with(start_time.to_i, duration, :summary => summary)
- post "/scheduled_maintenances/#{entity_name_esc}/ping?"+
+ apost "/scheduled_maintenances/#{entity_name_esc}/ping?"+
"start_time=1+day+ago&duration=30+minutes&summary=wow"
last_response.status.should == 302
end
@@ -225,18 +224,18 @@
Flapjack::Data::EntityCheck.should_receive(:for_entity).
with(entity, 'ping', :redis => redis).and_return(entity_check)
entity_check.should_receive(:end_scheduled_maintenance).with(start_time)
- delete "/scheduled_maintenances/#{entity_name_esc}/ping?start_time=#{start_time}"
+ adelete "/scheduled_maintenances/#{entity_name_esc}/ping?start_time=#{start_time}"
last_response.status.should == 302
end
it "shows a list of all known contacts" do
Flapjack::Data::Contact.should_receive(:all)
- get "/contacts"
+ aget "/contacts"
last_response.should be_ok
end
it "shows details of an individual contact found by id" do
contact = double('contact')
@@ -246,10 +245,10 @@
contact.should_receive(:notification_rules).and_return([])
Flapjack::Data::Contact.should_receive(:find_by_id).
with('0362', :redis => redis).and_return(contact)
- get "/contacts/0362"
+ aget "/contacts/0362"
last_response.should be_ok
end
end