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

[aws|storage] continuing to flesh out tests

This commit is contained in:
geemus 2010-10-12 18:07:36 -07:00
parent 4068db61ca
commit 46fdab47e5
10 changed files with 58 additions and 93 deletions

View file

@ -8,6 +8,7 @@ module Fog
identity :key, :aliases => 'Key'
attr_writer :body
attribute :content_length, :aliases => 'Content-Length'
attribute :content_type, :aliases => 'Content-Type'
attribute :etag, :aliases => ['Etag', 'ETag']

View file

@ -8,6 +8,7 @@ module Fog
identity :key, :aliases => 'Key'
attr_writer :body
attribute :content_length, :aliases => 'Content-Length'
attribute :content_type, :aliases => 'Content-Type'
attribute :etag, :aliases => ['Etag', 'ETag']

View file

@ -8,6 +8,7 @@ module Fog
identity :key, :aliases => 'Key'
attr_writer :body
attribute :content_length, :aliases => 'Content-Length'
# attribute :content_type, :aliases => 'Content-Type'
attribute :last_modified, :aliases => 'Last-Modified'

View file

@ -8,6 +8,7 @@ module Fog
identity :key, :aliases => 'Key'
attr_writer :body
attribute :content_length, :aliases => 'Content-Length'
attribute :content_type, :aliases => 'Content-Type'
attribute :etag, :aliases => 'Etag'

View file

@ -1,36 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Storage.delete_object' do
describe 'success' do
before(:each) do
AWS[:storage].put_bucket('fogdeleteobject')
AWS[:storage].put_object('fogdeleteobject', 'fog_delete_object', lorem_file)
end
after(:each) do
AWS[:storage].delete_bucket('fogdeleteobject')
end
it 'should return proper attributes' do
actual = AWS[:storage].delete_object('fogdeleteobject', 'fog_delete_object')
actual.status.should == 204
end
end
describe 'failure' do
it 'should raise a NotFound error if the bucket does not exist' do
lambda {
AWS[:storage].delete_object('fognotabucket', 'fog_delete_object')
}.should raise_error(Excon::Errors::NotFound)
end
it 'should not raise an error if the object does not exist' do
AWS[:storage].put_bucket('fogdeleteobject')
AWS[:storage].delete_object('fogdeleteobject', 'fog_not_an_object')
AWS[:storage].delete_bucket('fogdeleteobject')
end
end
end

View file

@ -1,43 +0,0 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Storage.put_object' do
describe 'success' do
before(:each) do
AWS[:storage].put_bucket('fogputobject')
@response = AWS[:storage].put_object('fogputobject', 'fog_put_object', lorem_file)
end
after(:each) do
AWS[:storage].delete_object('fogputobject', 'fog_put_object')
AWS[:storage].delete_bucket('fogputobject')
end
it 'should return proper attributes' do
@response.status.should == 200
end
it 'should not raise an error if the object already exists' do
actual = AWS[:storage].put_object('fogputobject', 'fog_put_object', lorem_file)
actual.status.should == 200
end
end
describe 'failure' do
it 'should raise a NotFound error if the bucket does not exist' do
lambda {
AWS[:storage].put_object('fognotabucket', 'fog_put_object', lorem_file)
}.should raise_error(Excon::Errors::NotFound)
end
it 'should not raise an error if the object already exists' do
AWS[:storage].put_bucket('fogputobject')
AWS[:storage].put_object('fogputobject', 'fog_put_object', lorem_file)
AWS[:storage].put_object('fogputobject', 'fog_put_object', lorem_file)
AWS[:storage].delete_object('fogputobject', 'fog_put_object')
AWS[:storage].delete_bucket('fogputobject')
end
end
end

View file

@ -2,40 +2,42 @@ Shindo.tests('AWS::Storage | bucket requests', ['aws']) do
tests('success') do
@buckets_format = {
@service_format = {
'Buckets' => [{
'CreationDate' => Time,
'Name' => String,
}],
'Owner' => {
'DisplayName' => String,
'ID' => String
}
}
tests("#put_bucket('fog_bucket')").succeeds do
AWS[:storage].put_bucket('fog_bucket')
tests("#put_bucket('fogbuckettests')").succeeds do
AWS[:storage].put_bucket('fogbuckettests')
end
tests("#get_service").formats('Buckets' => [@bucket_format]) do
tests("#get_service").formats(@service_format) do
AWS[:storage].get_service.body
end
tests("#delete_bucket('fog_bucket')").succeeds do
AWS[:storage].delete_bucket('fog_bucket')
tests("#delete_bucket('fogbuckettests')").succeeds do
AWS[:storage].delete_bucket('fogbuckettests')
end
end
tests('failure') do
tests("#delete_bucket('fog_not_a_bucket')").raises(Fog::Errors::NotFound) do
AWS[:storage].delete_bucket('fog_not_a_bucket')
tests("#delete_bucket('fognonbucket')").raises(Excon::Errors::NotFound) do
AWS[:storage].delete_bucket('fognonbucket')
end
@bucket = AWS[:storage].directories.create('fog_nonempty')
@bucket = AWS[:storage].directories.create(:key => 'fognonempty')
@file = @bucket.files.create(:key => 'foo', :body => 'bar')
tests("#delete_bucket('fog_nonempty')").raises(Fog::Errors::Conflict) do
AWS[:storage].delete_bucket('fog_nonempty')
tests("#delete_bucket('fognonempty')").raises(Excon::Errors::Conflict) do
AWS[:storage].delete_bucket('fognonempty')
end
@file.destroy

View file

@ -0,0 +1,33 @@
Shindo.tests('AWS::Storage | object requests', ['aws']) do
@directory = AWS[:storage].directories.create(:key => 'fogobjecttests')
tests('success') do
tests("#put_object('#{@directory.identity}', 'fog_object', lorem_file)").succeeds do
AWS[:storage].put_object(@directory.identity, 'fog_object', lorem_file)
end
tests("#get_object")
tests("#delete_object('#{@directory.identity}', 'fog_object')").succeeds do
AWS[:storage].delete_object(@directory.identity, 'fog_object')
end
end
tests('failure') do
tests("#put_object('fognonbucket', 'fog_object', lorem_file)").raises(Excon::Errors::NotFound) do
AWS[:storage].put_object('fognonbucket', 'fog_object', lorem_file)
end
tests("#delete_object('fognonbucket', 'fog_non_object')").raises(Excon::Errors::NotFound) do
AWS[:storage].delete_object('fognonbucket', 'fog_non_object')
end
end
@directory.destroy
end

View file

@ -16,6 +16,10 @@ end
FalseClass.send(:include, Fog::Boolean)
TrueClass.send(:include, Fog::Boolean)
def lorem_file
File.open(File.dirname(__FILE__) + '/lorem.txt', 'r')
end
module Shindo
class Tests

1
tests/lorem.txt Normal file
View file

@ -0,0 +1 @@
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.