2009-08-27 23:47:01 -04:00
|
|
|
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
|
|
|
2009-09-02 00:41:52 -04:00
|
|
|
describe 'Fog::AWS::S3::Objects' do
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
@bucket = s3.buckets.create(:name => 'fogbucketname')
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:each) do
|
|
|
|
@bucket.destroy
|
|
|
|
end
|
2009-08-27 23:47:01 -04:00
|
|
|
|
|
|
|
describe "#initialize" do
|
|
|
|
|
2009-09-02 00:41:52 -04:00
|
|
|
it "should remap attributes from parser" do
|
|
|
|
objects = Fog::AWS::S3::Objects.new(
|
|
|
|
'IsTruncated' => true,
|
|
|
|
'Marker' => 'marker',
|
|
|
|
'MaxKeys' => 1,
|
|
|
|
'Prefix' => 'prefix'
|
|
|
|
)
|
|
|
|
objects.is_truncated.should == true
|
|
|
|
objects.marker.should == 'marker'
|
|
|
|
objects.max_keys.should == 1
|
|
|
|
objects.prefix.should == 'prefix'
|
|
|
|
end
|
2009-08-27 23:47:01 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#all" do
|
|
|
|
|
2009-09-02 00:41:52 -04:00
|
|
|
it "should return a Fog::AWS::S3::Objects" do
|
|
|
|
@bucket.objects.all.should be_a(Fog::AWS::S3::Objects)
|
|
|
|
end
|
|
|
|
|
2009-08-27 23:47:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#bucket" do
|
|
|
|
|
2009-09-02 00:41:52 -04:00
|
|
|
it "should return a Fog::AWS::S3::Bucket" do
|
|
|
|
@bucket.objects.bucket.should be_a(Fog::AWS::S3::Bucket)
|
|
|
|
end
|
2009-08-27 23:47:01 -04:00
|
|
|
|
2009-09-02 23:17:53 -04:00
|
|
|
it "should be the bucket the objects are related to" do
|
2009-09-02 00:41:52 -04:00
|
|
|
@bucket.objects.bucket.should == @bucket
|
|
|
|
end
|
2009-08-27 23:47:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#create" do
|
|
|
|
|
2009-09-02 00:41:52 -04:00
|
|
|
it "should return a Fog::AWS::S3::Object" do
|
|
|
|
file = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
|
|
object = @bucket.objects.create(:key => 'fogobjectname', :body => file)
|
|
|
|
object.should be_a(Fog::AWS::S3::Object)
|
|
|
|
object.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should exist on s3" do
|
|
|
|
file = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
|
|
object = @bucket.objects.create(:key => 'fogobjectname', :body => file)
|
|
|
|
@bucket.objects.get('fogobjectname').should_not be_nil
|
|
|
|
object.destroy
|
|
|
|
end
|
2009-08-27 23:47:01 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#get" do
|
|
|
|
|
2009-09-02 23:17:53 -04:00
|
|
|
it "should return a Fog::AWS::S3::Object with metadata and data" do
|
|
|
|
file = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
|
|
object = @bucket.objects.create(:key => 'fogobjectname', :body => file)
|
|
|
|
object = @bucket.objects.get('fogobjectname')
|
|
|
|
object.body.should_not be_nil
|
|
|
|
object.content_length.should_not be_nil
|
|
|
|
object.etag.should_not be_nil
|
|
|
|
object.last_modified.should_not be_nil
|
|
|
|
object.destroy
|
|
|
|
end
|
2009-08-27 23:47:01 -04:00
|
|
|
|
2009-09-10 14:30:50 -04:00
|
|
|
it "should return chunked data if given a block" do
|
|
|
|
file = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
|
|
object = @bucket.objects.create(:key => 'fogobjectname', :body => file)
|
|
|
|
data = ''
|
|
|
|
@bucket.objects.get('fogobjectname') do |chunk|
|
|
|
|
data << chunk
|
|
|
|
end
|
|
|
|
data.should == File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r').read
|
|
|
|
object.destroy
|
|
|
|
end
|
|
|
|
|
2009-08-27 23:47:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-03 18:43:19 -04:00
|
|
|
describe "#get_url" do
|
|
|
|
|
|
|
|
it "should return a signed expiring url" do
|
|
|
|
file = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
|
|
object = @bucket.objects.create(:key => 'fogobjectname', :body => file)
|
|
|
|
url = @bucket.objects.get_url('fogobjectname', Time.now + 60 * 10)
|
2009-10-06 23:35:28 -04:00
|
|
|
unless Fog.mocking?
|
|
|
|
open(url).read.should == File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r').read
|
|
|
|
end
|
2009-10-03 18:43:19 -04:00
|
|
|
object.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2009-08-27 23:47:01 -04:00
|
|
|
describe "#head" do
|
|
|
|
|
2009-09-02 23:17:53 -04:00
|
|
|
it "should return a Fog::AWS::S3::Object with metadata" do
|
|
|
|
file = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
|
|
object = @bucket.objects.create(:key => 'fogobjectname', :body => file)
|
|
|
|
object = @bucket.objects.get('fogobjectname')
|
|
|
|
object.content_length.should_not be_nil
|
|
|
|
object.etag.should_not be_nil
|
|
|
|
object.last_modified.should_not be_nil
|
|
|
|
object.destroy
|
|
|
|
end
|
2009-08-27 23:47:01 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#new" do
|
|
|
|
|
2009-09-02 00:41:52 -04:00
|
|
|
it "should return a Fog::AWS::S3::Object" do
|
|
|
|
@bucket.objects.new.should be_a(Fog::AWS::S3::Object)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#reload" do
|
|
|
|
|
2009-09-02 23:17:53 -04:00
|
|
|
it "should reload from s3" do
|
|
|
|
@bucket.objects.reload.should == @bucket.objects
|
|
|
|
end
|
2009-08-27 23:47:01 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|