mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
get all mocked s3 tests passing
This commit is contained in:
parent
175e5802f7
commit
78e2928cee
5 changed files with 78 additions and 32 deletions
|
@ -55,7 +55,6 @@ unless Fog.mocking?
|
|||
|
||||
else
|
||||
|
||||
# TODO: IsTruncated, Marker, MaxKeys, Name, Prefix
|
||||
module Fog
|
||||
module AWS
|
||||
class S3
|
||||
|
@ -68,12 +67,17 @@ else
|
|||
else
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'IsTruncated' => false,
|
||||
'Contents' => bucket['Contents'].map do |object|
|
||||
data = object.reject {|key, value| !['ETag', 'Key', 'LastModified', 'Owner', 'StorageClass'].include?(key)}
|
||||
data = object.reject {|key, value| !['ETag', 'Key', 'LastModified', 'Owner', 'Size', 'StorageClass'].include?(key)}
|
||||
data['LastModified'] = Time.parse(data['LastModified'])
|
||||
data['Size'] = data['Size'].to_i
|
||||
data
|
||||
end
|
||||
end,
|
||||
'IsTruncated' => false,
|
||||
'Marker' => options['Marker'] || '',
|
||||
'MaxKeys' => options['MaxKeys'] || 1000,
|
||||
'Name' => bucket['Name'],
|
||||
'Prefix' => options['Prefix'] || ''
|
||||
}
|
||||
end
|
||||
response
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
module Fog
|
||||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class S3
|
||||
|
||||
|
@ -24,4 +26,29 @@ module Fog
|
|||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class S3
|
||||
|
||||
def get_bucket_location(bucket_name)
|
||||
response = Fog::Response.new
|
||||
bucket_status = get_bucket(bucket_name).status
|
||||
if bucket_status == 200
|
||||
response.status = 200
|
||||
bucket = @data['Buckets'].select {|bucket| bucket['Name'] == bucket_name}.first
|
||||
response.body = {'LocationConstraint' => bucket['LocationConstraint'] }
|
||||
else
|
||||
response.status = bucket_status
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -47,12 +47,18 @@ else
|
|||
def put_bucket(bucket_name, options = {})
|
||||
response = Fog::Response.new
|
||||
response.status = 200
|
||||
@data['Buckets'] << {
|
||||
bucket = {
|
||||
'Name' => bucket_name,
|
||||
'Contents' => [],
|
||||
'CreationDate' => Time.now,
|
||||
'Payer' => 'BucketOwner'
|
||||
}
|
||||
if options['LocationConstraint']
|
||||
bucket['LocationConstraint'] = options['LocationConstraint']
|
||||
else
|
||||
bucket['LocationConstraint'] = ''
|
||||
end
|
||||
@data['Buckets'] << bucket
|
||||
response
|
||||
end
|
||||
|
||||
|
|
|
@ -28,6 +28,10 @@ module Fog
|
|||
module AWS
|
||||
class S3
|
||||
|
||||
if Fog.mocking?
|
||||
attr_accessor :data
|
||||
end
|
||||
|
||||
# Initialize connection to S3
|
||||
#
|
||||
# ==== Notes
|
||||
|
|
|
@ -3,15 +3,20 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
describe 'S3.get_bucket_location' do
|
||||
|
||||
before(:all) do
|
||||
s3.put_bucket('foggetlocation', 'LocationConstraint' => 'EU')
|
||||
@s3 = s3
|
||||
@eu_s3 = eu_s3
|
||||
@s3.put_bucket('foggetlocation', 'LocationConstraint' => 'EU')
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
eu_s3.delete_bucket('foggetlocation')
|
||||
if Fog.mocking?
|
||||
@eu_s3.data = @s3.data
|
||||
end
|
||||
@eu_s3.delete_bucket('foggetlocation')
|
||||
end
|
||||
|
||||
it 'should return proper attributes' do
|
||||
actual = s3.get_bucket_location('foggetlocation')
|
||||
actual = @s3.get_bucket_location('foggetlocation')
|
||||
actual.status.should == 200
|
||||
actual.body['LocationConstraint'].should == 'EU'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue