From 65f933e7bfbd1ec1dea0251574a753257b321aad Mon Sep 17 00:00:00 2001 From: Edward Muller Date: Wed, 30 May 2012 21:43:28 -0700 Subject: [PATCH] Mock aws compute start_instances --- .../aws/requests/compute/start_instances.rb | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/fog/aws/requests/compute/start_instances.rb b/lib/fog/aws/requests/compute/start_instances.rb index f478affa9..102f6ea3d 100644 --- a/lib/fog/aws/requests/compute/start_instances.rb +++ b/lib/fog/aws/requests/compute/start_instances.rb @@ -27,6 +27,33 @@ module Fog end end + + class Mock + def start_instances(instance_id) + instance_ids = Array(instance_id) + + instance_set = self.data[:instances].values + instance_set = apply_tag_filters(instance_set, {'instance_id' => instance_ids}, 'instanceId') + + if instance_set.empty? + raise Fog::Compute::AWS::NotFound.new("The instance ID '#{instance_ids.first}' does not exist") + else + response = Excon::Response.new + response.status = 200 + + response.body = { + 'instancesSet' => instance_set.inject([]) do |ia, instance| + ia << {'currentState' => { 'code' => 0, 'name' => 'pending' }, + 'previousState' => instance['instanceState'], + 'instanceId' => instance['instanceId'] } + instance['instanceState'] = {'code'=>0, 'name'=>'pending'} + ia + end + } + response + end + end + end end end end