mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|storage|test] Make sure tests pass with both mocking enabled and disabled.
This commit is contained in:
parent
733fb7f2ac
commit
aff70389a8
10 changed files with 47 additions and 23 deletions
|
@ -48,7 +48,7 @@ module Fog
|
||||||
def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {})
|
def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {})
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
source_bucket = self.data[:buckets][source_bucket_name]
|
source_bucket = self.data[:buckets][source_bucket_name]
|
||||||
source_object = source_bucket && source_bucket[:objects][source_object_name]
|
source_object = source_bucket && source_bucket[:objects][source_object_name] && source_bucket[:objects][source_object_name].first
|
||||||
target_bucket = self.data[:buckets][target_bucket_name]
|
target_bucket = self.data[:buckets][target_bucket_name]
|
||||||
|
|
||||||
acl = options['x-amz-acl'] || 'private'
|
acl = options['x-amz-acl'] || 'private'
|
||||||
|
|
|
@ -61,6 +61,7 @@ module Fog
|
||||||
else
|
else
|
||||||
response.status = 400
|
response.status = 400
|
||||||
response.body = invalid_version_id_payload(version_id)
|
response.body = invalid_version_id_payload(version_id)
|
||||||
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
delete_marker = {
|
delete_marker = {
|
||||||
|
@ -72,11 +73,11 @@ module Fog
|
||||||
|
|
||||||
# When versioning is suspended, a delete marker is placed if the last object ID is not the value 'null',
|
# When versioning is suspended, a delete marker is placed if the last object ID is not the value 'null',
|
||||||
# otherwise the last object is replaced.
|
# otherwise the last object is replaced.
|
||||||
if bucket[:versioning] == 'Suspended' && bucket[:objects][object_name].last['VersionId'] == 'null'
|
if bucket[:versioning] == 'Suspended' && bucket[:objects][object_name].first['VersionId'] == 'null'
|
||||||
bucket[:objects][object_name].pop
|
bucket[:objects][object_name].shift
|
||||||
end
|
end
|
||||||
|
|
||||||
bucket[:objects][object_name] << delete_marker
|
bucket[:objects][object_name].unshift(delete_marker)
|
||||||
|
|
||||||
response.headers['x-amz-delete-marker'] = 'true'
|
response.headers['x-amz-delete-marker'] = 'true'
|
||||||
response.headers['x-amz-version-id'] = delete_marker['VersionId']
|
response.headers['x-amz-version-id'] = delete_marker['VersionId']
|
||||||
|
@ -85,6 +86,7 @@ module Fog
|
||||||
if version_id && version_id != 'null'
|
if version_id && version_id != 'null'
|
||||||
response.status = 400
|
response.status = 400
|
||||||
response.body = invalid_version_id_payload(version_id)
|
response.body = invalid_version_id_payload(version_id)
|
||||||
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||||
else
|
else
|
||||||
bucket[:objects].delete(object_name)
|
bucket[:objects].delete(object_name)
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,10 @@ module Fog
|
||||||
# Valid case.
|
# Valid case.
|
||||||
# TODO: (nirvdrum 12/15/11) It's not clear to me how to actually use version-id-marker, so I didn't implement it below.
|
# TODO: (nirvdrum 12/15/11) It's not clear to me how to actually use version-id-marker, so I didn't implement it below.
|
||||||
elsif bucket = self.data[:buckets][bucket_name]
|
elsif bucket = self.data[:buckets][bucket_name]
|
||||||
contents = bucket[:objects].values.flatten.sort {|x,y| x['Key'] <=> y['Key']}.reject do |object|
|
# We need to order results by S3 key, but since our data store is key => [versions], we want to ensure the integrity
|
||||||
|
# of the versions as well. So, sort the keys, then fetch the versions, and then combine them all as a sorted list by
|
||||||
|
# flattening the results.
|
||||||
|
contents = bucket[:objects].keys.sort.collect { |key| bucket[:objects][key] }.flatten.reject do |object|
|
||||||
(prefix && object['Key'][0...prefix.length] != prefix) ||
|
(prefix && object['Key'][0...prefix.length] != prefix) ||
|
||||||
(key_marker && object['Key'] <= key_marker) ||
|
(key_marker && object['Key'] <= key_marker) ||
|
||||||
(delimiter && object['Key'][(prefix ? prefix.length : 0)..-1].include?(delimiter) \
|
(delimiter && object['Key'][(prefix ? prefix.length : 0)..-1].include?(delimiter) \
|
||||||
|
@ -116,7 +119,7 @@ module Fog
|
||||||
data[tag_name].merge!({
|
data[tag_name].merge!({
|
||||||
'LastModified' => Time.parse(object['Last-Modified']),
|
'LastModified' => Time.parse(object['Last-Modified']),
|
||||||
'Owner' => bucket['Owner'],
|
'Owner' => bucket['Owner'],
|
||||||
'IsLatest' => object == bucket[:objects][object['Key']].last
|
'IsLatest' => object == bucket[:objects][object['Key']].first
|
||||||
})
|
})
|
||||||
|
|
||||||
data[tag_name]['Size'] = object['Content-Length'].to_i if tag_name == 'Version'
|
data[tag_name]['Size'] = object['Content-Length'].to_i if tag_name == 'Version'
|
||||||
|
@ -144,15 +147,18 @@ module Fog
|
||||||
|
|
||||||
# Missing bucket case.
|
# Missing bucket case.
|
||||||
else
|
else
|
||||||
response.status = 403
|
response.status = 404
|
||||||
response.body = {
|
response.body = {
|
||||||
'Error' => {
|
'Error' => {
|
||||||
'Code' => 'AccessDenied',
|
'Code' => 'NoSuchBucket',
|
||||||
'Message' => 'AccessDenied',
|
'Message' => 'The specified bucket does not exist',
|
||||||
|
'BucketName' => bucket_name,
|
||||||
'RequestId' => Fog::Mock.random_hex(16),
|
'RequestId' => Fog::Mock.random_hex(16),
|
||||||
'HostId' => Fog::Mock.random_base64(65)
|
'HostId' => Fog::Mock.random_base64(65)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,6 +60,8 @@ module Fog
|
||||||
'HostId' => Fog::Mock.random_base64(65)
|
'HostId' => Fog::Mock.random_base64(65)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||||
end
|
end
|
||||||
|
|
||||||
response
|
response
|
||||||
|
|
|
@ -76,7 +76,7 @@ module Fog
|
||||||
if (bucket = self.data[:buckets][bucket_name])
|
if (bucket = self.data[:buckets][bucket_name])
|
||||||
object = nil
|
object = nil
|
||||||
if bucket[:objects].has_key?(object_name)
|
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
|
object = version_id ? bucket[:objects][object_name].find { |object| object['VersionId'] == version_id} : bucket[:objects][object_name].first
|
||||||
end
|
end
|
||||||
|
|
||||||
if (object && !object[:delete_marker])
|
if (object && !object[:delete_marker])
|
||||||
|
@ -123,6 +123,8 @@ module Fog
|
||||||
'HostId' => Fog::Mock.random_base64(65)
|
'HostId' => Fog::Mock.random_base64(65)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||||
else
|
else
|
||||||
response.status = 404
|
response.status = 404
|
||||||
response.body = "...<Code>NoSuchKey<\/Code>..."
|
response.body = "...<Code>NoSuchKey<\/Code>..."
|
||||||
|
|
|
@ -51,17 +51,22 @@ DATA
|
||||||
'HostId' => Fog::Mock.random_base64(65)
|
'HostId' => Fog::Mock.random_base64(65)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
response.status = 403
|
response.status = 404
|
||||||
response.body = {
|
response.body = {
|
||||||
'Error' => {
|
'Error' => {
|
||||||
'Code' => 'AccessDenied',
|
'Code' => 'NoSuchBucket',
|
||||||
'Message' => 'AccessDenied',
|
'Message' => 'The specified bucket does not exist',
|
||||||
|
'BucketName' => bucket_name,
|
||||||
'RequestId' => Fog::Mock.random_hex(16),
|
'RequestId' => Fog::Mock.random_hex(16),
|
||||||
'HostId' => Fog::Mock.random_base64(65)
|
'HostId' => Fog::Mock.random_base64(65)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||||
end
|
end
|
||||||
|
|
||||||
response
|
response
|
||||||
|
|
|
@ -52,7 +52,7 @@ DATA
|
||||||
if self.data[:buckets][bucket_name]
|
if self.data[:buckets][bucket_name]
|
||||||
response.status = 200
|
response.status = 200
|
||||||
else
|
else
|
||||||
response.status = 403
|
response.status = 404
|
||||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -86,11 +86,11 @@ module Fog
|
||||||
|
|
||||||
# When versioning is suspended, putting an object will create a new 'null' version if the latest version
|
# When versioning is suspended, putting an object will create a new 'null' version if the latest version
|
||||||
# is a value other than 'null', otherwise it will replace the latest version.
|
# is a value other than 'null', otherwise it will replace the latest version.
|
||||||
if bucket[:versioning] == 'Suspended' && bucket[:objects][object_name].last['VersionId'] == 'null'
|
if bucket[:versioning] == 'Suspended' && bucket[:objects][object_name].first['VersionId'] == 'null'
|
||||||
bucket[:objects][object_name].pop
|
bucket[:objects][object_name].shift
|
||||||
end
|
end
|
||||||
|
|
||||||
bucket[:objects][object_name] << object
|
bucket[:objects][object_name].unshift(object)
|
||||||
else
|
else
|
||||||
bucket[:objects][object_name] = [object]
|
bucket[:objects][object_name] = [object]
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,10 +31,10 @@ Shindo.tests("Storage[:aws] | version", [:aws]) do
|
||||||
@version_instance.delete_marker
|
@version_instance.delete_marker
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#delete_marker should be true if the version isn't a DeleteMarker'").returns(true) do
|
tests("#delete_marker should be true if the version is a DeleteMarker'").returns(true) do
|
||||||
@instance.destroy
|
@instance.destroy
|
||||||
|
|
||||||
@instance.versions.all.last.delete_marker
|
@instance.versions.all.first.delete_marker
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,17 +17,24 @@ Shindo.tests("Storage[:aws] | versions", [:aws]) do
|
||||||
|
|
||||||
versions = []
|
versions = []
|
||||||
versions << @instance.connection.put_object(@instance.key, 'one', 'abcde').headers['x-amz-version-id']
|
versions << @instance.connection.put_object(@instance.key, 'one', 'abcde').headers['x-amz-version-id']
|
||||||
|
|
||||||
|
puts versions.first
|
||||||
|
|
||||||
versions << @instance.connection.put_object(@instance.key, 'one', '32423').headers['x-amz-version-id']
|
versions << @instance.connection.put_object(@instance.key, 'one', '32423').headers['x-amz-version-id']
|
||||||
versions << @instance.connection.delete_object(@instance.key, 'one').headers['x-amz-version-id']
|
versions << @instance.connection.delete_object(@instance.key, 'one').headers['x-amz-version-id']
|
||||||
|
versions.reverse!
|
||||||
|
|
||||||
|
puts versions.first
|
||||||
|
|
||||||
versions << @instance.connection.put_object(@instance.key, 'two', 'aoeu').headers['x-amz-version-id']
|
versions << @instance.connection.put_object(@instance.key, 'two', 'aoeu').headers['x-amz-version-id']
|
||||||
|
|
||||||
tests('#versions') do
|
tests('#versions') do
|
||||||
tests('#versions.size includes versions (including DeleteMarkers) for all keys').returns(4) do
|
tests('#versions.size includes versions (including DeleteMarkers) for all keys').returns(4) do
|
||||||
@instance.versions.size
|
@instance.versions.all.size
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('#versions returns the correct versions').returns(versions) do
|
tests('#versions returns the correct versions').returns(versions) do
|
||||||
@instance.versions.collect(&:version)
|
@instance.versions.all.collect(&:version)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,11 +44,11 @@ Shindo.tests("Storage[:aws] | versions", [:aws]) do
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#all for file returns only versions for that file").returns(1) do
|
tests("#all for file returns only versions for that file").returns(1) do
|
||||||
@instance.files.get('two').versions.collect(&:version).size
|
@instance.files.get('two').versions.all.collect(&:version).size
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#all for file returns only versions for that file").returns(versions.last) do
|
tests("#all for file returns only versions for that file").returns(versions.last) do
|
||||||
@instance.files.get('two').versions.collect(&:version).first
|
@instance.files.get('two').versions.all.collect(&:version).first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue