AnyEvent-Net-Amazon-S3

 view release on metacpan or  search on metacpan

t/02client.t  view on Meta::CPAN

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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,
);
 
my $readme_size   = stat('README')->size;
my $readme_md5hex = file_md5_hex('README');
 
my $client = AnyEvent::Net::Amazon::S3::Client->new( s3 => $s3 );
 
my @buckets = $client->buckets;
 
TODO: {
    local $TODO = "These tests only work if you're pedro";
    my $first_bucket = $buckets[0];
    like( $first_bucket->owner_id, qr/^c7483d612ac7f0c0/, 'have owner id' );

t/02client.t  view on Meta::CPAN

232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
);
is( $objects[0]->etag, $readme_md5hex,
    'newly uploaded object has the right etag' );
is( $objects[0]->size, $readme_size,
    'newly created object has the right size' );
ok( $objects[0]->last_modified, 'newly created object has a last modified' );
 
# download an object with get_filename
my $tmp_fh = File::Temp->new();
$object->get_filename($tmp_fh->filename);
is( stat($tmp_fh->filename)->size,   $readme_size,   'download has right size' );
is( file_md5_hex($tmp_fh->filename), $readme_md5hex, 'download has right etag' );
 
$object->delete;
 
# upload a public object with put_filename with known md5hex and size
$object = $bucket->object(
    key       => 'the new public readme',
    etag      => $readme_md5hex,
    size      => $readme_size,
    acl_short => 'public-read'

t/02client.t  view on Meta::CPAN

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
my $complete_upload_response;
ok(
    $complete_upload_response = $object->complete_multipart_upload( upload_id => $upload_id, part_numbers => [1,2], etags => \@etags),
    "successful response for complete multipart upload"
);
#get the file and check that it looks like we expect
ok($object->exists, "object has now been created");
 
$tmp_fh = File::Temp->new();
$object->get_filename($tmp_fh->filename);
is( stat($tmp_fh->filename)->size, 6 * 1024 * 1024, "downloaded file has a size equivalent to the sum of it's parts");
 
$tmp_fh->seek((5 * 1024 * 1024) - 1, SEEK_SET);#jump to 5MB position
my $test_bytes;
read($tmp_fh, $test_bytes, 2);
is($test_bytes, "xz", "The second chunk of the file begins in the correct place");
 
#test listing a multipart object
$stream = $bucket->list({prefix => 'new multipart file'});
lives_ok {my @items = $stream->items} 'Listing a multipart file does not throw an exeption';



( run in 1.042 second using v1.01-cache-2.11-cpan-49f99fa48dc )