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,45 +29,54 @@ 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
|
if (container = self.data[:containers][container_name])
|
||||||
response = Excon::Response.new
|
response.status = 201
|
||||||
if (container = self.data[:containers][container_name])
|
object = {
|
||||||
response.status = 201
|
:body => data[:body],
|
||||||
object = {
|
'Content-Type' => options['Content-Type'] || data[:headers]['Content-Type'],
|
||||||
:body => data[:body],
|
'ETag' => Fog::HP::Mock.etag,
|
||||||
'Content-Type' => options['Content-Type'] || data[:headers]['Content-Type'],
|
'Key' => object_name,
|
||||||
'ETag' => Fog::HP::Mock.etag,
|
'Date' => Fog::Time.now.to_date_header,
|
||||||
'Key' => object_name,
|
'Content-Length' => options['Content-Length'] || data[:headers]['Content-Length'],
|
||||||
'Date' => Fog::Time.now.to_date_header,
|
}
|
||||||
'Content-Length' => options['Content-Length'] || data[:headers]['Content-Length'],
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, value in options
|
for key, value in options
|
||||||
case key
|
case key
|
||||||
when 'Cache-Control', 'Content-Disposition', 'Content-Encoding', 'Content-MD5', 'Expires', /^X-Object-Meta-/
|
when 'Cache-Control', 'Content-Disposition', 'Content-Encoding', 'Content-MD5', 'Expires', /^X-Object-Meta-/
|
||||||
object[key] = value
|
object[key] = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
container[:objects][object_name] = object
|
container[:objects][object_name] = object
|
||||||
response.headers = {
|
response.headers = {
|
||||||
'Content-Length' => object['Content-Length'],
|
'Content-Length' => object['Content-Length'],
|
||||||
'Content-Type' => object['Content-Type'],
|
'Content-Type' => object['Content-Type'],
|
||||||
'ETag' => object['ETag'],
|
'ETag' => object['ETag'],
|
||||||
'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
|
||||||
|
|
Loading…
Add table
Reference in a new issue