test symlink md5 retrival
[cloudstore.git] / t / API.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 29;
6 use Data::Dump qw(dump);
7 use File::Path;
8
9 use lib 'lib';
10
11 use_ok 'CloudStore::API';
12
13 ok my $o = CloudStore::API->new('s1'), 'new';
14
15 die 'You need to run this test as root' unless $> == 0;
16
17 cmp_ok $o->create_user('md5@example.com','md5sum',0), 'eq', 'u2000', 'create_user md5';
18
19 ok my $info = $o->user_info( 'md5' ), 'user_info';
20 diag dump $info;
21
22 cmp_ok $info->{uid}, '==', 2000, 'uid';
23
24 ok my $uid = $o->create_user('test@example.com','password',100_000_000), 'create_user test';
25 diag "test: $uid";
26 ok my $test = $o->user_info( $uid ), "user_info $uid";
27 diag dump($test);
28
29 ok open(my $fh, ">", $test->{dir} . '/foo.txt'), 'open';
30 ok print($fh "test pid: $$\n"), 'print';
31 ok close($fh) , 'close';
32 ok chown $test->{uid}, $test->{gid}, "$test->{dir}/foo.txt", 'chown';
33
34 ok my $uid2 = $o->create_user('test2@example.com','password',100_000_000), 'create_user test2';
35 ok my $test2 = $o->user_info( $uid2 ), "user_info $uid2";
36
37 foreach ( $test->{dir}, $test2->{dir} ) {
38         $_ .= "/.log";
39         unlink $_ if -e $_;
40 }
41
42 sub usage {
43         ok my $u = $o->usage( $_[0] ), 'usage';
44 #       diag dump $u;
45 }
46
47 ok $o->send_file( $uid => '/foo.txt', $uid2 => 'dir1/dir2/bar.txt' ), 'send_file';
48 usage $uid;
49 usage $uid2;
50
51 ok $o->send_file( $uid2 => 'dir1/dir2/bar.txt', $uid => 'bar.txt' ), 'send_file back';
52 usage $uid;
53 usage $uid2;
54
55 ok $o->send_file( $uid2 => 'dir1/dir2/bar.txt', 2004 => 'bar.txt' ), 'send_file cross-slice';
56
57 ok $o->delete( $uid, 'foo.txt' );
58 usage $uid;
59
60 ok $o->delete( $uid2, 'dir1' );
61 usage $uid2;
62
63 ok $o->delete( $uid, 'bar.txt' );
64 usage $uid;
65
66 my $path = "/tmp/test.$$/base/dir/path";
67 ok $o->mkbasepath( $path, { uid => $info->{uid} } ), "mkbasepath $path";
68
69 ok ! $o->mkbasepath( $path, { uid => $info->{uid} } ), "exists $path";
70
71 $path =~ s{/path}{}; # strip file
72 my $uid = (stat($path))[4];
73 diag "uid $path = $uid";
74 cmp_ok $uid, '==', $info->{uid}, "owner $info->{uid}";
75
76 File::Path::remove_tree("/tmp/test.$$"); # cleanup
77