Skip to content

Commit db83c1e

Browse files
committed
Add initial rsync tests
1 parent 234c246 commit db83c1e

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-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

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

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)