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:
parent
e358edf951
commit
f6d26909f3
1 changed files with 37 additions and 28 deletions
|
@ -29,17 +29,26 @@ module Fog
|
|||
class Mock # :nodoc:all
|
||||
|
||||
def put_object(container_name, object_name, data, options = {})
|
||||
response = Excon::Response.new
|
||||
### 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
|
||||
_, source_container_name, source_object_name = source.split('/')
|
||||
# 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
|
||||
data = Fog::Storage.parse_data(data)
|
||||
unless data[:body].is_a?(String)
|
||||
data[:body] = data[:body].read
|
||||
end
|
||||
end
|
||||
response = Excon::Response.new
|
||||
if (container = self.data[:containers][container_name])
|
||||
response.status = 201
|
||||
object = {
|
||||
|
@ -66,8 +75,8 @@ module Fog
|
|||
'Date' => object['Date']
|
||||
}
|
||||
else
|
||||
response.status = 404
|
||||
raise(Excon::Errors.status_error({:expects => 201}, response))
|
||||
raise Fog::Storage::HP::NotFound
|
||||
end
|
||||
end
|
||||
response
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue