From 704e33e7d81f684b15e61f03506142df4127621d Mon Sep 17 00:00:00 2001 From: Thomas Kadauke Date: Tue, 4 Jun 2013 16:00:39 +0200 Subject: [PATCH] Store mock stacks in memory to make tests more realistic --- lib/fog/openstack/orchestration.rb | 6 +++++- .../openstack/requests/orchestration/create_stack.rb | 12 ++++++++++++ .../openstack/requests/orchestration/delete_stack.rb | 4 +++- .../openstack/requests/orchestration/list_stacks.rb | 4 +++- .../openstack/requests/orchestration/stack_tests.rb | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/fog/openstack/orchestration.rb b/lib/fog/openstack/orchestration.rb index c57a83000..3b2fcde9a 100644 --- a/lib/fog/openstack/orchestration.rb +++ b/lib/fog/openstack/orchestration.rb @@ -28,7 +28,11 @@ module Fog attr_reader :current_tenant def self.data - @data ||= {} + @data ||= Hash.new do |hash, key| + hash[key] = { + :stacks => {} + } + end end def self.reset diff --git a/lib/fog/openstack/requests/orchestration/create_stack.rb b/lib/fog/openstack/requests/orchestration/create_stack.rb index 641eebbde..f82e8424a 100644 --- a/lib/fog/openstack/requests/orchestration/create_stack.rb +++ b/lib/fog/openstack/requests/orchestration/create_stack.rb @@ -32,6 +32,18 @@ module Fog class Mock def create_stack(stack_name, options = {}) + stack_id = Fog::Mock.random_hex(32) + stack = self.data[:stacks][stack_id] = { + 'id' => stack_id, + 'stack_name' => stack_name, + 'links' => [], + 'description' => options[:description], + 'stack_status' => 'CREATE_COMPLETE', + 'stack_status_reason' => 'Stack successfully created', + 'creation_time' => Time.now, + 'updated_time' => Time.now + } + response = Excon::Response.new response.status = 202 response.body = {} diff --git a/lib/fog/openstack/requests/orchestration/delete_stack.rb b/lib/fog/openstack/requests/orchestration/delete_stack.rb index 106e68b38..400274375 100644 --- a/lib/fog/openstack/requests/orchestration/delete_stack.rb +++ b/lib/fog/openstack/requests/orchestration/delete_stack.rb @@ -20,9 +20,11 @@ module Fog end end - + class Mock def delete_stack(stack_name, stack_id) + self.data[:stacks].delete(stack_id) + response = Excon::Response.new response.status = 202 response.body = {} diff --git a/lib/fog/openstack/requests/orchestration/list_stacks.rb b/lib/fog/openstack/requests/orchestration/list_stacks.rb index e8b45634b..2b54a238c 100644 --- a/lib/fog/openstack/requests/orchestration/list_stacks.rb +++ b/lib/fog/openstack/requests/orchestration/list_stacks.rb @@ -35,8 +35,10 @@ module Fog class Mock def list_stacks(options = {}) + stacks = self.data[:stacks].values + Excon::Response.new( - :body => { 'stacks' => [] }, + :body => { 'stacks' => stacks }, :status => 200 ) end diff --git a/tests/openstack/requests/orchestration/stack_tests.rb b/tests/openstack/requests/orchestration/stack_tests.rb index bc2677ccc..0e6530e86 100644 --- a/tests/openstack/requests/orchestration/stack_tests.rb +++ b/tests/openstack/requests/orchestration/stack_tests.rb @@ -3,7 +3,7 @@ Shindo.tests('Fog::Orchestration[:openstack] | stack requests', ['openstack']) d 'links' => Array, 'id' => String, 'stack_name' => String, - 'description' => String, + 'description' => Fog::Nullable::String, 'stack_status' => String, 'stack_status_reason' => String, 'creation_time' => Time,