spec/lib/flapjack/gateways/jsonapi/report_methods_spec.rb in flapjack-0.8.12 vs spec/lib/flapjack/gateways/jsonapi/report_methods_spec.rb in flapjack-0.9.0

- old
+ new

@@ -14,87 +14,95 @@ let(:entity_check_name) { 'ping' } let(:check_presenter) { double(Flapjack::Gateways::JSONAPI::CheckPresenter) } it "returns the status for all entities" do - status = double('status') - expect(status).to receive(:as_json).and_return({:status => 'data'}) + status = {'status' => 'data'} expect(check_presenter).to receive(:status).and_return(status) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) - expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). - with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(Flapjack::Data::EntityCheck).to receive(:for_entity). + with(entity, 'SSH', :redis => redis).and_return(entity_check) expect(entity).to receive(:check_list).and_return(['SSH']) expect(Flapjack::Data::Entity).to receive(:all). with(:redis => redis).and_return([entity]) - expect(entity).to receive(:name).exactly(3).times.and_return(entity_name) - expect(entity).to receive(:id).and_return(entity_id) + expect(entity).to receive(:name).twice.and_return(entity_name) + expect(entity).to receive(:id).twice.and_return(entity_id) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :status_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :status_reports => [{ + :status => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :statuses => {'status' => 'data'} - }] - } + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } + } aget "/status_report/entities" expect(last_response).to be_ok expect(last_response.body).to eq(result.to_json) end it "returns the status for all checks on an entity" do - status = double('status') - expect(status).to receive(:as_json).and_return({:status => 'data'}) + status = {'status' => 'data'} expect(check_presenter).to receive(:status).and_return(status) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) - expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). - with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(Flapjack::Data::EntityCheck).to receive(:for_entity). + with(entity, 'SSH', :redis => redis).and_return(entity_check) expect(entity).to receive(:check_list).and_return(['SSH']) expect(Flapjack::Data::Entity).to receive(:find_by_id). with(entity_id, :redis => redis).and_return(entity) - expect(entity).to receive(:name).exactly(3).times.and_return(entity_name) - expect(entity).to receive(:id).and_return(entity_id) + expect(entity).to receive(:name).twice.and_return(entity_name) + expect(entity).to receive(:id).twice.and_return(entity_id) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :status_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :status_reports => [{ + :status => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :statuses => {'status' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/status_report/entities/#{entity_id}" expect(last_response).to be_ok @@ -108,40 +116,44 @@ aget "/status_report/entities/#{entity_id}" expect(last_response.status).to eq(404) end it "returns the status for an entity check" do - status = double('status') - expect(status).to receive(:as_json).and_return({:status => 'data'}) + status = {'status' => 'data'} expect(check_presenter).to receive(:status).and_return(status) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(entity).to receive(:name).twice.and_return(entity_name) expect(entity).to receive(:id).and_return(entity_id) - expect(entity).to receive(:name).and_return(entity_name) expect(entity_check).to receive(:entity).and_return(entity) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :status_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :status_reports => [{ + :status => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :statuses => {'status' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/status_report/checks/#{entity_name}:SSH" expect(last_response).to be_ok @@ -163,44 +175,48 @@ aget "/status_report/checks/#{entity_name}:SSH" expect(last_response).to be_not_found end it "returns a list of scheduled maintenance periods for an entity" do - sched_maint = double('scheduled_maintenances') - expect(sched_maint).to receive(:as_json).and_return({:scheduled_maintenances => 'data'}) + sched_maint = {:scheduled_maintenances => 'data'} expect(check_presenter).to receive(:scheduled_maintenance).and_return(sched_maint) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) - expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). - with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(Flapjack::Data::EntityCheck).to receive(:for_entity). + with(entity, 'SSH', :redis => redis).and_return(entity_check) expect(entity).to receive(:check_list).and_return(['SSH']) expect(Flapjack::Data::Entity).to receive(:find_by_id). with(entity_id, :redis => redis).and_return(entity) - expect(entity).to receive(:name).exactly(3).times.and_return(entity_name) - expect(entity).to receive(:id).and_return(entity_id) + expect(entity).to receive(:name).twice.and_return(entity_name) + expect(entity).to receive(:id).twice.and_return(entity_id) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :scheduled_maintenance_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :scheduled_maintenance_reports => [{ + :scheduled_maintenances => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :scheduled_maintenances => {'scheduled_maintenances' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/scheduled_maintenance_report/entities/#{entity_id}" expect(last_response).to be_ok @@ -209,168 +225,183 @@ it "returns a list of scheduled maintenance periods within a time window for an entity" do start = Time.parse('1 Jan 2012') finish = Time.parse('6 Jan 2012') - sched_maint = double('scheduled_maintenances') - expect(sched_maint).to receive(:as_json).and_return({:scheduled_maintenances => 'data'}) + sched_maint = {:scheduled_maintenances => 'data'} expect(check_presenter).to receive(:scheduled_maintenance). with(start.to_i, finish.to_i).and_return(sched_maint) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) - expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). - with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(Flapjack::Data::EntityCheck).to receive(:for_entity). + with(entity, 'SSH', :redis => redis).and_return(entity_check) expect(entity).to receive(:check_list).and_return(['SSH']) expect(Flapjack::Data::Entity).to receive(:find_by_id). with(entity_id, :redis => redis).and_return(entity) - expect(entity).to receive(:name).exactly(3).times.and_return(entity_name) - expect(entity).to receive(:id).and_return(entity_id) + expect(entity).to receive(:name).twice.and_return(entity_name) + expect(entity).to receive(:id).twice.and_return(entity_id) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :scheduled_maintenance_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :scheduled_maintenance_reports => [{ + :scheduled_maintenances => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :scheduled_maintenances => {'scheduled_maintenances' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/scheduled_maintenance_report/entities/#{entity_id}", :start_time => start.iso8601, :end_time => finish.iso8601 expect(last_response).to be_ok expect(last_response.body).to eq(result.to_json) end it "returns a list of scheduled maintenance periods for a check on an entity" do - sched_maint = double('scheduled_maintenances') - expect(sched_maint).to receive(:as_json).and_return({:scheduled_maintenances => 'data'}) + sched_maint = {:scheduled_maintenances => 'data'} expect(check_presenter).to receive(:scheduled_maintenance).and_return(sched_maint) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(entity).to receive(:name).twice.and_return(entity_name) expect(entity).to receive(:id).and_return(entity_id) - expect(entity).to receive(:name).and_return(entity_name) expect(entity_check).to receive(:entity).and_return(entity) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :scheduled_maintenance_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :scheduled_maintenance_reports => [{ + :scheduled_maintenances => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :scheduled_maintenances => {'scheduled_maintenances' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/scheduled_maintenance_report/checks/#{entity_name}:SSH" expect(last_response).to be_ok expect(last_response.body).to eq(result.to_json) end it "returns a list of unscheduled maintenance periods for an entity" do - unsched_maint = double('unscheduled_maintenances') - expect(unsched_maint).to receive(:as_json).and_return({:unscheduled_maintenances => 'data'}) + unsched_maint = {:unscheduled_maintenances => 'data'} expect(check_presenter).to receive(:unscheduled_maintenance).and_return(unsched_maint) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) - expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). - with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(Flapjack::Data::EntityCheck).to receive(:for_entity). + with(entity, 'SSH', :redis => redis).and_return(entity_check) expect(entity).to receive(:check_list).and_return(['SSH']) expect(Flapjack::Data::Entity).to receive(:find_by_id). with(entity_id, :redis => redis).and_return(entity) - expect(entity).to receive(:name).exactly(3).times.and_return(entity_name) - expect(entity).to receive(:id).and_return(entity_id) + expect(entity).to receive(:name).twice.and_return(entity_name) + expect(entity).to receive(:id).twice.and_return(entity_id) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :unscheduled_maintenance_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :unscheduled_maintenance_reports => [{ + :unscheduled_maintenances => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :unscheduled_maintenances => {'unscheduled_maintenances' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/unscheduled_maintenance_report/entities/#{entity_id}" expect(last_response).to be_ok expect(last_response.body).to eq(result.to_json) end it "returns a list of unscheduled maintenance periods for a check on an entity" do - unsched_maint = double('unscheduled_maintenances') - expect(unsched_maint).to receive(:as_json).and_return({:unscheduled_maintenances => 'data'}) + unsched_maint = {:unscheduled_maintenances => 'data'} expect(check_presenter).to receive(:unscheduled_maintenance).and_return(unsched_maint) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). with(entity_name, 'SSH', :redis => redis).and_return(entity_check) - + expect(entity).to receive(:name).twice.and_return(entity_name) expect(entity).to receive(:id).and_return(entity_id) - expect(entity).to receive(:name).and_return(entity_name) expect(entity_check).to receive(:entity).and_return(entity) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :unscheduled_maintenance_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :unscheduled_maintenance_reports => [{ + :unscheduled_maintenances => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :unscheduled_maintenances => {'unscheduled_maintenances' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/unscheduled_maintenance_report/checks/#{entity_name}:SSH" expect(last_response).to be_ok @@ -379,163 +410,178 @@ it "returns a list of unscheduled maintenance periods within a time window for a check an entity" do start = Time.parse('1 Jan 2012') finish = Time.parse('6 Jan 2012') - unsched_maint = double('scheduled_maintenances') - expect(unsched_maint).to receive(:as_json).and_return({:unscheduled_maintenances => 'data'}) + unsched_maint = {:unscheduled_maintenances => 'data'} expect(check_presenter).to receive(:unscheduled_maintenance). with(start.to_i, finish.to_i).and_return(unsched_maint) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(entity).to receive(:name).twice.and_return(entity_name) expect(entity).to receive(:id).and_return(entity_id) - expect(entity).to receive(:name).and_return(entity_name) expect(entity_check).to receive(:entity).and_return(entity) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :unscheduled_maintenance_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :unscheduled_maintenance_reports => [{ + :unscheduled_maintenances => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :unscheduled_maintenances => {'unscheduled_maintenances' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/unscheduled_maintenance_report/checks/#{entity_name}:SSH", :start_time => start.iso8601, :end_time => finish.iso8601 expect(last_response).to be_ok expect(last_response.body).to eq(result.to_json) end it "returns a list of outages for a check on an entity" do - outages = double('outages') - expect(outages).to receive(:as_json).and_return({:outages => 'data'}) + outages = {:outages => 'data'} expect(check_presenter).to receive(:outage).and_return(outages) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(entity).to receive(:name).twice.and_return(entity_name) expect(entity).to receive(:id).and_return(entity_id) - expect(entity).to receive(:name).and_return(entity_name) expect(entity_check).to receive(:entity).and_return(entity) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :outage_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :outage_reports => [{ + :outages => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :outages => {'outages' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/outage_report/checks/#{entity_name}:SSH" expect(last_response).to be_ok expect(last_response.body).to eq(result.to_json) end it "returns a list of downtimes for an entity" do - downtime = double('downtime') - expect(downtime).to receive(:as_json).and_return({:downtime => 'data'}) + downtime = {:downtime => 'data'} expect(check_presenter).to receive(:downtime).and_return(downtime) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) - expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). - with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(Flapjack::Data::EntityCheck).to receive(:for_entity). + with(entity, 'SSH', :redis => redis).and_return(entity_check) expect(entity).to receive(:check_list).and_return(['SSH']) expect(Flapjack::Data::Entity).to receive(:find_by_id). with(entity_id, :redis => redis).and_return(entity) - expect(entity).to receive(:name).exactly(3).times.and_return(entity_name) + expect(entity).to receive(:name).twice.and_return(entity_name) + expect(entity).to receive(:id).twice.and_return(entity_id) - expect(entity).to receive(:id).and_return(entity_id) + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') - expect(entity_check).to receive(:check).twice.and_return('SSH') - result = { - :downtime_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :downtime_reports => [{ + :downtime => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :downtimes => {'downtime' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/downtime_report/entities/#{entity_id}" expect(last_response).to be_ok expect(last_response.body).to eq(result.to_json) end it "returns a list of downtimes for a check on an entity" do - downtime = double('downtime') - expect(downtime).to receive(:as_json).and_return({:downtime => 'data'}) + downtime = {:downtime => 'data'} expect(check_presenter).to receive(:downtime).and_return(downtime) expect(Flapjack::Gateways::JSONAPI::CheckPresenter).to receive(:new). with(entity_check).and_return(check_presenter) expect(Flapjack::Data::EntityCheck).to receive(:for_entity_name). with(entity_name, 'SSH', :redis => redis).and_return(entity_check) + expect(entity).to receive(:name).twice.and_return(entity_name) expect(entity).to receive(:id).and_return(entity_id) - expect(entity).to receive(:name).and_return(entity_name) expect(entity_check).to receive(:entity).and_return(entity) - expect(entity_check).to receive(:check).twice.and_return('SSH') + expect(entity_check).to receive(:check).exactly(3).times.and_return('SSH') result = { - :downtime_reports => [{ - 'id' => entity_id, - 'name' => entity_name, - 'links' => { - 'checks' => ["#{entity_name}:SSH"], + :downtime_reports => [{ + :downtime => 'data', + :links => { + :entity => [entity_id], + :check => ["#{entity_name}:SSH"] + }}], + :linked => { + :entities => [{ + :id => entity_id, + :name => entity_name, + :links => { + :checks => ["#{entity_name}:SSH"], } }], - :linked => { - :checks => [{ - :id => "#{entity_name}:SSH", - :name => 'SSH', - :downtimes => {'downtime' => 'data'} - }] + :checks => [{ + :id => "#{entity_name}:SSH", + :name => 'SSH', + }] } } aget "/downtime_report/checks/#{entity_name}:SSH" expect(last_response).to be_ok