diff --git a/lib/fog/hp/models/storage/directory.rb b/lib/fog/hp/models/storage/directory.rb index 2a6a050da..bed91d1f0 100644 --- a/lib/fog/hp/models/storage/directory.rb +++ b/lib/fog/hp/models/storage/directory.rb @@ -261,7 +261,9 @@ module Fog # get the metadata and merge them in meta_hash = {} metadata.each { |meta| meta_hash.store(meta.key, meta.value) } - options.merge!(meta_hash) + if meta_hash + options.merge!(meta_hash) + end service.put_container(key, options) # Added an extra check to see if CDN is enabled for the container if (!service.cdn.nil? && service.cdn.enabled?) diff --git a/lib/fog/hp/models/storage/metadata.rb b/lib/fog/hp/models/storage/metadata.rb index 82d72f3fd..d29a05fd9 100644 --- a/lib/fog/hp/models/storage/metadata.rb +++ b/lib/fog/hp/models/storage/metadata.rb @@ -20,6 +20,8 @@ module Fog metadata.each_pair {|k,v| metas << {'key' => k, 'value' => v} } load(metas) end + rescue Fog::Storage::HP::NotFound + nil end def destroy diff --git a/tests/hp/models/storage/directory_tests.rb b/tests/hp/models/storage/directory_tests.rb index 63b8137d0..fcf20b577 100644 --- a/tests/hp/models/storage/directory_tests.rb +++ b/tests/hp/models/storage/directory_tests.rb @@ -43,6 +43,75 @@ Shindo.tests("Fog::Storage[:hp] | directory", ['hp', 'storage']) do @instance.cdn_public_ssl_url end + # metadata tests + tests('#metadata.all').succeeds do + @instance.metadata.all + end + + tests('#metadata.set').succeeds do + @instance.metadata.set('X-Container-Meta-One' => 'One') + end + + tests('#metadata.get set meta').succeeds do + meta = @instance.metadata.get('X-Container-Meta-One') + tests('gets correct value') do + meta.value == 'One' + end + meta + end + + tests('#metadata.update').succeeds do + @instance.metadata.update('X-Container-Meta-One' => 'One Updated') + end + + tests('#metadata.get updated meta').succeeds do + meta = @instance.metadata.get('X-Container-Meta-One') + tests('gets correct value') do + meta.value == 'One Updated' + end + meta + end + + # metadata set via setter + tests('#metadata=').succeeds do + @instance.metadata = {'X-Container-Meta-Two' => 'Two'} + @instance.save + end + + tests('#metadata.get set meta via setter').succeeds do + meta = @instance.metadata.get('X-Container-Meta-Two') + tests('gets correct value') do + meta.value == 'Two' + end + meta + end + + #metadata set via Meta object + tests('metadata set via Meta object').succeeds do + m = Fog::Storage::HP::Meta.new + m.key = 'X-Container-Meta-Three' + m.value = 'Three' + @instance.metadata << m + @instance.save + end + + tests('#metadata.get set via Meta object').succeeds do + meta = @instance.metadata.get('X-Container-Meta-Three') + tests('gets correct value') do + meta.value == 'Three' + end + meta + end + + # invalid metadata + tests("#metadata.get('invalid-meta')").succeeds do + meta = @instance.metadata.get('X-Container-Meta-InValidMeta') + tests('gets nil') do + meta == nil + end + meta + end + end tests('failure') do @@ -55,6 +124,7 @@ Shindo.tests("Fog::Storage[:hp] | directory", ['hp', 'storage']) do @instance.revoke('invalid-acl') end + end end