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

Begin work on mocking reserved instances. Provide describe_reserved_instances_offerings for mocking and real. REAL TALK

This commit is contained in:
Dylan Egan 2011-07-13 10:48:53 +10:00
parent a17ec2f42a
commit 14f242f640
4 changed files with 83 additions and 2 deletions

View file

@ -12,7 +12,7 @@ module Fog
def end_element(name)
case name
when 'availabilityZone', 'instanceType', 'productDescription', 'reservedInstancesOfferingId'
when 'availabilityZone', 'currencyCode', 'instanceType', 'instanceTenancy', 'productDescription', 'reservedInstancesOfferingId'
@reserved_instances_offering[name] = value
when 'duration'
@reserved_instances_offering[name] = value.to_i

View file

@ -32,7 +32,30 @@ module Fog
:parser => Fog::Parsers::Compute::AWS::DescribeReservedInstancesOfferings.new
}.merge!(params))
end
end
class Mock
def describe_reserved_instances_offerings(filters = {})
response = Excon::Response.new
response.status = 200
response.body = {
'reservedInstancesOfferingsSet' => [{
'reservedInstancesOfferingId' => Fog::AWS::Mock.reserved_instances_offering_id,
'instanceType' => 'm1.small',
'availabilityZone' => 'us-east-1d',
'duration' => 31536000,
'fixedPrice' => 350.0,
'usagePrice' => 0.03,
'productDescription' => 'Linux/UNIX',
'instanceTenancy' => 'default',
'currencyCode' => 'USD'
}],
'requestId' => Fog::AWS::Mock.request_id
}
response
end
end
end
end

View file

@ -178,6 +178,10 @@ module Fog
"r-#{Fog::Mock.random_hex(8)}"
end
def self.reserved_instances_offering_id
request_id
end
def self.snapshot_id
"snap-#{Fog::Mock.random_hex(8)}"
end

View file

@ -79,6 +79,43 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
'requestId' => String
}
@describe_reserved_instances_offerings_format = {
'reservedInstancesOfferingsSet' => [{
'reservedInstancesOfferingId' => String,
'instanceType' => String,
'availabilityZone' => String,
'duration' => Integer,
'fixedPrice' => Float,
'usagePrice' => Float,
'productDescription' => String,
'instanceTenancy' => String,
'currencyCode' => String
}],
'requestId' => String
}
@describe_reserved_instances_format = {
'reservedInstancesSet' => [{
'reservedInstancesId' => String,
'instanceType' => String,
'availabilityZone' => String,
'start' => Time,
'duration' => Integer,
'fixedPrice' => Float,
'usagePrice' => Float,
'instanceCount' => Integer,
'productDescription' => String,
'state' => String,
'tagSet' => [{
'key' => String,
'value' => String
}],
'instanceTenancy' => String,
'currencyCode' => String
}],
'requestId' => String
}
tests('success') do
@instance_id = nil
@ -151,6 +188,23 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
Fog::Compute[:aws].terminate_instances(@instance_id).body
end
tests("#describe_reserved_instances_offerings").formats(@describe_reserved_instances_offerings_format) do
@reserved_instances = Fog::Compute[:aws].describe_reserved_instances_offerings.body
@reserved_instances
end
if Fog.mocking?
pending
@reserved_instance_offering_id = @reserved_instances["reservedInstancesOfferingSet"].first["reservedInstancesOfferingId"]
tests("#purchase_reserved_instances_offering('#{@reserved_instance_offering_id}')").formats(@purchase_reserved_instances_offerings_format) do
Fog::Compute[:aws].purchase_reserved_instances_offering(@reserved_instance_offering_id, 1).body
end
tests("#describe_reserved_instances").formats(@describe_reserved_instances_format) do
Fog::Compute[:aws].describe_reserved_instances.body
end
end
end
tests('failure') do