AnyEvent-Net-Amazon-S3

 view release on metacpan or  search on metacpan

t/01api.t  view on Meta::CPAN

#!perl
use warnings;
use strict;
use lib 'lib';
use Digest::MD5::File qw(file_md5_hex);
use Test::More;

unless ( $ENV{'AMAZON_S3_EXPENSIVE_TESTS'} ) {
    plan skip_all => 'Testing this module for real costs money.';
} else {
#    plan tests => 71 * 2 + 4;
    plan tests => 71 * 1 + 4;
}

use_ok('AnyEvent::Net::Amazon::S3');

use vars qw/$OWNER_ID $OWNER_DISPLAYNAME/;

my $aws_access_key_id     = $ENV{'AWS_ACCESS_KEY_ID'};
my $aws_secret_access_key = $ENV{'AWS_ACCESS_KEY_SECRET'};

my $s3 = AnyEvent::Net::Amazon::S3->new(
    {   aws_access_key_id     => $aws_access_key_id,
        aws_secret_access_key => $aws_secret_access_key,
        retry                 => 1,
    }
);

# list all buckets that i own
my $response = $s3->buckets;

$OWNER_ID          = $response->{owner_id};
$OWNER_DISPLAYNAME = $response->{owner_displayname};

TODO: {
    local $TODO = "These tests only work if you're pedro";

    like( $response->{owner_id}, qr/^c7483d612ac7f0c0/ );
    is( $response->{owner_displayname},   'pedro_figueiredo' );
    is( scalar @{ $response->{buckets} }, 6 );
}

# Currently, seems not to work correctly
#for my $location ( undef, 'US' ) {
for my $location ( undef ) {

  # create a bucket
  # make sure it's a valid hostname for EU testing
    my $bucketname = 'net-amazon-s3-test-' . lc($aws_access_key_id) . '-' . time;

    # for testing
    # my $bucket = $s3->bucket($bucketname); $bucket->delete_bucket; exit;

    my $bucket_obj = $s3->add_bucket(
        {   bucket              => $bucketname,
            acl_short           => 'public-read',
            location_constraint => $location
        }
    ) or die $s3->err . ": " . $s3->errstr;

    is( ref $bucket_obj,                      "AnyEvent::Net::Amazon::S3::Bucket" );
    is( $bucket_obj->get_location_constraint, $location );

    like_acl_allusers_read($bucket_obj);



( run in 1.155 second using v1.01-cache-2.11-cpan-39bf76dae61 )