test md5_get on symlinks
[cloudstore.git] / t / Gearman.t
index 8e211b4..c344dd6 100755 (executable)
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 43;
+use Test::More tests => 60;
 use Data::Dump qw(dump);
 
 use lib 'lib';
@@ -11,8 +11,7 @@ use_ok 'CloudStore::Gearman';
 
 my $hostname = `hostname -s`;
 chomp $hostname;
-
-my $user = $ARGV[0] || 2001;
+$hostname =~ s/-dev// && warn "# fix hostname for development";
 
 sub gearman {
        my ( $function, $args ) = @_;
@@ -32,18 +31,22 @@ sub test_refresh_file_list {
        gearman list_files => "~$login";
 }
 
-my $u1 = gearman 'create_user' => 'test@example.com secret 0';
+my $quota = 5 * 1024 * 1024;
+
+my $u1 = gearman 'create_user' => 'test@example.com secret ' . $quota;
 like $u1, qr/u\d+/, "login $u1";
-my $u2 = gearman 'create_user' => 'test2@example.com secret 0';
+my $u2 = gearman 'create_user' => 'test2@example.com secret ' . ($quota + 1);
 like $u2, qr/u\d+/, "login $u2";
-my $u3 = gearman 'create_user' => 'slice2@example.com secret 0';
+my $u3 = gearman 'create_user' => 'slice2@example.com secret ' . ($quota + 2);
 like $u3, qr/u\d+/, "login $u2 (on other slice)";
 
-my $o = gearman $hostname . '_s1_quota_get' => $user;
-diag dump $o;
-cmp_ok $o, '=~', qr/^(\d+)\s+(\d+)$/, 'format: used quota';
+foreach my $login ( $u1, $u2, $u3 ) {
+       my $o = gearman $hostname . '_s1_quota_get' => $login;
+       diag dump $o;
+       cmp_ok $o, '=~', qr/^(\d+)\s+(\d+)$/, 'format: used quota';
+}
 
-gearman( 'user_usage' => $user );
+gearman( 'user_usage' => $u1 );
 
 gearman( $hostname . '_s1_torrent_list' );
 
@@ -53,14 +56,37 @@ foreach my $login ( $u1, $u2 ) {
        ok file_exists "~$login/.meta/files", "file_exists ~$login/.meta/files";
 }
 
-file_exists "~$u1/foo.txt" || BAIL_OUT("~$u1/foo.txt is required for rest of tests");
+if ( ! file_exists("~$u1/foo.txt") ) {
+       diag "create ~$u1/foo.txt";
+       $ENV{RSYNC_PASSWORD} ||= 'secret';
+       system('rsync', '-vv', $0, "rsync://$u1\@127.0.0.1:6501/$u1/" );
+       gearman rename_file => "~$u1/Gearman.t#foo.txt";
+} else {
+       file_exists("~$u1/foo.txt") || BAIL_OUT("~$u1/foo.txt is required for rest of tests");
+}
+
+my $md5 = gearman( 'md5_get' => "~$u1/foo.txt" );
+diag "md5_get = $md5";
 
 gearman send_file => "~$u1/foo.txt#~$u2/dir with space/file with space";
 test_refresh_file_list "$u2";
 
+cmp_ok gearman( 'md5_get' => "~$u2/dir with space/file with space" ), 'eq', $md5, "md5_get on send_file to $u2";
+
+my $files = gearman list_files => "~$u2";
+like $files, qr|dir with space/file with space|, 'found sent file in list_files';
+
+gearman send_file => "~$u2/dir with space/file with space#~$u3/another dir with spaces/and file with spaces";
+test_refresh_file_list "$u3";
+
+cmp_ok gearman( 'md5_get' => "~$u3/another dir with spaces/and file with spaces" ), 'eq', $md5, "md5_get on send_file to $u3";
+
 gearman delete => "~$u2/dir with space/file with space";
 test_refresh_file_list "$u2";
 
+gearman delete => "~$u3/another dir with spaces/and file with spaces";
+test_refresh_file_list "$u3";
+
 gearman send_file => "~$u1/foo.txt#~$u2/foo.txt";
 test_refresh_file_list "$u2";