test refresh_file_list invocations in API
authorDobrica Pavlinusic <dpavlin@rsync1.maxxo.com>
Sat, 14 Apr 2012 15:50:34 +0000 (17:50 +0200)
committerDobrica Pavlinusic <dpavlin@rsync1.maxxo.com>
Sat, 14 Apr 2012 15:50:34 +0000 (17:50 +0200)
t/Gearman.t

index 6983d67..ef3dc47 100755 (executable)
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 19;
+use Test::More tests => 24;
 use Data::Dump qw(dump);
 
 use lib 'lib';
@@ -16,11 +16,22 @@ my $user = $ARGV[0] || 2001;
 
 sub gearman {
        my ( $function, $args ) = @_;
-       ok my $o = CloudStore::Gearman->gearman_do( @_ ), join(' ',@_);
+       ok( my $o = CloudStore::Gearman->gearman_do( @_ ), join(' ',@_) );
        diag dump $o;
        return $o;
 }
 
+sub file_exists {
+       my ( $file ) = @_;
+       CloudStore::Gearman->gearman_do( file_size => $file );
+}
+
+sub test_refresh_file_list {
+       my ( $login ) = @_;
+       ok ! file_exists( "~$login/.meta/files" ), "refresh_file_list removed .meta/files";
+       gearman list_files => "~$login";
+}
+
 my $o = gearman $hostname . '_s1_quota_get' => $user;
 diag dump $o;
 cmp_ok $o, '=~', qr/^(\d+)\s+(\d+)$/, 'format: used quota';
@@ -29,15 +40,25 @@ gearman( 'user_usage' => $user );
 
 gearman( $hostname . '_s1_torrent_list' );
 
+diag "create .meta/files if it doesn't exist";
+foreach my $uid ( 2001, 2002 ) {
+       gearman list_files => "~u$uid";
+       ok file_exists "~u$uid/.meta/files", "file_exists ~u$uid/.meta/files";
+}
 
 gearman send_file => '~u2001/foo.txt#~u2002/dir with space/file with space';
+test_refresh_file_list 'u2002';
 
 gearman delete => '~u2002/dir with space/file with space';
+test_refresh_file_list 'u2002';
 
 gearman send_file => '~u2001/foo.txt#~u2002/foo.txt';
+test_refresh_file_list 'u2002';
 
 gearman rename_file => '~u2002/foo.txt#bar.txt';
+test_refresh_file_list 'u2002';
 gearman rename_file => '~u2002/bar.txt#baz.txt';
+test_refresh_file_list 'u2002';
 
 cmp_ok  
 gearman( file_size => '~u2001/foo.txt' ), '==',
@@ -51,6 +72,7 @@ my $size_2 = gearman( file_size => '~u2004/foo.txt' );
 cmp_ok $size_1, '==', $size_2, 'symlink size same';
 
 gearman delete => '~u2002/baz.txt';
+test_refresh_file_list 'u2002';
 
 ok ! CloudStore::Gearman->gearman_do( file_size => '~u2002/baz.txt' ), 'deleted file size';