mkbasepath now correctly creates paths with uid
[cloudstore.git] / t / API.t
diff --git a/t/API.t b/t/API.t
index 2083c28..4f81d1f 100755 (executable)
--- a/t/API.t
+++ b/t/API.t
@@ -2,19 +2,19 @@
 use strict;
 use warnings;
 
-use Test::More tests => 25;
+use Test::More tests => 29;
 use Data::Dump qw(dump);
+use File::Path;
 
 use lib 'lib';
 
 use_ok 'CloudStore::API';
 
-$ENV{PORT}=6500;
-$ENV{SLICE}='/tmp/';
+ok my $o = CloudStore::API->new('s1'), 'new';
 
-ok my $o = CloudStore::API->new, 'new';
+die 'You need to run this test as root' unless $> == 0;
 
-cmp_ok $o->create_user('md5@example.com','md5sum',0), '==', 2000, 'create_user md5';
+cmp_ok $o->create_user('md5@example.com','md5sum',0), 'eq', 'u2000', 'create_user md5';
 
 ok my $info = $o->user_info( 'md5' ), 'user_info';
 diag dump $info;
@@ -52,6 +52,8 @@ ok $o->send_file( $uid2 => 'dir1/dir2/bar.txt', $uid => 'bar.txt' ), 'send_file
 usage $uid;
 usage $uid2;
 
+ok $o->send_file( $uid2 => 'dir1/dir2/bar.txt', 2004 => 'bar.txt' ), 'send_file cross-slice';
+
 ok $o->delete( $uid, 'foo.txt' );
 usage $uid;
 
@@ -61,3 +63,15 @@ usage $uid2;
 ok $o->delete( $uid, 'bar.txt' );
 usage $uid;
 
+my $path = "/tmp/test.$$/base/dir/path";
+ok $o->mkbasepath( $path, { uid => $info->{uid} } ), "mkbasepath $path";
+
+ok ! $o->mkbasepath( $path, { uid => $info->{uid} } ), "exists $path";
+
+$path =~ s{/path}{}; # strip file
+my $uid = (stat($path))[4];
+diag "uid $path = $uid";
+cmp_ok $uid, '==', $info->{uid}, "owner $info->{uid}";
+
+File::Path::remove_tree("/tmp/test.$$"); # cleanup
+