From d436e18aa00c381e9a7a77ed6a32b5d6c9c81f53 Mon Sep 17 00:00:00 2001 From: Dan Abel Date: Wed, 16 Oct 2013 12:19:07 +0100 Subject: [PATCH] [vcloud_director] improoved tests for #ensure_list! --- tests/vcloud_director/ensure_list_tests.rb | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/vcloud_director/ensure_list_tests.rb b/tests/vcloud_director/ensure_list_tests.rb index 1d27f7c68..364b2e034 100644 --- a/tests/vcloud_director/ensure_list_tests.rb +++ b/tests/vcloud_director/ensure_list_tests.rb @@ -5,7 +5,7 @@ Shindo.tests('Compute::VcloudDirector | ensure_list!', ['vclouddirector']) do @service = Fog::Compute::VcloudDirector.new - tests('#ensure_list! for single key') do + tests('#ensure_list! for single key ensures our key has an array as a value') do tests('for key with a hash').returns(Array) do testdata = {:k => {:A => '1'}} @service.ensure_list!(testdata, :k) @@ -31,7 +31,7 @@ Shindo.tests('Compute::VcloudDirector | ensure_list!', ['vclouddirector']) do end end - tests ('#ensure_list! for nested keys') do + tests('#ensure_list! for nested keys ensures that the child key has an array as a value') do tests('with no key').returns(Array) do testdata = {} @service.ensure_list!(testdata, :keys, :key) @@ -51,6 +51,34 @@ Shindo.tests('Compute::VcloudDirector | ensure_list!', ['vclouddirector']) do end end + tests('#ensure_list! with parent and child keys does not effect existing data') do + tests('for existing array').returns([:one, :two]) do + testdata = {:keys => {:key => [:one, :two]}} + @service.ensure_list!(testdata, :keys, :key) + testdata[:keys][:key] + end + + tests('for existing hash').returns([{:one => :two}]) do + testdata = {:keys => {:key => {:one => :two}}} + @service.ensure_list!(testdata, :keys, :key) + testdata[:keys][:key] + end + end + + tests('#ensure_list! with single key does not effect existing data') do + tests('for existing array').returns([:one, :two]) do + testdata = {:k => [:one, :two]} + @service.ensure_list!(testdata, :k) + testdata[:k] + end + + tests('for existing hash').returns([{:one => 'two'}]) do + testdata = {:k => {:one => 'two'}} + @service.ensure_list!(testdata, :k) + testdata[:k] + end + end + end end