1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/spec/aws/requests/storage/get_object_spec.rb

59 lines
1.8 KiB
Ruby
Raw Normal View History

2009-08-17 15:55:30 -07:00
require File.dirname(__FILE__) + '/../../../spec_helper'
2010-09-09 17:50:38 -07:00
describe 'Storage.get_object' do
2009-08-19 20:32:57 -07:00
describe 'success' do
2009-08-19 20:32:57 -07:00
before(:each) do
2010-09-09 17:50:38 -07:00
AWS[:storage].put_bucket('foggetobject')
AWS[:storage].put_object('foggetobject', 'fog_get_object', lorem_file)
end
2009-06-08 15:49:24 -07:00
2009-08-19 20:32:57 -07:00
after(:each) do
2010-09-09 17:50:38 -07:00
AWS[:storage].delete_object('foggetobject', 'fog_get_object')
AWS[:storage].delete_bucket('foggetobject')
end
2009-06-08 15:49:24 -07:00
it 'should return proper attributes' do
2010-09-09 17:50:38 -07:00
actual = AWS[:storage].get_object('foggetobject', 'fog_get_object')
actual.status.should == 200
data = lorem_file.read
actual.body.should == data
actual.headers['Content-Length'].should == data.length.to_s
actual.headers['Content-Type'].should be_a(String)
actual.headers['ETag'].should be_a(String)
actual.headers['Last-Modified'].should be_a(String)
end
2009-09-09 20:44:28 -07:00
it 'should return chunks with optional block' do
data = ''
2010-09-09 17:50:38 -07:00
AWS[:storage].get_object('foggetobject', 'fog_get_object') do |chunk|
2009-09-09 20:44:28 -07:00
data << chunk
end
data.should == lorem_file.read
2009-09-09 20:44:28 -07:00
end
it 'should return a signed expiring url' do
2010-09-09 17:50:38 -07:00
url = AWS[:storage].get_object_url('foggetobject', 'fog_get_object', Time.now + 60 * 10)
unless Fog.mocking?
open(url).read.should == lorem_file.read
end
end
end
describe 'failure' do
it 'should raise a NotFound error if the bucket does not exist' do
lambda {
2010-09-09 17:50:38 -07:00
AWS[:storage].get_object('fognotabucket', 'fog_get_object')
}.should raise_error(Excon::Errors::NotFound)
end
it 'should raise a NotFound error if the object does not exist' do
lambda {
2010-09-09 17:50:38 -07:00
AWS[:storage].get_object('foggetobject', 'fog_not_an_object')
}.should raise_error(Excon::Errors::NotFound)
end
end
2009-06-29 22:23:14 -07:00
end