Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial rsync tests #1357

Merged
merged 3 commits into from
Jun 26, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add initial rsync tests
  • Loading branch information
ferki committed Jun 26, 2020
commit c1607d02e5c06bbf247e132665ea34619c1db7d1
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ Revision history for Rex
[REVISION]
- Use author tests to check tidiness of bin files
- Use Symbol to manipulate Perl symbols
- Add initial rsync tests

1.11.0 2020-06-05 Ferenc Erki <erkiferenc@gmail.com>
[BUG FIXES]
96 changes: 96 additions & 0 deletions t/rsync.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
use strict;
use warnings;
use autodie;

BEGIN {
use Test::More;
use Rex::Commands::Run;

can_run('rsync') or plan skip_all => 'Could not find rsync command';

eval 'use Rex::Commands::Rsync; 1'
or plan skip_all => 'Could not load Rex::Commands::Rsync module';
}

use Cwd qw(getcwd);
use File::Find;
use File::Spec::Functions qw(catfile rel2abs);
use File::Temp qw(tempdir);
use Rex::Task;

plan tests => 2;

sub setup {
my $target_dir = tempdir( CLEANUP => 1 );

ok( -d $target_dir, "$target_dir is a directory" );

opendir( my $DIR, $target_dir );
my @contents = readdir $DIR;
closedir $DIR;

my @empty = qw(. ..);

is_deeply( \@contents, \@empty, "$target_dir is empty" );

return $target_dir;
}

sub test_results {
my ( $source, $target ) = @_;
my ( @expected, @result );

# expected results
find(
{
wanted => sub {
s:^(t|.*/t)(?=/)::;
push @expected, $_;
},
no_chdir => 1
},
$source
);

# actual results
find(
{
wanted => sub {
s/$target//;
push @result, $_ if length($_);
},
no_chdir => 1
},
$target
);

is_deeply( \@result, \@expected, 'synced dir matches' );
}

subtest 'local rsync with absolute path' => sub {
my $cwd = getcwd();

my $source = catfile( $cwd, 't/sync' );
my $target = setup();

my $task = Rex::Task->new( name => 'local_rsync' );
isa_ok( $task, 'Rex::Task', 'task exists' );

sync $source, $target;

test_results( $source, $target );
};

subtest 'local rsync with relative path' => sub {
my $cwd = getcwd();

my $source = 't/sync';
my $target = setup();

my $task = Rex::Task->new( name => 'local_rsync' );
isa_ok( $task, 'Rex::Task', 'task exists' );

sync $source, $target;

test_results( $source, $target );
};
Empty file added t/sync/dir/file3
Empty file.
Empty file added t/sync/dir/file4
Empty file.
Empty file added t/sync/file1
Empty file.
Empty file added t/sync/file2
Empty file.