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

[aws|storage|test] Added the ability to get_object by versionId.

This commit is contained in:
Kevin Menard 2011-12-15 17:23:50 -05:00
parent 5290d0f960
commit 701175a0a7

View file

@ -62,15 +62,23 @@ module Fog
class Mock # :nodoc:all
def get_object(bucket_name, object_name, options = {}, &block)
version_id = options.delete('versionId')
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
unless object_name
raise ArgumentError.new('object_name is required')
end
response = Excon::Response.new
if (bucket = self.data[:buckets][bucket_name])
object = bucket[:objects][object_name].last if bucket[:objects].has_key?(object_name)
object = nil
if bucket[:objects].has_key?(object_name)
object = version_id ? bucket[:objects][object_name].find { |object| object['VersionId'] == version_id} : bucket[:objects][object_name].last
end
if (object && !object[:delete_marker])
if options['If-Match'] && options['If-Match'] != object['ETag']
response.status = 412
@ -100,6 +108,18 @@ module Fog
end
end
end
elsif version_id && !object
response.status = 400
response.body = {
'Error' => {
'Code' => 'InvalidArgument',
'Message' => 'Invalid version id specified',
'ArgumentValue' => version_id,
'ArgumentName' => 'versionId',
'RequestId' => Fog::Mock.random_hex(16),
'HostId' => Fog::Mock.random_base64(65)
}
}
else
response.status = 404
response.body = "...<Code>NoSuchKey<\/Code>..."