1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[hp|storage] Minor fixes to post_container and post_object methods and tests.

This commit is contained in:
Rupak Ganguly 2013-04-24 11:24:01 -04:00
parent f3eeaedf2a
commit 5263f25130
4 changed files with 30 additions and 22 deletions

View file

@ -3,17 +3,17 @@ module Fog
class HP
class Real
# Update or create a container
# Create or update metadata for an existing container
#
# ==== Parameters
# * container<~String> - Name for container, should be < 256 bytes and must not contain '/'
#
# * container<~String> - Name for existing container, should be < 256 bytes and must not contain '/'
# * headers<~Hash> - Hash of metadata name/value pairs
def post_container(container, headers = {})
response = request(
:expects => 204,
:headers => headers,
:method => 'POST',
:path => "#{Fog::HP.escape(container)}"
:path => Fog::HP.escape(container)
)
response
end
@ -22,7 +22,7 @@ module Fog
class Mock # :nodoc:all
def post_container(container_name, object_name, headers = {})
def post_container(container_name, headers = {})
if self.data[:containers][container_name].nil?
raise Fog::Storage::HP::NotFound
end

View file

@ -3,11 +3,12 @@ module Fog
class HP
class Real
# Create a new object
# Create or update metadata for an existing object
#
# ==== Parameters
# * container<~String> - Name for container, should be < 256 bytes and must not contain '/'
#
# * container<~String> - Name of the existing container, should be < 256 bytes and must not contain '/'
# * object<~String> - Name of the existing object
# * headers<~Hash> - Hash of metadata name/value pairs
def post_object(container, object, headers = {})
response = request(
:expects => 202,
@ -24,17 +25,24 @@ module Fog
def post_object(container_name, object_name, headers = {})
response = Excon::Response.new
source_container = self.data[:containers][container_name]
container = self.data[:containers][container_name]
if (source_container && container)
if container = self.data[:containers][container_name]
response.status = 202
source_object = source_container[:objects][object_name]
target_object = source_object.dup
target_object.merge!({
'Key' => object_name,
'Date' => Fog::Time.now.to_date_header
})
container[:objects][object_name] = target_object
object = container[:objects][object_name]
for key, value in headers
case key
when 'Content-Disposition', 'Content-Encoding', 'X-Delete-At', 'X-Delete-After', /^X-Object-Meta-/
object[key] = value unless value.nil?
end
end
container[:objects][object_name] = object
response.headers = {
'Content-Length' => object['Content-Length'],
'Content-Type' => object['Content-Type'],
'ETag' => object['ETag'],
'Date' => object['Date']
}
else
raise Fog::Storage::HP::NotFound
end

View file

@ -14,8 +14,8 @@ Shindo.tests("Fog::Storage[:hp] | container requests", ['hp']) do
Fog::Storage[:hp].put_container('fogcontainertests')
end
tests("#post_container('fogcontainertests', {'X-Container-Sync-Key' => 'keyd'})").succeeds do
Fog::Storage[:hp].post_container('fogcontainertests', {'X-Container-Meta-Foo' => 'd'})
tests("#post_container('fogcontainertests', {'X-Container-Meta-Foo' => 'foometa'})").succeeds do
Fog::Storage[:hp].post_container('fogcontainertests', {'X-Container-Meta-Foo' => 'foometa'})
end
tests("#get_container('fogcontainertests')").formats(@container_format) do

View file

@ -9,8 +9,8 @@ Shindo.tests("Fog::Storage[:hp] | object requests", ['hp', 'storage']) do
Fog::Storage[:hp].put_object(@dir_name, 'fog_object', lorem_file)
end
tests("#post_object('#{@dir_name}', 'fog_object', {})").succeeds do
Fog::Storage[:hp].post_object(@dir_name, 'fog_object', {})
tests("#post_object('#{@dir_name}', 'fog_object', {'X-Object-Meta-Foo' => 'foometa'})").succeeds do
Fog::Storage[:hp].post_object(@dir_name, 'fog_object', {'X-Object-Meta-Foo' => 'foometa'})
end
tests("#get_object('#{@dir_name}', 'fog_object')").succeeds do