Skip to content

Commit

Permalink
mock related fixes and marking unmocked tests pending
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Oct 14, 2010
1 parent b224ccb commit 592c8cc
Show file tree
Hide file tree
Showing 26 changed files with 95 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/fog/aws/requests/compute/create_snapshot.rb
Expand Up @@ -51,6 +51,7 @@ def create_snapshot(volume_id, description = nil)
response.body = {
'requestId' => Fog::AWS::Mock.request_id
}.merge!(data)
@data[:snapshots][snapshot_id]['tagSet'] = {}
else
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
Expand Down
12 changes: 6 additions & 6 deletions lib/fog/aws/requests/compute/describe_availability_zones.rb
Expand Up @@ -44,10 +44,10 @@ def describe_availability_zones(filters = {})
response = Excon::Response.new

availability_zone_info = [
{"regionName"=>"us-east-1", "zoneName"=>"us-east-1a", "zoneState"=>"available"},
{"regionName"=>"us-east-1", "zoneName"=>"us-east-1b", "zoneState"=>"available"},
{"regionName"=>"us-east-1", "zoneName"=>"us-east-1c", "zoneState"=>"available"},
{"regionName"=>"us-east-1", "zoneName"=>"us-east-1d", "zoneState"=>"available"}
{"messageSet" => [], "regionName" => "us-east-1", "zoneName" => "us-east-1a", "zoneState" => "available"},
{"messageSet" => [], "regionName" => "us-east-1", "zoneName" => "us-east-1b", "zoneState" => "available"},
{"messageSet" => [], "regionName" => "us-east-1", "zoneName" => "us-east-1c", "zoneState" => "available"},
{"messageSet" => [], "regionName" => "us-east-1", "zoneName" => "us-east-1d", "zoneState" => "available"},
]

aliases = {'region-name' => 'regionName', 'zone-name' => 'zoneName', 'state' => 'zoneState'}
Expand All @@ -58,8 +58,8 @@ def describe_availability_zones(filters = {})

response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'availabilityZoneInfo' => availability_zone_info
'availabilityZoneInfo' => availability_zone_info,
'requestId' => Fog::AWS::Mock.request_id
}
response
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/aws/requests/compute/describe_instances.rb
Expand Up @@ -74,7 +74,7 @@ def describe_instances(filters = {})
filters = {'instance-id' => [*filters]}
end

if Fog.mocking? && filter.keys.any? {|key| key =~ /^tag/}
if filters.keys.any? {|key| key =~ /^tag/}
Formatador.display_line("[yellow][WARN] describe_instances tag filters are not yet mocked[/] [light_black](#{caller.first})[/]")
Fog::Mock.not_implemented
end
Expand Down Expand Up @@ -184,7 +184,7 @@ def describe_instances(filters = {})
'ownerId' => instance['ownerId'],
'reservationId' => instance['reservationId']
}
reservation_set[instance['reservationId']]['instancesSet'] << instance.reject{|key,value| !['amiLaunchIndex', 'architecture', 'blockDeviceMapping', 'clientToken', 'dnsName', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'ipAddress', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'placement', 'privateDnsName', 'privateIpAddress', 'productCodes', 'ramdiskId', 'reason', 'rootDeviceType'].include?(key)}
reservation_set[instance['reservationId']]['instancesSet'] << instance.reject{|key,value| !['amiLaunchIndex', 'architecture', 'blockDeviceMapping', 'clientToken', 'dnsName', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'ipAddress', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'placement', 'privateDnsName', 'privateIpAddress', 'productCodes', 'ramdiskId', 'reason', 'rootDeviceType', 'stateReason', 'tagSet'].include?(key)}
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/requests/compute/describe_snapshots.rb
Expand Up @@ -59,7 +59,7 @@ def describe_snapshots(filters = {}, options = {})
Formatador.display_line("[yellow][WARN] describe_snapshots with a second param is deprecated, use describe_snapshots(options) instead[/] [light_black](#{caller.first})[/]")
end

if Fog.mocking? && filter.keys.any? {|key| key =~ /^tag/}
if filters.keys.any? {|key| key =~ /^tag/}
Formatador.display_line("[yellow][WARN] describe_snapshots tag filters are not yet mocked[/] [light_black](#{caller.first})[/]")
Fog::Mock.not_implemented
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/requests/compute/describe_volumes.rb
Expand Up @@ -49,7 +49,7 @@ def describe_volumes(filters = {})
filters = {'volume-id' => [*filters]}
end

if Fog.mocking? && filter.keys.any? {|key| key =~ /^tag/}
if filters.keys.any? {|key| key =~ /^tag/}
Formatador.display_line("[yellow][WARN] describe_volumes tag filters are not yet mocked[/] [light_black](#{caller.first})[/]")
Fog::Mock.not_implemented
end
Expand Down
2 changes: 2 additions & 0 deletions lib/fog/aws/requests/compute/run_instances.rb
Expand Up @@ -147,6 +147,8 @@ def run_instances(image_id, min_count, max_count, options = {})
'ownerId' => @owner_id,
'privateIpAddress' => nil,
'reservationId' => reservation_id,
'stateReason' => {},
'tagSet' => {}
})
end
response.body = {
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/linode/requests/compute/avail_linodeplans.rb
Expand Up @@ -9,7 +9,7 @@ class Real
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def avail_linodeplans(linodeplan_id=nil)
def avail_linodeplans(linodeplan_id = nil)
options = {}
if linodeplan_id
options.merge!(:planId => linodeplan_id)
Expand All @@ -25,7 +25,7 @@ def avail_linodeplans(linodeplan_id=nil)

class Mock

def avail_linodeplans
def avail_linodeplans(linodeplan_id = nil)
Fog::Mock.not_implemented
end

Expand Down
4 changes: 2 additions & 2 deletions lib/fog/rackspace/requests/compute/create_image.rb
Expand Up @@ -47,12 +47,12 @@ def create_image(server_id, options = {})
'name' => options['name'] || '',
'serverId' => server_id,
'status' => 'SAVING',
'updated' => now,
'updated' => now.to_s,
}

@data[:last_modified][:images][data['id']] = now
@data[:images][data['id']] = data
response.body = { 'image' => data.reject {|key, value| !['id', 'name', 'serverId'].include?(key)} }
response.body = { 'image' => data.reject {|key, value| !['id', 'name', 'serverId', 'status', 'updated'].include?(key)} }
response
end

Expand Down
4 changes: 2 additions & 2 deletions lib/fog/rackspace/requests/compute/list_images_detail.rb
Expand Up @@ -32,14 +32,14 @@ def list_images_detail
for image in images
case image['status']
when 'SAVING'
if Time.now - @data[:last_modified][:images][image['id']] > 2
if Time.now - @data[:last_modified][:images][image['id']] > Fog::Mock.delay
image['status'] = 'ACTIVE'
end
end
end

response.status = [200, 203][rand(1)]
response.body = { 'images' => images }
response.body = { 'images' => images.map {|image| image.reject {|key, value| !['id', 'name', 'status', 'updated'].include?(key)}} }
response
end

Expand Down
1 change: 1 addition & 0 deletions spec/aws/requests/simpledb/select_spec.rb
Expand Up @@ -13,6 +13,7 @@
end

it 'should return multi-value attributes when present' do
pending if Fog.mocking?
@item = "someitem_fog_domain_#{Time.now.to_i}"
AWS[:sdb].put_attributes(@domain_name, @item, { "attr" => "foo" })
AWS[:sdb].put_attributes(@domain_name, @item, { "attr" => "foo2" })
Expand Down
1 change: 1 addition & 0 deletions tests/aws/requests/compute/image_tests.rb
Expand Up @@ -27,6 +27,7 @@
# end

tests("#describe_images('ImageId' => '#{GENTOO_AMI}')").formats(@images_format) do
pending if Fog.mocking?
AWS[:compute].describe_images('ImageId' => GENTOO_AMI).body
end

Expand Down
5 changes: 5 additions & 0 deletions tests/aws/requests/compute/tag_tests.rb
Expand Up @@ -15,14 +15,17 @@
tests('success') do

tests("#create_tags('#{@volume.identity}', 'foo' => 'bar')").formats(AWS::Compute::Formats::BASIC) do
pending if Fog.mocking?
AWS[:compute].create_tags(@volume.identity, 'foo' => 'bar').body
end

tests('#describe_tags').formats(@tags_format) do
pending if Fog.mocking?
AWS[:compute].describe_tags.body
end

tests("#delete_tags('#{@volume.identity}', 'foo' => 'bar')").formats(AWS::Compute::Formats::BASIC) do
pending if Fog.mocking?
AWS[:compute].delete_tags(@volume.identity, 'foo' => 'bar').body
end

Expand All @@ -31,10 +34,12 @@
tests('failure') do

tests("#create_tags('vol-00000000', 'baz' => 'qux')").raises(Fog::Service::NotFound) do
pending if Fog.mocking?
AWS[:compute].create_tags('vol-00000000', 'baz' => 'qux')
end

tests("#delete_tags('vol-00000000', 'baz' => 'qux')").raises(Fog::Service::NotFound) do
pending if Fog.mocking?
AWS[:compute].delete_tags('vol-00000000', 'baz' => 'qux')
end

Expand Down
16 changes: 14 additions & 2 deletions tests/bluebox/requests/compute/block_tests.rb
Expand Up @@ -22,28 +22,37 @@
@block_id = nil

tests("create_block('#{@product_id}', '#{@template_id}', 'password' => '#{@password}')").formats(@block_format) do
pending if Fog.mocking?
data = Bluebox[:compute].create_block(@product_id, @template_id, 'password' => @password).body
@block_id = data['id']
data
end

Bluebox[:compute].servers.get(@block_id).wait_for { ready? }
unless Fog.mocking?
Bluebox[:compute].servers.get(@block_id).wait_for { ready? }
end

tests("get_block('#{@block_id}')").formats(@block_format) do
pending if Fog.mocking?
Bluebox[:compute].get_block(@block_id).body
end

tests("get_blocks").formats([@block_format.reject {|key,value| ['product', 'template'].include?(key)}]) do
pending if Fog.mocking?
Bluebox[:compute].get_blocks.body
end

tests("reboot_block('#{@block_id}')").formats({'status' => String, 'text' => String}) do
pending if Fog.mocking?
Bluebox[:compute].reboot_block(@block_id).body
end

Bluebox[:compute].servers.get(@block_id).wait_for { ready? }
unless Fog.mocking?
Bluebox[:compute].servers.get(@block_id).wait_for { ready? }
end

tests("destroy_block('#{@block_id})'").formats({'text' => String}) do
pending if Fog.mocking?
Bluebox[:compute].destroy_block(@block_id).body
end

Expand All @@ -52,14 +61,17 @@
tests('failure') do

tests("get_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
pending if Fog.mocking?
Bluebox[:compute].get_block('00000000-0000-0000-0000-000000000000')
end

tests("reboot_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
pending if Fog.mocking?
Bluebox[:compute].reboot_block('00000000-0000-0000-0000-000000000000')
end

tests("destroy_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
pending if Fog.mocking?
Bluebox[:compute].destroy_block('00000000-0000-0000-0000-000000000000')
end

Expand Down
3 changes: 3 additions & 0 deletions tests/bluebox/requests/compute/product_tests.rb
Expand Up @@ -5,10 +5,12 @@
@product_id = '94fd37a7-2606-47f7-84d5-9000deda52ae' # 1 GB

tests("get_product('#{@product_id}')").formats(Bluebox::Compute::Formats::PRODUCT) do
pending if Fog.mocking?
Bluebox[:compute].get_product(@product_id).body
end

tests("get_products").formats([Bluebox::Compute::Formats::PRODUCT]) do
pending if Fog.mocking?
Bluebox[:compute].get_products.body
end

Expand All @@ -17,6 +19,7 @@
tests('failure') do

tests("get_product('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
pending if Fog.mocking?
Bluebox[:compute].get_product('00000000-0000-0000-0000-000000000000')
end

Expand Down
3 changes: 3 additions & 0 deletions tests/bluebox/requests/compute/template_tests.rb
Expand Up @@ -12,10 +12,12 @@
@template_id = 'a00baa8f-b5d0-4815-8238-b471c4c4bf72' # Ubuntu 9.10 64bit

tests("get_template('#{@template_id}')").formats(@template_format) do
pending if Fog.mocking?
Bluebox[:compute].get_template(@template_id).body
end

tests("get_templates").formats([@template_format]) do
pending if Fog.mocking?
Bluebox[:compute].get_templates.body
end

Expand All @@ -24,6 +26,7 @@
tests('failure') do

tests("get_template('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::Compute::NotFound) do
pending if Fog.mocking?
Bluebox[:compute].get_template('00000000-0000-0000-0000-000000000000')
end

Expand Down
1 change: 1 addition & 0 deletions tests/linode/requests/compute/datacenter_tests.rb
Expand Up @@ -10,6 +10,7 @@
tests('success') do

tests('#avail_datacenters').formats(@datacenters_format) do
pending if Fog.mocking?
Linode[:compute].avail_datacenters.body
end

Expand Down
2 changes: 2 additions & 0 deletions tests/linode/requests/compute/distribution_tests.rb
Expand Up @@ -16,12 +16,14 @@
@distribution_id = nil

tests('#avail_distributions').formats(@distributions_format) do
pending if Fog.mocking?
data = Linode[:compute].avail_distributions.body
@distribution_id = data['DATA'].first['DISTRIBUTIONID']
data
end

tests("@avail_distributions(#{@distribution_id})").formats(@distributions_format) do
pending if Fog.mocking?
Linode[:compute].avail_distributions(@distribution_id).body
end

Expand Down
6 changes: 6 additions & 0 deletions tests/linode/requests/compute/linode_tests.rb
Expand Up @@ -41,16 +41,19 @@

# (2 => Dallas, TX, USA), (1 => 1 month), (1 => Linode 512)
tests('#linode_create(2, 1, 1)').formats(@linode_format) do
pending if Fog.mocking?
data = Linode[:compute].linode_create(2, 1, 1).body
@linode_id = data['DATA']['LinodeID']
data
end

tests("#linode_list(#{@linode_id})").formats(@linodes_format) do
pending if Fog.mocking?
Linode[:compute].linode_list(@linode_id).body
end

tests('#linode_list').formats(@linodes_format) do
pending if Fog.mocking?
Linode[:compute].linode_list.body
end

Expand All @@ -59,6 +62,7 @@
# end

tests('#linode_delete(#{@linode_id})').succeeds do
pending if Fog.mocking?
Linode[:compute].linode_delete(@linode_id)
end

Expand All @@ -67,10 +71,12 @@
tests('failure') do

tests('#linode_reboot(0)').raises(Fog::Linode::Compute::NotFound) do
pending if Fog.mocking?
Linode[:compute].linode_reboot(0)
end

tests('#linode_delete(0)').raises(Fog::Linode::Compute::NotFound) do
pending if Fog.mocking?
Linode[:compute].linode_delete(0)
end

Expand Down
2 changes: 2 additions & 0 deletions tests/linode/requests/compute/linodeplans_tests.rb
Expand Up @@ -23,12 +23,14 @@
@linodeplan_id = nil

tests('#avail_linodeplans').formats(@linodeplans_format) do
pending if Fog.mocking?
data = Linode[:compute].avail_linodeplans.body
@linodeplan_id = data['DATA'].first['PLANID']
data
end

tests("#avail_linodeplans(#{@linodeplan_id})").formats(@linodeplans_format) do
pending if Fog.mocking?
Linode[:compute].avail_linodeplans(@linodeplan_id).body
end

Expand Down
4 changes: 4 additions & 0 deletions tests/rackspace/requests/compute/flavor_tests.rb
Expand Up @@ -10,14 +10,17 @@
tests('success') do

tests('#get_flavor_details(1)').formats(@flavor_format) do
pending if Fog.mocking?
Rackspace[:compute].get_flavor_details(1).body['flavor']
end

tests('#list_flavors').formats({'flavors' => [Rackspace::Compute::Formats::SUMMARY]}) do
pending if Fog.mocking?
Rackspace[:compute].list_flavors.body
end

tests('#list_flavors_detail').formats({'flavors' => [@flavor_format]}) do
pending if Fog.mocking?
Rackspace[:compute].list_flavors_detail.body
end

Expand All @@ -26,6 +29,7 @@
tests('failure') do

tests('#get_flavor_details(0)').raises(Fog::Rackspace::Compute::NotFound) do
pending if Fog.mocking?
Rackspace[:compute].get_flavor_details(0)
end

Expand Down

0 comments on commit 592c8cc

Please sign in to comment.