fog--fog/spec/aws/requests/s3/get_bucket_spec.rb

117 lines
4.3 KiB
Ruby
Raw Normal View History

2009-08-17 22:55:30 +00:00
require File.dirname(__FILE__) + '/../../../spec_helper'
2009-06-05 23:51:17 +00:00
describe 'S3.get_bucket' do
describe 'success' do
2009-06-05 23:51:17 +00:00
2009-08-20 03:32:57 +00:00
before(:each) do
s3.put_bucket('foggetbucket')
file = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
s3.put_object('foggetbucket', 'fog_object', file)
file = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
s3.put_object('foggetbucket', 'fog_other_object', file)
end
2009-06-05 23:51:17 +00:00
2009-08-20 03:32:57 +00:00
after(:each) do
s3.delete_object('foggetbucket', 'fog_object')
s3.delete_object('foggetbucket', 'fog_other_object')
s3.delete_bucket('foggetbucket')
end
2009-06-05 23:51:17 +00:00
it 'should return proper attributes' do
actual = s3.get_bucket('foggetbucket')
actual.body['IsTruncated'].should == false
actual.body['Marker'].should be_a(String)
actual.body['MaxKeys'].should be_an(Integer)
actual.body['Name'].should be_a(String)
actual.body['Prefix'].should be_a(String)
actual.body['Contents'].should be_an(Array)
actual.body['Contents'].length.should == 2
object = actual.body['Contents'].first
object['ETag'].should be_a(String)
object['Key'].should == 'fog_object'
object['LastModified'].should be_a(Time)
owner = object['Owner']
owner['DisplayName'].should be_a(String)
owner['ID'].should be_a(String)
object['Size'].should be_an(Integer)
object['StorageClass'].should be_a(String)
end
2009-08-18 16:32:25 +00:00
it 'should accept marker option' do
actual = s3.get_bucket('foggetbucket', 'marker' => 'fog_object')
actual.body['IsTruncated'].should == false
actual.body['Marker'].should be_a(String)
actual.body['MaxKeys'].should be_an(Integer)
actual.body['Name'].should be_a(String)
actual.body['Prefix'].should be_a(String)
actual.body['Contents'].should be_an(Array)
actual.body['Contents'].length.should == 1
object = actual.body['Contents'].first
object['ETag'].should be_a(String)
object['Key'].should == 'fog_other_object'
object['LastModified'].should be_a(Time)
owner = object['Owner']
owner['DisplayName'].should be_a(String)
owner['ID'].should be_a(String)
object['Size'].should be_an(Integer)
object['StorageClass'].should be_a(String)
end
2009-08-18 16:32:25 +00:00
it 'should respect max-keys option' do
actual = s3.get_bucket('foggetbucket', 'max-keys' => 1)
actual.body['IsTruncated'].should == true
actual.body['Marker'].should be_a(String)
actual.body['MaxKeys'].should be_an(Integer)
actual.body['Name'].should be_a(String)
actual.body['Prefix'].should be_a(String)
actual.body['Contents'].should be_an(Array)
actual.body['Contents'].length.should == 1
object = actual.body['Contents'].first
object['ETag'].should be_a(String)
object['Key'].should == 'fog_object'
object['LastModified'].should be_a(Time)
owner = object['Owner']
owner['DisplayName'].should be_a(String)
owner['ID'].should be_a(String)
object['Size'].should be_an(Integer)
object['StorageClass'].should be_a(String)
end
2009-06-05 23:51:17 +00:00
it 'should accept prefix option' do
actual = s3.get_bucket('foggetbucket', 'prefix' => 'fog_ob')
actual.body['IsTruncated'].should == false
actual.body['Marker'].should be_a(String)
actual.body['MaxKeys'].should be_an(Integer)
actual.body['Name'].should be_a(String)
actual.body['Prefix'].should be_a(String)
actual.body['Contents'].should be_an(Array)
actual.body['Contents'].length.should == 1
object = actual.body['Contents'].first
object['ETag'].should be_a(String)
object['Key'].should == 'fog_object'
object['LastModified'].should be_a(Time)
owner = object['Owner']
owner['DisplayName'].should be_a(String)
owner['ID'].should be_a(String)
object['Size'].should be_an(Integer)
object['StorageClass'].should be_a(String)
end
2009-08-18 00:57:52 +00:00
end
describe 'failure' do
it 'should raise a NotFound error if the bucket does not exist' do
lambda {
s3.get_bucket('fognotabucket')
}.should raise_error(Excon::Errors::NotFound)
end
it 'should request non-subdomain buckets and raise a NotFound error' do
lambda {
s3.get_bucket('A-invalid--name')
}.should raise_error(Excon::Errors::NotFound)
end
end
2009-06-05 23:51:17 +00:00
end