Archive for the ‘AmazonS3’ Category

Amazon S3, Ruby, and the failing tests

A friend of mine, Jeko, introduced me to Amazon S3, praising the Ruby support, and the ease of use. So when Gabriele Renzi suggested me a potential wonderful use for S3 (still secret, sorry) I decided to give it a try and downloaded the Ruby sample libraries.

Unfortunately all the tests were failing, and that made me unhappy. What made it strange was that the first time I ran the tests I two errors, and the second time I ran them the first error was replaced by another one.

I dag into the code and found a simple but effective fix for all the problems.

The first-error-replacement was caused by a non emptying of the test Bucket after the tests failed. I edited the setup method in the test suite to look like this:

def setup
    @conn = S3::AWSAuthConnection.new(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
     @conn.list_bucket(BUCKET_NAME).entries.each do |object|
       @conn.delete(BUCKET_NAME, object.key)
     end
     @conn.delete_bucket(BUCKET_NAME)
  end

Now I kept getting the same error but it was an easy fix: edit line 534 of S3.rb to look like this:

  @properties.name = @curr_text.strip

With this two fixes the test suite runs correctly (I can’t certify its validity though :) ). After a succesful test run you can remove the fixes to the setup method, because it keeps working fine, but I would leave them untouched, you never know if there’s a problem in a test ;)