5 use Test::More tests => 29;
6 use Data::Dump qw(dump);
11 use_ok 'CloudStore::API';
13 BEGIN { $ENV{SLICE} = '/rsync1/s1' }
15 ok my $o = CloudStore::API->new('s1'), 'new';
17 die 'You need to run this test as root' unless $> == 0;
19 cmp_ok $o->create_user('md5@example.com','md5sum',0), 'eq', 'md5', 'create_user md5';
21 ok my $info = $o->user_info( 'md5' ), 'user_info';
24 cmp_ok $info->{uid}, '==', 2000, 'uid';
26 ok my $uid = $o->create_user('test@example.com','password',100_000_000), 'create_user test';
28 ok my $test = $o->user_info( $uid ), "user_info $uid";
31 ok open(my $fh, ">", $test->{dir} . '/foo.txt'), 'open';
32 ok print($fh "test pid: $$\n"), 'print';
33 ok close($fh) , 'close';
34 ok chown $test->{uid}, $test->{gid}, "$test->{dir}/foo.txt", 'chown';
36 ok my $uid2 = $o->create_user('test2@example.com','password',100_000_000), 'create_user test2';
37 ok my $test2 = $o->user_info( $uid2 ), "user_info $uid2";
39 foreach ( $test->{dir}, $test2->{dir} ) {
45 ok my $u = $o->usage( $_[0] ), 'usage';
49 ok $o->send_file( $uid => '/foo.txt', $uid2 => 'dir1/dir2/bar.txt' ), 'send_file';
53 ok $o->send_file( $uid2 => 'dir1/dir2/bar.txt', $uid => 'bar.txt' ), 'send_file back';
57 ok $o->send_file( $uid2 => 'dir1/dir2/bar.txt', 2004 => 'bar.txt' ), 'send_file cross-slice';
59 ok $o->delete( $uid, 'foo.txt' );
62 ok $o->delete( $uid2, 'dir1' );
65 ok $o->delete( $uid, 'bar.txt' );
68 my $path = "/tmp/test.$$/base/dir/path";
69 ok $o->mkbasepath( $path, { uid => $info->{uid} } ), "mkbasepath $path";
71 ok ! $o->mkbasepath( $path, { uid => $info->{uid} } ), "exists $path";
73 $path =~ s{/path}{}; # strip file
74 my $uid = (stat($path))[4];
75 diag "uid $path = $uid";
76 cmp_ok $uid, '==', $info->{uid}, "owner $info->{uid}";
78 File::Path::remove_tree("/tmp/test.$$"); # cleanup