fix total number of tests
[cloudstore.git] / t / Gearman.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 35;
6 use Data::Dump qw(dump);
7
8 use lib 'lib';
9
10 use_ok 'CloudStore::Gearman';
11
12 my $hostname = `hostname -s`;
13 chomp $hostname;
14
15 my $user = $ARGV[0] || 2001;
16
17 sub gearman {
18         my ( $function, $args ) = @_;
19         ok( my $o = CloudStore::Gearman->gearman_do( @_ ), join(' ',@_) );
20         diag dump $o;
21         return $o;
22 }
23
24 sub file_exists {
25         my ( $file ) = @_;
26         CloudStore::Gearman->gearman_do( file_size => $file );
27 }
28
29 sub test_refresh_file_list {
30         my ( $login ) = @_;
31         ok ! file_exists( "~$login/.meta/files" ), "refresh_file_list removed .meta/files";
32         gearman list_files => "~$login";
33 }
34
35 my $o = gearman $hostname . '_s1_quota_get' => $user;
36 diag dump $o;
37 cmp_ok $o, '=~', qr/^(\d+)\s+(\d+)$/, 'format: used quota';
38
39 gearman( 'user_usage' => $user );
40
41 gearman( $hostname . '_s1_torrent_list' );
42
43 diag "create .meta/files if it doesn't exist";
44 foreach my $uid ( 2001, 2002 ) {
45         gearman list_files => "~u$uid";
46         ok file_exists "~u$uid/.meta/files", "file_exists ~u$uid/.meta/files";
47 }
48
49 gearman send_file => '~u2001/foo.txt#~u2002/dir with space/file with space';
50 test_refresh_file_list 'u2002';
51
52 gearman delete => '~u2002/dir with space/file with space';
53 test_refresh_file_list 'u2002';
54
55 gearman send_file => '~u2001/foo.txt#~u2002/foo.txt';
56 test_refresh_file_list 'u2002';
57
58 gearman rename_file => '~u2002/foo.txt#bar.txt';
59 test_refresh_file_list 'u2002';
60 gearman rename_file => '~u2002/bar.txt#baz.txt';
61 test_refresh_file_list 'u2002';
62
63 cmp_ok  
64 gearman( file_size => '~u2001/foo.txt' ), '==',
65 gearman( file_size => '~u2002/baz.txt' ), 'size_same';
66
67 diag "test symlink to other shard";
68 gearman send_file => '~u2001/foo.txt#~u2004/foo.txt';
69 my $size_1 = gearman( file_size => '~u2001/foo.txt' );
70 my $size_2 = gearman( file_size => '~u2004/foo.txt' );
71
72 cmp_ok $size_1, '==', $size_2, 'symlink size same';
73
74 gearman delete => '~u2002/baz.txt';
75 test_refresh_file_list 'u2002';
76
77 ok ! CloudStore::Gearman->gearman_do( file_size => '~u2002/baz.txt' ), 'deleted file size';
78