base = File.dirname(__FILE__) require File.join(base, '../test_setup') require 'rubygems' require_gem 'FakeWeb' context 'S33r Client' do setup do @base = File.dirname(__FILE__) # client for testing: one without SSL, one with @client = Client.new(Testing::ACCESS_KEY, Testing::SECRET_ACCESS_KEY, :use_ssl => false, :dump_requests => true) @client2 = Client.new(Testing::ACCESS_KEY, Testing::SECRET_ACCESS_KEY) # test config. files @plain_config_file = File.join(@base, '../files/client_config.yml') @custom_config_file = File.join(@base, '../files/namedbucket_config.yml') # OK bucket with attached response @bucket = 'testingtesting' @url = s3_public_url(@bucket) xml_file = File.join(@base, '../files/bucket_listing.xml') @bucket_listing_xml = File.open(xml_file) { |f| f.read } listbucket_response = Net::HTTPResponse.new('1.1', '200', 'OK') listbucket_response.body = @bucket_listing_xml FakeWeb.register_uri(@url, :status => 200, :response => listbucket_response) # broken bucket: for testing behaviour if S3 is unavailable @bucket2 = 's3broken' @url2 = s3_public_url(@bucket2) FakeWeb.register_uri(@url2, :status => 503) # OK resource @resource_key = 'iamhere' @url3 = s3_public_url(@bucket, @resource_key) FakeWeb.register_uri(@url3, :status => 200) # missing resource @missing_resource = 'iammissing' @url4 = s3_public_url(@bucket, @missing_resource) FakeWeb.register_uri(@url4, :status => 404) # missing bucket @missing_bucket = 'iamamissingbucket' @url5 = s3_public_url(@missing_bucket) FakeWeb.register_uri(@url5, :status => 404) end specify 'should return use_ssl setting correctly' do @client.use_ssl.should.not.be true @client2.use_ssl.should.be true end specify 'should trap max_keys too high in bucket listing request' do lambda { @client.list_bucket('duff', :max_keys => (BUCKET_LIST_MAX_MAX_KEYS + 1)) }.should.raise \ BucketListingMaxKeysError end specify 'should fetch bucket listing ok' do resp, listing = @client.list_bucket(@bucket) resp.ok?.should.be true end # NB tests for content of BucketListing in depth are done in spec_bucket_listing specify 'should attach BucketListing instance to ListBucketResult responses' do resp, listing = @client.list_bucket(@bucket) listing.should.be.an_instance_of BucketListing listing.contents.size.should.be 10 end specify 'can be initialised from plain config file' do c = Client.init(@plain_config_file) c.aws_access_key.should.equal 'youraccesskey' c.aws_secret_access_key.should.equal 'yoursecretkey' end specify 'should retain leading slashes on keys when constructing request URLs' do todo end specify 'should raise an error if S3 is down' do lambda { @client.list_bucket(@bucket2) }.should.raise S3FallenOver end specify 'should return S3Object with metadata properties when getting a resource key' do todo end specify 'should identify whether resources exist' do # resource_exists? should work just with a bucket name @client.resource_exists?(@bucket).should.be true # these ones exist @client.bucket_exists?(@bucket).should.be true @client.resource_exists?(@bucket, @resource_key).should.be true # the missing ones @client.resource_exists?(@bucket, @missing_resource).should.be false @client.bucket_exists?(@missing_bucket).should.be false end end