spec/lib/flapjack/gateways/api/entity_methods_spec.rb in flapjack-0.7.34 vs spec/lib/flapjack/gateways/api/entity_methods_spec.rb in flapjack-0.7.35

- old
+ new

@@ -21,13 +21,10 @@ before(:all) do Flapjack::Gateways::API.class_eval { set :raise_errors, true } - Flapjack::Gateways::API.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::API.instance_variable_set('@config', {}) @@ -38,11 +35,11 @@ it "returns a list of checks for an entity" do entity.should_receive(:check_list).and_return([check]) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/checks/#{entity_name_esc}" + aget "/checks/#{entity_name_esc}" last_response.should be_ok last_response.body.should == [check].to_json end context 'non-bulk API calls' do @@ -56,20 +53,20 @@ with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/status/#{entity_name_esc}" + aget "/status/#{entity_name_esc}" last_response.should be_ok last_response.body.should == ['status!'].to_json end it "should not show the status for an entity that's not found" do Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(nil) - get "/status/#{entity_name_esc}" + aget "/status/#{entity_name_esc}" last_response.should be_forbidden end it "returns the status for a check on an entity" do status = double('status', :to_json => 'status!'.to_json) @@ -82,31 +79,31 @@ with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/status/#{entity_name_esc}/#{check}" + aget "/status/#{entity_name_esc}/#{check}" last_response.should be_ok last_response.body.should == 'status!'.to_json end it "should not show the status for a check on an entity that's not found" do Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(nil) - get "/status/#{entity_name_esc}/#{check}" + aget "/status/#{entity_name_esc}/#{check}" last_response.should be_forbidden end it "should not show the status for a check that's not found on an entity" do 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, check, :redis => redis).and_return(nil) - get "/status/#{entity_name_esc}/#{check}" + aget "/status/#{entity_name_esc}/#{check}" last_response.should be_forbidden end it "returns a list of scheduled maintenance periods for an entity" do sched = double('sched', :to_json => 'sched!'.to_json) @@ -115,11 +112,11 @@ Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/scheduled_maintenances/#{entity_name_esc}" + aget "/scheduled_maintenances/#{entity_name_esc}" last_response.should be_ok last_response.body.should == [{:check => check, :scheduled_maintenance => sched}].to_json end it "returns a list of scheduled maintenance periods within a time window for an entity" do @@ -132,11 +129,11 @@ Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/scheduled_maintenances/#{entity_name_esc}?" + + aget "/scheduled_maintenances/#{entity_name_esc}?" + "start_time=#{CGI.escape(start.iso8601)}&end_time=#{CGI.escape(finish.iso8601)}" last_response.should be_ok last_response.body.should == [{:check => check, :scheduled_maintenance => sched}].to_json end @@ -148,11 +145,11 @@ 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, check, :redis => redis).and_return(entity_check) - get "/scheduled_maintenances/#{entity_name_esc}/#{check}" + aget "/scheduled_maintenances/#{entity_name_esc}/#{check}" last_response.should be_ok last_response.body.should == 'sched!'.to_json end it "creates an acknowledgement for an entity check" do @@ -164,11 +161,11 @@ Flapjack::Data::EntityCheck.should_receive(:for_entity). with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Event.should_receive(:create_acknowledgement). with(entity_name, check, :summary => nil, :duration => (4 * 60 * 60), :redis => redis) - post "/acknowledgements/#{entity_name_esc}/#{check}" + apost "/acknowledgements/#{entity_name_esc}/#{check}" last_response.status.should == 204 end it "returns a list of unscheduled maintenance periods for an entity" do unsched = double('unsched', :to_json => 'unsched!'.to_json) @@ -177,11 +174,11 @@ Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/unscheduled_maintenances/#{entity_name_esc}" + aget "/unscheduled_maintenances/#{entity_name_esc}" last_response.should be_ok last_response.body.should == [{:check => check, :unscheduled_maintenance => unsched}].to_json end it "returns a list of unscheduled maintenance periods for a check on an entity" do @@ -192,11 +189,11 @@ 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, check, :redis => redis).and_return(entity_check) - get "/unscheduled_maintenances/#{entity_name_esc}/#{check}" + aget "/unscheduled_maintenances/#{entity_name_esc}/#{check}" last_response.should be_ok last_response.body.should == 'unsched!'.to_json end it "returns a list of unscheduled maintenance periods within a time window for a check an entity" do @@ -210,11 +207,11 @@ 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, check, :redis => redis).and_return(entity_check) - get "/unscheduled_maintenances/#{entity_name_esc}/#{check}" + + aget "/unscheduled_maintenances/#{entity_name_esc}/#{check}" + "?start_time=#{CGI.escape(start.iso8601)}&end_time=#{CGI.escape(finish.iso8601)}" last_response.should be_ok last_response.body.should == 'unsched!'.to_json end @@ -225,11 +222,11 @@ Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/outages/#{entity_name_esc}" + aget "/outages/#{entity_name_esc}" last_response.should be_ok last_response.body.should == [{:check => check, :outages => out}].to_json end it "returns a list of outages for a check on an entity" do @@ -240,11 +237,11 @@ 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, check, :redis => redis).and_return(entity_check) - get "/outages/#{entity_name_esc}/#{check}" + aget "/outages/#{entity_name_esc}/#{check}" last_response.should be_ok last_response.body.should == 'out!'.to_json end it "returns a list of downtimes for an entity" do @@ -254,11 +251,11 @@ Flapjack::Gateways::API::EntityPresenter.should_receive(:new). with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/downtime/#{entity_name_esc}" + aget "/downtime/#{entity_name_esc}" last_response.should be_ok last_response.body.should == [{:check => check, :downtime => down}].to_json end it "returns a list of downtimes for a check on an entity" do @@ -269,11 +266,11 @@ 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, check, :redis => redis).and_return(entity_check) - get "/downtime/#{entity_name_esc}/#{check}" + aget "/downtime/#{entity_name_esc}/#{check}" last_response.should be_ok last_response.body.should == 'down!'.to_json end it "creates a test notification event for check on an entity" do @@ -287,11 +284,11 @@ with(entity, 'foo', :redis => redis).and_return(entity_check) Flapjack::Data::Event.should_receive(:test_notifications). with(entity_name, 'foo', hash_including(:redis => redis)) - post "/test_notifications/#{entity_name_esc}/foo" + apost "/test_notifications/#{entity_name_esc}/foo" last_response.status.should == 204 end end @@ -306,19 +303,19 @@ with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/status", :entity => entity_name + aget "/status", :entity => entity_name last_response.body.should == result.to_json end it "should not show the status for an entity that's not found" do Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(nil) - get "/status", :entity => entity_name + aget "/status", :entity => entity_name last_response.should be_forbidden end it "returns the status for a check on an entity" do status = double('status') @@ -332,31 +329,31 @@ with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/status", :check => {entity_name => check} + aget "/status", :check => {entity_name => check} last_response.should be_ok last_response.body.should == result.to_json end it "should not show the status for a check on an entity that's not found" do Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(nil) - get "/status", :check => {entity_name => check} + aget "/status", :check => {entity_name => check} last_response.should be_forbidden end it "should not show the status for a check that's not found on an entity" do 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, check, :redis => redis).and_return(nil) - get "/status", :check => {entity_name => check} + aget "/status", :check => {entity_name => check} last_response.should be_forbidden end it "creates an acknowledgement for an entity check" do Flapjack::Data::Entity.should_receive(:find_by_name). @@ -368,11 +365,11 @@ entity_check.should_receive(:check).and_return(check) Flapjack::Data::Event.should_receive(:create_acknowledgement). with(entity_name, check, :summary => nil, :duration => (4 * 60 * 60), :redis => redis) - post '/acknowledgements',:check => {entity_name => check} + apost '/acknowledgements',:check => {entity_name => check} last_response.status.should == 204 end it "deletes an unscheduled maintenance period for an entity check" do end_time = Time.now + (60 * 60) # an hour from now @@ -382,11 +379,11 @@ with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - delete "/unscheduled_maintenances", :check => {entity_name => check}, :end_time => end_time.iso8601 + adelete "/unscheduled_maintenances", :check => {entity_name => check}, :end_time => end_time.iso8601 last_response.status.should == 204 end it "creates a scheduled maintenance period for an entity check" do start = Time.now + (60 * 60) # an hour from now @@ -396,19 +393,19 @@ Flapjack::Data::EntityCheck.should_receive(:for_entity). with(entity, check, :redis => redis).and_return(entity_check) entity_check.should_receive(:create_scheduled_maintenance). with(start.getutc.to_i, duration, :summary => 'test') - post "/scheduled_maintenances/#{entity_name_esc}/#{check}?" + + apost "/scheduled_maintenances/#{entity_name_esc}/#{check}?" + "start_time=#{CGI.escape(start.iso8601)}&summary=test&duration=#{duration}" last_response.status.should == 204 end it "doesn't create a scheduled maintenance period if the start time isn't passed" do duration = (2 * 60 * 60) # two hours - post "/scheduled_maintenances/#{entity_name_esc}/#{check}?" + + apost "/scheduled_maintenances/#{entity_name_esc}/#{check}?" + "summary=test&duration=#{duration}" last_response.status.should == 403 end it "deletes a scheduled maintenance period for an entity check" do @@ -419,18 +416,18 @@ with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - delete "/scheduled_maintenances", :check => {entity_name => check}, :start_time => start_time.iso8601 + adelete "/scheduled_maintenances", :check => {entity_name => check}, :start_time => start_time.iso8601 last_response.status.should == 204 end it "doesn't delete a scheduled maintenance period if the start time isn't passed" do entity_check.should_not_receive(:end_scheduled_maintenance) - delete "/scheduled_maintenances", :check => {entity_name => check} + adelete "/scheduled_maintenances", :check => {entity_name => check} last_response.status.should == 403 end it "deletes scheduled maintenance periods for multiple entity checks" do start_time = Time.now + (60 * 60) # an hour from now @@ -446,11 +443,11 @@ with(entity, 'foo', :redis => redis).and_return(entity_check_2) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - delete "/scheduled_maintenances", :check => {entity_name => [check, 'foo']}, :start_time => start_time.iso8601 + adelete "/scheduled_maintenances", :check => {entity_name => [check, 'foo']}, :start_time => start_time.iso8601 last_response.status.should == 204 end it "returns a list of scheduled maintenance periods for an entity" do sm = double('sched_maint') @@ -462,11 +459,11 @@ with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/scheduled_maintenances", :entity => entity_name + aget "/scheduled_maintenances", :entity => entity_name last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of scheduled maintenance periods within a time window for an entity" do @@ -482,11 +479,11 @@ with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/scheduled_maintenances", :entity => entity_name, + aget "/scheduled_maintenances", :entity => entity_name, :start_time => start.iso8601, :end_time => finish.iso8601 last_response.should be_ok last_response.body.should == result.to_json end @@ -503,11 +500,11 @@ with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/scheduled_maintenances", :check => {entity_name => check} + aget "/scheduled_maintenances", :check => {entity_name => check} last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of unscheduled maintenance periods for an entity" do @@ -520,11 +517,11 @@ with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/unscheduled_maintenances", :entity => entity_name + aget "/unscheduled_maintenances", :entity => entity_name last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of unscheduled maintenance periods for a check on an entity" do @@ -540,11 +537,11 @@ with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/unscheduled_maintenances", :check => {entity_name => check} + aget "/unscheduled_maintenances", :check => {entity_name => check} last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of unscheduled maintenance periods within a time window for a check an entity" do @@ -563,11 +560,11 @@ with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/unscheduled_maintenances", :check => {entity_name => check}, + aget "/unscheduled_maintenances", :check => {entity_name => check}, :start_time => start.iso8601, :end_time => finish.iso8601 last_response.should be_ok last_response.body.should == result.to_json end @@ -609,11 +606,11 @@ Flapjack::Data::EntityCheck.should_receive(:for_entity). with(entity_2, 'foo', :redis => redis).and_return(foo_check) Flapjack::Data::EntityCheck.should_receive(:for_entity). with(entity_2, 'bar', :redis => redis).and_return(bar_check) - get "/outages", :entity => entity_name, :check => {entity_2_name => ['foo', 'bar']} + aget "/outages", :entity => entity_name, :check => {entity_2_name => ['foo', 'bar']} last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of outages for a check on an entity" do @@ -629,11 +626,11 @@ with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/outages", :check => {entity_name => check} + aget "/outages", :check => {entity_name => check} last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of downtimes for an entity" do @@ -646,11 +643,11 @@ with(entity, :redis => redis).and_return(entity_presenter) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/downtime", :entity => entity_name + aget "/downtime", :entity => entity_name last_response.should be_ok last_response.body.should == result.to_json end it "returns a list of downtimes for a check on an entity" do @@ -666,11 +663,11 @@ with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "/downtime", :check => {entity_name => check} + aget "/downtime", :check => {entity_name => check} last_response.should be_ok last_response.body.should == result.to_json end it "creates test notification events for all checks on an entity" do @@ -698,12 +695,11 @@ with(entity_name, check, hash_including(:redis => redis)) Flapjack::Data::Event.should_receive(:test_notifications). with(entity_name, 'foo', hash_including(:redis => redis)) - - post '/test_notifications', :entity => entity_name + apost '/test_notifications', :entity => entity_name last_response.status.should == 204 end it "creates a test notification event for check on an entity" do Flapjack::Data::Entity.should_receive(:find_by_name). @@ -714,14 +710,13 @@ entity_check.should_receive(:check).and_return(check) Flapjack::Data::EntityCheck.should_receive(:for_entity). with(entity, check, :redis => redis).and_return(entity_check) Flapjack::Data::Event.should_receive(:test_notifications). - with(entity_name, check, hash_including(:redis => redis)) + with(entity_name, check, hash_including(:redis => redis)) - - post '/test_notifications', :check => {entity_name => check} + apost '/test_notifications', :check => {entity_name => check} last_response.status.should == 204 end it "creates entities from a submitted list" do entities = {'entities' => @@ -736,18 +731,18 @@ } ] } Flapjack::Data::Entity.should_receive(:add).twice - post "/entities", entities.to_json, {'CONTENT_TYPE' => 'application/json'} + apost "/entities", entities.to_json, {'CONTENT_TYPE' => 'application/json'} last_response.status.should == 204 end it "does not create entities if the data is improperly formatted" do Flapjack::Data::Entity.should_not_receive(:add) - post "/entities", {'entities' => ["Hello", "there"]}.to_json, + apost "/entities", {'entities' => ["Hello", "there"]}.to_json, {'CONTENT_TYPE' => 'application/json'} last_response.status.should == 403 end it "does not create entities if they don't contain an id" do @@ -762,11 +757,11 @@ } ] } Flapjack::Data::Entity.should_receive(:add) - post "/entities", entities.to_json, {'CONTENT_TYPE' => 'application/json'} + apost "/entities", entities.to_json, {'CONTENT_TYPE' => 'application/json'} last_response.status.should == 403 end end @@ -776,91 +771,91 @@ entity.should_receive(:add_tags).with('web') entity.should_receive(:tags).and_return(['web']) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - post "entities/#{entity_name}/tags", :tag => 'web' + apost "entities/#{entity_name}/tags", :tag => 'web' last_response.should be_ok last_response.body.should be_json_eql( ['web'].to_json ) end it "does not set a single tag on an entity that's not found" do Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(nil) - post "entities/#{entity_name}/tags", :tag => 'web' + apost "entities/#{entity_name}/tags", :tag => 'web' last_response.should be_forbidden end it "sets multiple tags on an entity and returns current tags" do entity.should_receive(:add_tags).with('web', 'app') entity.should_receive(:tags).and_return(['web', 'app']) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) # NB submitted at a lower level as tag[]=web&tag[]=app - post "entities/#{entity_name}/tags", :tag => ['web', 'app'] + apost "entities/#{entity_name}/tags", :tag => ['web', 'app'] last_response.should be_ok last_response.body.should be_json_eql( ['web', 'app'].to_json ) end it "does not set multiple tags on an entity that's not found" do Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(nil) - post "entities/#{entity_name}/tags", :tag => ['web', 'app'] + apost "entities/#{entity_name}/tags", :tag => ['web', 'app'] last_response.should be_forbidden end it "removes a single tag from an entity" do entity.should_receive(:delete_tags).with('web') Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - delete "entities/#{entity_name}/tags", :tag => 'web' + adelete "entities/#{entity_name}/tags", :tag => 'web' last_response.status.should == 204 end it "does not remove a single tag from an entity that's not found" do Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(nil) - delete "entities/#{entity_name}/tags", :tag => 'web' + adelete "entities/#{entity_name}/tags", :tag => 'web' last_response.should be_forbidden end it "removes multiple tags from an entity" do entity.should_receive(:delete_tags).with('web', 'app') Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - delete "entities/#{entity_name}/tags", :tag => ['web', 'app'] + adelete "entities/#{entity_name}/tags", :tag => ['web', 'app'] last_response.status.should == 204 end it "does not remove multiple tags from an entity that's not found" do Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(nil) - delete "entities/#{entity_name}/tags", :tag => ['web', 'app'] + adelete "entities/#{entity_name}/tags", :tag => ['web', 'app'] last_response.should be_forbidden end it "gets all tags on an entity" do entity.should_receive(:tags).and_return(['web', 'app']) Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(entity) - get "entities/#{entity_name}/tags" + aget "entities/#{entity_name}/tags" last_response.should be_ok last_response.body.should be_json_eql( ['web', 'app'].to_json ) end it "does not get all tags on an entity that's not found" do Flapjack::Data::Entity.should_receive(:find_by_name). with(entity_name, :redis => redis).and_return(nil) - get "entities/#{entity_name}/tags" + aget "entities/#{entity_name}/tags" last_response.should be_forbidden end end