From 0c27b3fd28f171eee51a2e7fab09e029041cad2a Mon Sep 17 00:00:00 2001 From: Daniel Reichert Date: Wed, 31 Jul 2013 14:14:10 -0700 Subject: [PATCH] [rackspace|monitoring] Adding working alarm tests --- .../models/monitoring/alarm_tests.rb | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/tests/rackspace/models/monitoring/alarm_tests.rb b/tests/rackspace/models/monitoring/alarm_tests.rb index fc1a10a0f..42431af94 100644 --- a/tests/rackspace/models/monitoring/alarm_tests.rb +++ b/tests/rackspace/models/monitoring/alarm_tests.rb @@ -1,47 +1,53 @@ -Shindo.tests('Fog::Rackspace::Monitoring | check', ['rackspace','rackspace_monitoring']) do +Shindo.tests('Fog::Rackspace::Monitoring | alarm', ['rackspace','rackspace_monitoring']) do service = Fog::Rackspace::Monitoring.new - - tests('#entity=') do - tests('should create new entity if object is a string') do - check = Fog::Rackspace::Monitoring::Check.new + tests('#alarm=') do + tests('should assign alarm id if object is a string') do + alarm = Fog::Rackspace::Monitoring::Alarm.new id = "123123" - check.entity = "123123" - returns(Fog::Rackspace::Monitoring::Entity) { check.entity.class } - returns(id) { check.entity.id } + alarm.id = "123123" + returns(Fog::Rackspace::Monitoring::Alarm) { alarm.class } + returns(id) { alarm.id } end - tests('should set entity if object is an entity') do - id = "555" - entity = Fog::Rackspace::Monitoring::Entity.new(:id => id) - check = Fog::Rackspace::Monitoring::Check.new + tests('should set check if object is a check') do + entity_id = "555" + entity = Fog::Rackspace::Monitoring::Entity.new(:id => entity_id) + check_id = "54321" + check = Fog::Rackspace::Monitoring::Check.new(:id => check_id) check.entity = entity - returns(Fog::Rackspace::Monitoring::Entity) { check.entity.class } - returns(id) { check.entity.id } + alarm = Fog::Rackspace::Monitoring::Alarm.new + alarm.check_id = check.id + + returns(Fog::Rackspace::Monitoring::Alarm) { alarm.class } + returns(check_id) { alarm.check_id } end end begin @entity = service.entities.create :label => "fog_#{Time.now.to_i.to_s}" - - options = CHECK_CREATE_OPTIONS.merge(:label => "fog_#{Time.now.to_i.to_s}", :entity => @entity) - collection = service.checks(:entity => @entity) + @check = service.checks.create(CHECK_CREATE_OPTIONS.merge( + :label => "fog_#{Time.now.to_i.to_s}", + :entity => @entity) ) + np = "npTechnicalContactsEmail" + options = CHECK_CREATE_OPTIONS.merge( + :label => "fog_#{Time.now.to_i.to_s}", + :entity => @entity, + :entity_id => @entity.id, + :check => @check, + :check_id => @check.id, + :notification_plan_id => np + ) + collection = service.alarms(:entity => @entity) model_tests(collection, options, false) do tests('#update').succeeds do new_label = "new_label_#{Time.now.to_i.to_s}" @instance.label = new_label - timeout = 2 - @instance.timeout = 2 @instance.save - @instance.timeout = -1 # blank out timeout just to make sure @instance.label = nil # blank out label just to make sure @instance.reload - returns(timeout) { @instance.timeout } returns(new_label) { @instance.label} end - tests('#metrics').succeeds do - @instance.metrics - end end ensure @entity.destroy unless @entity