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

parser is much closer to the original XML

test updates @data
This commit is contained in:
gilles 2011-03-15 15:35:32 -07:00
parent 87b5a30e19
commit 01cfd42011
5 changed files with 44 additions and 11 deletions

View file

@ -234,8 +234,8 @@ module Fog
raise ArgumentError.new("only Boolean allowed here")
end
#set the attribute
response[identity] == 'enabled' ? self.monitoring=true : self.monitoring=false
#set the attribute, there is only one instance_id here
response.body['instancesSet'][0]['monitoring'] == 'enabled' ? self.monitoring=true : self.monitoring=false
end
end

View file

@ -7,17 +7,23 @@ module Fog
def reset
@response = {}
@current_id = nil
@instance_set = []
@current_instance_set = {}
end
def end_element(name)
case name
when 'requestId'
@response['requestId'] = @value
when 'instanceId'
@current_id = @value
@current_instance_set['instanceId'] = @value
when 'item'
@current_id = nil
@instance_set << @current_instance_set
@current_instance_set = {}
when 'state'
@response[@current_id] = @value
@current_instance_set['monitoring'] = @value
when 'instancesSet'
@response['instancesSet'] = @instance_set
end
end

View file

@ -33,7 +33,16 @@ module Fog
def monitor_instances(instance_ids)
response = Excon::Response.new
response.status = 200
response.body = instance_ids.inject({}) { |memo, id| {memo[id] => 'enabled'} }
[*instance_ids].each do |instance_id|
if instance = @data[:instances][instance_id]
instance['monitoring']['state'] = 'enabled'
else
raise Fog::AWS::Compute::NotFound.new("The instance ID '#{instance_ids}' does not exist")
end
end
instances_set = [*instance_ids].inject([]) { |memo, id| memo << {'instanceId' => id, 'monitoring' => 'enabled'} }
response.body = {'requestId' => 'some_request_id', 'instancesSet' => instances_set}
response
end
end

View file

@ -33,9 +33,18 @@ module Fog
def unmonitor_instances(instance_ids)
response = Excon::Response.new
response.status = 200
response.body = instance_ids.inject({}) { |memo, id| {memo[id] => 'disabled'} }
[*instance_ids].each do |instance_id|
if instance = @data[:instances][instance_id]
instance['monitoring']['state'] = 'enabled'
else
raise Fog::AWS::Compute::NotFound.new("The instance ID '#{instance_ids}' does not exist")
end
end
instances_set = [*instance_ids].inject([]) { |memo, id| memo << {'instanceId' => id, 'monitoring' => 'disabled'} }
response.body = {'requestId' => 'some_request_id', 'instancesSet' => instances_set}
response
end
end
end

View file

@ -30,8 +30,17 @@ Shindo.tests('AWS::Compute::MonitorUnmonitorInstances | monitor/unmonitor parser
body = Nokogiri::XML::SAX::PushParser.new(parser)
body << aws_result
test('enabled') { parser.response['i-43a4412a'] == 'enabled' }
test('disabled') { parser.response['i-23a3397d'] == 'disabled' }
test('requestId') { parser.response['requestId'] == '59dbff89-35bd-4eac-99ed-be587EXAMPLE' }
test('enabled') do
selected = parser.response['instancesSet'].select { |item| item['instanceId'] == 'i-43a4412a' }[0]
selected['monitoring'] == 'enabled'
end
test('disabled') do
selected = parser.response['instancesSet'].select { |item| item['instanceId'] == 'i-23a3397d' }[0]
selected['monitoring'] == 'disabled'
end
end