Skip to content

Commit 6b872ea

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

File tree

6 files changed

+78
-0
lines changed

6 files changed

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

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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;
10+
11+
use Rex::Commands::Rsync;
12+
use Rex::Task;
13+
14+
if ( $^O =~ m/^MSWin/ ) {
15+
plan skip_all => 'No rsync support on Windows';
16+
}
17+
else {
18+
plan tests => 1;
19+
}
20+
21+
sub setup {
22+
my $target_dir = tempdir( CLEANUP => 1 );
23+
24+
ok( -d $target_dir, "$target_dir is a directory" );
25+
26+
opendir( my $DIR, $target_dir );
27+
my @contents = readdir $DIR;
28+
closedir $DIR;
29+
30+
my @empty = qw(. ..);
31+
32+
is_deeply( \@contents, \@empty, "$target_dir is empty" );
33+
34+
return $target_dir;
35+
}
36+
37+
sub test_results {
38+
my $target_dir = shift;
39+
40+
my @expected;
41+
find(
42+
{
43+
wanted => sub {
44+
s/t//;
45+
push @expected, $_;
46+
},
47+
no_chdir => 1
48+
},
49+
't/sync'
50+
);
51+
52+
my @result;
53+
find(
54+
{
55+
wanted => sub {
56+
s/$target_dir//;
57+
push @result, $_ if length($_);
58+
},
59+
no_chdir => 1
60+
},
61+
$target_dir
62+
);
63+
64+
is_deeply( \@result, \@expected, 'synced dir matches' );
65+
}
66+
67+
subtest 'local rsync' => sub {
68+
my $target_dir = setup();
69+
my $cwd = getcwd;
70+
71+
my $task = Rex::Task->new( name => 'local_rsync' );
72+
isa_ok( $task, 'Rex::Task', 'create task object' );
73+
74+
sync catfile( $cwd, 't/sync' ), $target_dir;
75+
76+
test_results($target_dir);
77+
};

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)