mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|compute] cleanup/fleshout create_tag mocking
This commit is contained in:
parent
3b20e45902
commit
ddd31dbc16
3 changed files with 33 additions and 41 deletions
|
@ -78,6 +78,7 @@ module Fog
|
||||||
region_hash[key] = {
|
region_hash[key] = {
|
||||||
:deleted_at => {},
|
:deleted_at => {},
|
||||||
:addresses => {},
|
:addresses => {},
|
||||||
|
:images => {},
|
||||||
:instances => {},
|
:instances => {},
|
||||||
:key_pairs => {},
|
:key_pairs => {},
|
||||||
:limits => { :addresses => 5 },
|
:limits => { :addresses => 5 },
|
||||||
|
@ -114,7 +115,7 @@ module Fog
|
||||||
},
|
},
|
||||||
:snapshots => {},
|
:snapshots => {},
|
||||||
:volumes => {},
|
:volumes => {},
|
||||||
:tags => []
|
:tags => {}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,51 +36,43 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def create_tags(resources, tags)
|
def create_tags(resources, tags)
|
||||||
response = Excon::Response.new
|
|
||||||
resources = [*resources]
|
resources = [*resources]
|
||||||
resource_tags = {}
|
|
||||||
objects = resources.map do |resource_id|
|
tagged = resources.map do |resource_id|
|
||||||
if resource = @data[:instances][resource_id]
|
type = case resource_id
|
||||||
[resource, 'instance']
|
when /^ami\-[a-z0-9]{8}$/i
|
||||||
elsif resource = @data[:images][resource_id]
|
'image'
|
||||||
[resource, 'image']
|
when /^i\-[a-z0-9]{8}$/i
|
||||||
elsif resource = @data[:volumes][resource_id]
|
'instance'
|
||||||
[resource, 'volume']
|
when /^snap\-[a-z0-9]{8}$/i
|
||||||
elsif resource = @data[:snapshots][resource_id]
|
'snapshot'
|
||||||
[resource, 'snapshot']
|
when /^vol\-[a-z0-9]{8}$/i
|
||||||
|
'volume'
|
||||||
|
end
|
||||||
|
if type && @data[:"#{type}s"][resource_id]
|
||||||
|
{ 'resourceId' => resource_id, 'resourceType' => type }
|
||||||
|
else
|
||||||
|
raise(Fog::Service::NotFound.new("The #{type} ID '#{resource_id}' does not exist"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if objects.all?
|
tags.each do |key, value|
|
||||||
response.status = 200
|
@data[:tags][key] ||= {}
|
||||||
@data[:tags] ||= []
|
@data[:tags][key][value] ||= []
|
||||||
tags.each do |key, value|
|
@data[:tags][key][value] = @data[:tags][key][value] & tagged
|
||||||
resources.each_with_index do |resource_id, i|
|
|
||||||
object, resource_type = objects[i]
|
|
||||||
object['tagSet'] ||= {}
|
|
||||||
object['tagSet'][key] = value
|
|
||||||
@data[:tags] << {
|
|
||||||
'key' => key,
|
|
||||||
'value' => value,
|
|
||||||
'resourceId' => resource_id,
|
|
||||||
'resourceType' => resource_type
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
response.body = {
|
|
||||||
'requestId' => Fog::AWS::Mock.request_id,
|
|
||||||
'return' => 'true'
|
|
||||||
}
|
|
||||||
else
|
|
||||||
response.status = 400
|
|
||||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = {
|
||||||
|
'requestId' => Fog::AWS::Mock.request_id,
|
||||||
|
'return' => true
|
||||||
|
}
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,11 +11,11 @@ Shindo.tests('AWS::Compute | tag requests', ['aws']) do
|
||||||
}
|
}
|
||||||
|
|
||||||
@volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1)
|
@volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1)
|
||||||
|
@volume.wait_for { ready? }
|
||||||
|
|
||||||
tests('success') do
|
tests('success') do
|
||||||
|
|
||||||
tests("#create_tags('#{@volume.identity}', 'foo' => 'bar')").formats(AWS::Compute::Formats::BASIC) 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
|
AWS[:compute].create_tags(@volume.identity, 'foo' => 'bar').body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ Shindo.tests('AWS::Compute | tag requests', ['aws']) do
|
||||||
tests('failure') do
|
tests('failure') do
|
||||||
|
|
||||||
tests("#create_tags('vol-00000000', 'baz' => 'qux')").raises(Fog::Service::NotFound) 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')
|
AWS[:compute].create_tags('vol-00000000', 'baz' => 'qux')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue