root/lang/perl/Net-Amazon-HadoopEC2-S3fs/trunk/t/01_module.t @ 22245

Revision 22245, 2.5 kB (checked in by lopnor, 5 years ago)

pods, some interface changes

Line 
1use strict;
2use warnings;
3use Test::More;
4use File::Temp;
5use File::Spec;
6use File::Basename;
7
8BEGIN {
9    for (qw( AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY S3FS_TEST_BUCKET)) {
10        unless ($ENV{$_}) {
11            plan skip_all => "set $_ to run this test.";
12            exit 0;
13        }
14    }
15    plan tests => 18;
16    use_ok 'Net::Amazon::HadoopEC2::S3fs';
17}
18
19my $fs = Net::Amazon::HadoopEC2::S3fs->new(
20    {
21        aws_access_key_id => $ENV{AWS_ACCESS_KEY_ID},
22        aws_secret_access_key => $ENV{AWS_SECRET_ACCESS_KEY},
23        bucket => $ENV{S3FS_TEST_BUCKET},
24    }
25);
26isa_ok $fs, 'Net::Amazon::HadoopEC2::S3fs';
27{
28    my $res = $fs->s3->list_all;
29    for my $key (@{$res->{keys}}) {
30        $fs->s3->delete_key($key->{key});
31    }
32}
33
34{
35    my $dir = $fs->mkdir('/');
36    isa_ok $dir, 'Net::Amazon::HadoopEC2::S3fs::Inode';
37    my $list = $fs->list('/');
38    is scalar @{$list}, 1;
39    isa_ok $list->[0], 'Net::Amazon::HadoopEC2::S3fs::Inode';
40    is $list->[0]->inode_type, 'directory';
41    is $list->[0]->path, '/';
42}
43{
44    for (qw( /user /user/root /user/root/input )) {
45        my $dir = $fs->mkdir($_);
46    }
47    my $list = $fs->list('/');
48}
49{
50    my $tmp = File::Temp->new;
51    print $tmp 'hogehoge';
52    close $tmp;
53    my $destination = '/user/root/input';
54    my $path = File::Spec->catfile($destination, basename($tmp->filename));
55    {
56        my $file = $fs->put(
57            {
58                file => $tmp->filename,
59                destination => $destination,
60            }
61        );
62        isa_ok $file, 'Net::Amazon::HadoopEC2::S3fs::Inode';
63    }
64    {
65        my $list = $fs->list($destination);
66        is scalar @{$list}, 2;
67        my ($file) = grep {$_->path eq $path} @{$list};
68        isa_ok $file, 'Net::Amazon::HadoopEC2::S3fs::Inode';
69        is $file->path, $path;
70        is $file->inode_type, 'file';
71        my $blocks = $file->blocks;
72        is scalar @{$blocks}, 1;
73        my $block = $blocks->[0];
74        is $block->size, 8;
75    }
76    {
77        my $got = File::Temp->new;
78        close $got;
79        ok $fs->get(
80            {
81                file => $path,
82                destination => $got->filename,
83            }
84        );
85        open my $fh, $got->filename;
86        my $content = do {local $/; <$fh>};
87        is $content, 'hogehoge';
88    }
89    {
90        ok $fs->remove($path);
91        my $list = $fs->list($destination);
92        is scalar @{$list}, 1;
93    }
94}
95{
96    my $res = $fs->s3->list_all;
97    for my $key (@{$res->{keys}}) {
98        $fs->s3->delete_key($key->{key});
99    }
100}
Note: See TracBrowser for help on using the browser.