Skip to content

Commit b3f121a

Browse files
committed
Add initial rsync tests
1 parent 5b14179 commit b3f121a

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Revision history for Rex
2323
[REVISION]
2424
- Use author tests to check tidiness of bin files
2525
- Use Symbol to manipulate Perl symbols
26+
- Add initial rsync tests
2627

2728
1.11.0 2020-06-05 Ferenc Erki <[email protected]>
2829
[BUG FIXES]

t/rsync.t

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
use strict;
2+
use warnings;
3+
use autodie;
4+
5+
use Cwd qw(getcwd);
6+
use File::Find;
7+
use File::Spec::Functions qw(catfile rel2abs);
8+
use File::Temp qw(tempdir);
9+
use Test::More tests => 1;
10+
11+
use Rex::Commands::Rsync;
12+
use Rex::Task;
13+
14+
sub setup {
15+
my $target_dir = tempdir( CLEANUP => 1 );
16+
17+
ok( -d $target_dir, "$target_dir is a directory" );
18+
19+
opendir( my $DIR, $target_dir );
20+
my @contents = readdir $DIR;
21+
closedir $DIR;
22+
23+
my @empty = qw(. ..);
24+
25+
is_deeply( \@contents, \@empty, "$target_dir is empty" );
26+
27+
return $target_dir;
28+
}
29+
30+
sub test_results {
31+
my $target_dir = shift;
32+
33+
my @expected;
34+
find(
35+
{
36+
wanted => sub {
37+
s/t//;
38+
push @expected, $_;
39+
},
40+
no_chdir => 1
41+
},
42+
't/sync'
43+
);
44+
45+
my @result;
46+
find(
47+
{
48+
wanted => sub {
49+
s/$target_dir//;
50+
push @result, $_ if length($_);
51+
},
52+
no_chdir => 1
53+
},
54+
$target_dir
55+
);
56+
57+
is_deeply( \@result, \@expected, 'synced dir matches' );
58+
}
59+
60+
subtest 'local rsync' => sub {
61+
my $target_dir = setup();
62+
my $cwd = getcwd;
63+
64+
my $task = Rex::Task->new( name => 'local_rsync' );
65+
isa_ok( $task, 'Rex::Task', 'create task object' );
66+
67+
sync catfile( $cwd, 't/sync' ), $target_dir;
68+
69+
test_results($target_dir);
70+
};

t/sync/dir/file3

Whitespace-only changes.

t/sync/dir/file4

Whitespace-only changes.

t/sync/file1

Whitespace-only changes.

t/sync/file2

Whitespace-only changes.

0 commit comments

Comments
 (0)