From 3b20e45902ecbd73175f0906aaebea5e98c1f519 Mon Sep 17 00:00:00 2001 From: Matt Griffin Date: Fri, 15 Oct 2010 05:55:08 +0800 Subject: [PATCH] [aws|compute] Add mock for create_tags --- lib/fog/aws/compute.rb | 3 +- lib/fog/aws/requests/compute/create_tags.rb | 45 ++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lib/fog/aws/compute.rb b/lib/fog/aws/compute.rb index 0a1a8163b..3896b308d 100644 --- a/lib/fog/aws/compute.rb +++ b/lib/fog/aws/compute.rb @@ -113,7 +113,8 @@ module Fog } }, :snapshots => {}, - :volumes => {} + :volumes => {}, + :tags => [] } end end diff --git a/lib/fog/aws/requests/compute/create_tags.rb b/lib/fog/aws/requests/compute/create_tags.rb index c4be188cc..f6357af38 100644 --- a/lib/fog/aws/requests/compute/create_tags.rb +++ b/lib/fog/aws/requests/compute/create_tags.rb @@ -36,10 +36,51 @@ module Fog class Mock def create_tags(resources, tags) - Fog::Mock.not_implemented + 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'] + 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)) + end + response end - + end + end end end