1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|cloudwatch] Add mocked implementation of put_metric_alarm.

This commit is contained in:
Jens Braeuer 2011-10-04 14:32:23 +02:00
parent 584ce1b16c
commit 18bdf9e55b

View file

@ -56,6 +56,37 @@ module Fog
end
end
class Mock
require 'fog/aws/parsers/cloud_watch/put_metric_alarm'
# See: Fog::AWS::CloudWatch::Real.put_metric_alarm()
#
def put_metric_alarm(alarm_name, actions, metric)
if alarm_name.nil? or alarm_name.empty?
raise Fog::Compute::AWS::Error.new("The request must contain the parameter 'alarm_name'")
end
supported_actions = [ "InsufficientData", "OK", "Alarm" ]
found_actions = actions.keys.select {|key| supported_actions.include? key }
if found_actions.empty?
raise Fog::Compute::AWS::Error.new("The request must contain a supported action")
end
metric_requirements = [ "ComparisonOperator", "EvaluationPeriods", "Namespace", "Period", "Statistic", "Threshold" ]
metric_requirements.each do |req|
unless metric.has_key?(req)
raise Fog::Compute::AWS::Error.new("The request must contain a the parameter '%s'" % req)
end
end
response = Excon::Response.new
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id
}
response
end
end
end
end
end