Amazon-S3-Thin
view release on metacpan or search on metacpan
xt/91_functional.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Config::Tiny;
use Amazon::S3::Thin;
if (!$ENV{EXTENDED_TESTING}) {
plan skip_all => 'Skip functional test because it would call S3 APIs and charge real money. $ENV{EXTENDED_TESTING} is not set.';
}
my $debug = 1;
my $use_https = 1;
my $config_file = $ENV{HOME} . '/.aws/credentials';
my $profile = 's3thin';
my $bucket = $ENV{TEST_S3THIN_BUCKET} || 'dqneo-private-test';
my $crd = Config::Tiny->read($config_file)->{$profile};
sub test_with_existing_bucket {
my $crd = shift;
my $arg = shift;
diag('Testing with existing resources.');
# This region is that of the bucket used in this test,
# because in signature v4 we must know the region of a bucket before accessing it.
my $region = 'ap-northeast-1';
my %opt = (
aws_access_key_id => $crd->{aws_access_key_id},
aws_secret_access_key => $crd->{aws_secret_access_key},
secure => $use_https,
signature_version => $arg->{signature_version},
region => $region,
# use_path_style => $arg->{use_path_style},
debug => $debug,
);
my $s3client = Amazon::S3::Thin->new(\%opt);
ok $s3client, 'new';
# These bucket and key suppose to exists beforehand.
my $key = 'hello.txt';
my $response;
diag('get an existing object in an existing bucket');
$response = $s3client->get_object($bucket, $key);
is $response->code , 200;
is $response->content, "hello world\n";
diag('list object in an existing bucket');
$response = $s3client->list_objects($bucket);
is $response->code , 200;
like $response->content, qr/hello.txt/;
}
sub test_with_new_bucket {
my $crd = shift;
my $arg = shift;
diag(' region ' . $arg->{region});
my %opt = (
aws_access_key_id => $crd->{aws_access_key_id},
aws_secret_access_key => $crd->{aws_secret_access_key},
secure => $use_https,
signature_version => $arg->{signature_version},
region => $arg->{region},
# use_path_style => $arg->{use_path_style},
debug => $debug,
);
my $s3client = Amazon::S3::Thin->new(\%opt);
my $bucket = 's3thin-' . $arg->{region} . $arg->{signature_version} . time();
my $response;
$response = $s3client->put_bucket($bucket);
( run in 0.948 second using v1.01-cache-2.11-cpan-98e64b0badf )