5 use Test::More tests => 55;
6 use Data::Dump qw(dump);
10 use_ok 'CloudStore::Gearman';
12 my $hostname = `hostname -s`;
16 my ( $function, $args ) = @_;
17 ok( my $o = CloudStore::Gearman->gearman_do( @_ ), join(' ',@_) );
18 diag "result = ",dump $o if $ENV{DEBUG};
24 CloudStore::Gearman->gearman_do( file_size => $file );
27 sub test_refresh_file_list {
29 ok ! file_exists( "~$login/.meta/files" ), "refresh_file_list removed .meta/files";
30 gearman list_files => "~$login";
33 my $quota = 5 * 1024 * 1024;
35 my $u1 = gearman 'create_user' => 'test@example.com secret ' . $quota;
36 like $u1, qr/u\d+/, "login $u1";
37 my $u2 = gearman 'create_user' => 'test2@example.com secret ' . ($quota + 1);
38 like $u2, qr/u\d+/, "login $u2";
39 my $u3 = gearman 'create_user' => 'slice2@example.com secret ' . ($quota + 2);
40 like $u3, qr/u\d+/, "login $u2 (on other slice)";
42 foreach my $login ( $u1, $u2, $u3 ) {
43 my $o = gearman $hostname . '_s1_quota_get' => $login;
45 cmp_ok $o, '=~', qr/^(\d+)\s+(\d+)$/, 'format: used quota';
48 gearman( 'user_usage' => $u1 );
50 gearman( $hostname . '_s1_torrent_list' );
52 diag "create .meta/files if it doesn't exist";
53 foreach my $login ( $u1, $u2 ) {
54 gearman list_files => "~$login";
55 ok file_exists "~$login/.meta/files", "file_exists ~$login/.meta/files";
58 file_exists "~$u1/foo.txt" || BAIL_OUT("~$u1/foo.txt is required for rest of tests");
60 gearman send_file => "~$u1/foo.txt#~$u2/dir with space/file with space";
61 test_refresh_file_list "$u2";
63 my $files = gearman list_files => "~$u2";
64 like $files, qr|dir with space/file with space|, 'found sent file in list_files';
66 gearman send_file => "~$u2/dir with space/file with space#~$u3/another dir with spaces/and file with spaces";
67 test_refresh_file_list "$u3";
69 gearman delete => "~$u2/dir with space/file with space";
70 test_refresh_file_list "$u2";
72 gearman delete => "~$u3/another dir with spaces/and file with spaces";
73 test_refresh_file_list "$u3";
75 gearman send_file => "~$u1/foo.txt#~$u2/foo.txt";
76 test_refresh_file_list "$u2";
78 gearman rename_file => "~$u2/foo.txt#bar.txt";
79 test_refresh_file_list "$u2";
80 gearman rename_file => "~$u2/bar.txt#baz.txt";
81 test_refresh_file_list "$u2";
84 gearman( file_size => "~$u1/foo.txt" ), '==',
85 gearman( file_size => "~$u2/baz.txt" ), 'size_same';
87 diag "test symlink to other shard";
88 gearman send_file => "~$u1/foo.txt#~$u3/foo.txt";
90 gearman( file_size => "~$u1/foo.txt" ), '==',
91 gearman( file_size => "~$u3/foo.txt" ), 'cross-slice symlink size same';
92 test_refresh_file_list "$u3";
94 gearman delete => "~$u2/baz.txt";
95 test_refresh_file_list "$u2";
97 ok ! file_exists "~$u2/baz.txt", 'deleted file size';