From ca185960e4cec2d4088681935c60729d8f4dc8ab Mon Sep 17 00:00:00 2001 From: Ryan Richard Date: Fri, 30 Aug 2013 11:20:50 -0500 Subject: [PATCH] list_alarm and get_alarm mock support --- .../requests/monitoring/delete_alarm.rb | 14 ++++++ .../requests/monitoring/get_alarm.rb | 38 ++++++++++++++ .../requests/monitoring/list_alarms.rb | 50 +++++++++++++++++++ .../requests/monitoring/alarm_tests.rb | 4 -- 4 files changed, 102 insertions(+), 4 deletions(-) diff --git a/lib/fog/rackspace/requests/monitoring/delete_alarm.rb b/lib/fog/rackspace/requests/monitoring/delete_alarm.rb index 96faa8214..82f661515 100644 --- a/lib/fog/rackspace/requests/monitoring/delete_alarm.rb +++ b/lib/fog/rackspace/requests/monitoring/delete_alarm.rb @@ -10,7 +10,21 @@ module Fog :path => "entities/#{entity_id}/alarms/#{alarm_id}" ) end + end + class Mock + + def delete_alarm(entity_id, alarm_id) + + response = Excon::Response.new + response.status = 204 + response.body = "" + response.headers = { + + + } + response + end end end end diff --git a/lib/fog/rackspace/requests/monitoring/get_alarm.rb b/lib/fog/rackspace/requests/monitoring/get_alarm.rb index 6b2e59aee..c1c42eeeb 100644 --- a/lib/fog/rackspace/requests/monitoring/get_alarm.rb +++ b/lib/fog/rackspace/requests/monitoring/get_alarm.rb @@ -12,6 +12,44 @@ module Fog end end + + class Mock + + def get_alarm(entity_id, alarm_id) + + if entity_id == -1 || alarm_id == -1 + raise Fog::Rackspace::Monitoring::NotFound + end + + response = Excon::Response.new + response.status = 200 + response.body = { + "id" => alarm_id, + "label" => nil, + "check_id" => Fog::Mock.random_letters(10), + "criteria" => nil, + "disabled" => false, + "notification_plan_id" => "npTechnicalContactsEmail", + "metadata" => nil, + "created_at" => Time.now.to_i - 1, + "updated_at" => Time.now.to_i + } + response.headers = { + "Date" => Time.now.utc.to_s, + "Content-Type" => "application/json; charset=UTF-8", + "X-RateLimit-Limit" => "50000", + "X-RateLimit-Remaining" => "38687", + "X-RateLimit-Window" => "24 hours", + "X-RateLimit-Type" => "global", + "X-Response-Id" => "pomkondbno93gm3030fm303.mmowd", + "X-LB" => "ord1-maas-prod-api0", + "Vary" => "Accept-Encoding", + "Transfer-Encoding" => "chunked" + } + response.remote_ip = Fog::Rackspace::MockData.ipv4_address + response + end + end end end end diff --git a/lib/fog/rackspace/requests/monitoring/list_alarms.rb b/lib/fog/rackspace/requests/monitoring/list_alarms.rb index 854fd5ad7..8c9c9f465 100644 --- a/lib/fog/rackspace/requests/monitoring/list_alarms.rb +++ b/lib/fog/rackspace/requests/monitoring/list_alarms.rb @@ -12,6 +12,56 @@ module Fog end end + + class Mock + + def list_alarms(entity_id) + + if entity_id == -1 + raise Fog::Rackspace::Monitoring::NotFound + end + + response = Excon::Response.new + response.status = 200 + response.body = { + "values" => [ + { + "id" => Fog::Mock.random_letters(10), + "label" => nil, + "check_id" => Fog::Mock.random_letters(10), + "criteria" => nil, + "disabled" => false, + "notification_plan_id" => "npTechnicalContactsEmail", + "metadata" => nil, + "created_at" => Time.now.to_i - 1, + "updated_at" => Time.now.to_i + } + ], + "metadata" => + { + "count" =>1, + "limit" =>100, + "marker" =>nil, + "next_marker" =>nil, + "next_href" =>nil + } + } + response.headers = { + "Date" => Time.now.utc.to_s, + "Content-Type" => "application/json; charset=UTF-8", + "X-RateLimit-Limit" => "50000", + "X-RateLimit-Remaining" => "38687", + "X-RateLimit-Window" => "24 hours", + "X-RateLimit-Type" => "global", + "X-Response-Id" => "pomegmgm3030fm303.mmowd", + "X-LB" => "ord1-maas-prod-api0", + "Vary" => "Accept-Encoding", + "Transfer-Encoding" => "chunked" + } + response.remote_ip = Fog::Rackspace::MockData.ipv4_address + response + end + end end end end diff --git a/tests/rackspace/requests/monitoring/alarm_tests.rb b/tests/rackspace/requests/monitoring/alarm_tests.rb index 9be7767a3..17c18e9a9 100644 --- a/tests/rackspace/requests/monitoring/alarm_tests.rb +++ b/tests/rackspace/requests/monitoring/alarm_tests.rb @@ -24,11 +24,9 @@ Shindo.tests('Fog::Rackspace::Monitoring | alarm_tests', ['rackspace','rackspace account.update_alarm(entity_id,alarm_id,options).data end tests('#list alarms').formats(LIST_HEADERS_FORMAT) do - pending if Fog.mocking? account.list_alarms(entity_id).data[:headers] end tests('#get alarm').formats(LIST_HEADERS_FORMAT) do - pending if Fog.mocking? account.get_alarm(entity_id,alarm_id).data[:headers] end tests('#delete alarm').formats(DELETE_DATA_FORMAT) do @@ -46,11 +44,9 @@ Shindo.tests('Fog::Rackspace::Monitoring | alarm_tests', ['rackspace','rackspace response = account.update_alarm(-1,-1,options) end tests('#fail to list alarms').raises(Fog::Rackspace::Monitoring::NotFound) do - pending if Fog.mocking? account.list_alarms(-1) end tests('#fail to get alarm').raises(Fog::Rackspace::Monitoring::NotFound) do - pending if Fog.mocking? account.get_alarm(-1,-1) end tests('#fail to delete alarm(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do