2009-08-17 15:55:30 -07:00
|
|
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2009-06-07 01:37:54 -07:00
|
|
|
|
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-06-07 01:37:54 -07:00
|
|
|
|
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)
|
2009-08-19 19:11:57 -07:00
|
|
|
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')
|
2009-08-19 19:11:57 -07:00
|
|
|
end
|
2009-06-08 15:49:24 -07:00
|
|
|
|
2009-08-19 19:11:57 -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')
|
2009-08-19 19:11:57 -07:00
|
|
|
actual.status.should == 200
|
2009-11-05 09:19:48 -08:00
|
|
|
data = lorem_file.read
|
2009-08-19 19:11:57 -07:00
|
|
|
actual.body.should == data
|
|
|
|
actual.headers['Content-Length'].should == data.length.to_s
|
2009-09-02 20:09:06 -07:00
|
|
|
actual.headers['Content-Type'].should be_a(String)
|
2009-08-19 19:11:57 -07:00
|
|
|
actual.headers['ETag'].should be_a(String)
|
|
|
|
actual.headers['Last-Modified'].should be_a(String)
|
|
|
|
end
|
2009-06-07 01:37:54 -07:00
|
|
|
|
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
|
2009-11-05 09:19:48 -08:00
|
|
|
data.should == lorem_file.read
|
2009-09-09 20:44:28 -07:00
|
|
|
end
|
|
|
|
|
2009-10-03 15:43:19 -07:00
|
|
|
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)
|
2009-10-08 23:13:17 -07:00
|
|
|
unless Fog.mocking?
|
2009-11-05 09:19:48 -08:00
|
|
|
open(url).read.should == lorem_file.read
|
2009-10-08 23:13:17 -07:00
|
|
|
end
|
2009-10-03 15:43:19 -07:00
|
|
|
end
|
|
|
|
|
2009-08-16 13:31:36 -07:00
|
|
|
end
|
2009-08-19 19:11:57 -07:00
|
|
|
describe 'failure' do
|
2009-08-16 13:31:36 -07:00
|
|
|
|
2009-08-19 19:11:57 -07:00
|
|
|
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')
|
2009-10-31 12:26:49 -07:00
|
|
|
}.should raise_error(Excon::Errors::NotFound)
|
2009-08-19 19:11:57 -07:00
|
|
|
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')
|
2009-10-31 12:26:49 -07:00
|
|
|
}.should raise_error(Excon::Errors::NotFound)
|
2009-08-19 19:11:57 -07:00
|
|
|
end
|
2009-08-16 13:31:36 -07:00
|
|
|
|
2009-08-19 19:11:57 -07:00
|
|
|
end
|
2009-06-29 22:23:14 -07:00
|
|
|
end
|