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

Add mocking support for copy operation using puut object.

This commit is contained in:
Rupak Ganguly 2012-04-02 18:45:33 -04:00
parent e358edf951
commit f6d26909f3

View file

@ -29,17 +29,26 @@ module Fog
class Mock # :nodoc:all class Mock # :nodoc:all
def put_object(container_name, object_name, data, options = {}) def put_object(container_name, object_name, data, options = {})
response = Excon::Response.new
### Take care of case of copy operation ### Take care of case of copy operation
if source = options['X-Copy-From'] && data.nil? source = options['X-Copy-From']
if (source && data.nil?)
# split source container and object # split source container and object
_, source_container_name, source_object_name = source.split('/')
# dup object into target object # dup object into target object
source_container = self.data[:containers][source_container_name]
container = self.data[:containers][container_name]
if (source_container && container)
response.status = 201
container[:objects][object_name] = source_container[:objects][source_object_name]
else
raise Fog::Storage::HP::NotFound
end
else else
data = Fog::Storage.parse_data(data) data = Fog::Storage.parse_data(data)
unless data[:body].is_a?(String) unless data[:body].is_a?(String)
data[:body] = data[:body].read data[:body] = data[:body].read
end end
end
response = Excon::Response.new
if (container = self.data[:containers][container_name]) if (container = self.data[:containers][container_name])
response.status = 201 response.status = 201
object = { object = {
@ -66,8 +75,8 @@ module Fog
'Date' => object['Date'] 'Date' => object['Date']
} }
else else
response.status = 404 raise Fog::Storage::HP::NotFound
raise(Excon::Errors.status_error({:expects => 201}, response)) end
end end
response response
end end