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] = {
|
||||
:deleted_at => {},
|
||||
:addresses => {},
|
||||
:images => {},
|
||||
:instances => {},
|
||||
:key_pairs => {},
|
||||
:limits => { :addresses => 5 },
|
||||
|
@ -114,7 +115,7 @@ module Fog
|
|||
},
|
||||
:snapshots => {},
|
||||
:volumes => {},
|
||||
:tags => []
|
||||
:tags => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,51 +36,43 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def create_tags(resources, tags)
|
||||
response = Excon::Response.new
|
||||
resources = [*resources]
|
||||
resource_tags = {}
|
||||
objects = resources.map do |resource_id|
|
||||
if resource = @data[:instances][resource_id]
|
||||
[resource, 'instance']
|
||||
elsif resource = @data[:images][resource_id]
|
||||
[resource, 'image']
|
||||
elsif resource = @data[:volumes][resource_id]
|
||||
[resource, 'volume']
|
||||
elsif resource = @data[:snapshots][resource_id]
|
||||
[resource, 'snapshot']
|
||||
|
||||
tagged = resources.map do |resource_id|
|
||||
type = case resource_id
|
||||
when /^ami\-[a-z0-9]{8}$/i
|
||||
'image'
|
||||
when /^i\-[a-z0-9]{8}$/i
|
||||
'instance'
|
||||
when /^snap\-[a-z0-9]{8}$/i
|
||||
'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
|
||||
|
||||
if objects.all?
|
||||
response.status = 200
|
||||
@data[:tags] ||= []
|
||||
tags.each do |key, value|
|
||||
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))
|
||||
|
||||
tags.each do |key, value|
|
||||
@data[:tags][key] ||= {}
|
||||
@data[:tags][key][value] ||= []
|
||||
@data[:tags][key][value] = @data[:tags][key][value] & tagged
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'return' => true
|
||||
}
|
||||
response
|
||||
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.wait_for { ready? }
|
||||
|
||||
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
|
||||
|
||||
|
@ -34,7 +34,6 @@ Shindo.tests('AWS::Compute | tag requests', ['aws']) do
|
|||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue