Skip to content

Commit

Permalink
Merge 64c17e0 into 2675153
Browse files Browse the repository at this point in the history
  • Loading branch information
ferki committed Jul 29, 2023
2 parents 2675153 + 64c17e0 commit c5d5742
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 40 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -5,6 +5,7 @@ Revision history for Rex

[BUG FIXES]
- Fix checking test git repository
- Fix local package installation

[DOCUMENTATION]

Expand Down
2 changes: 1 addition & 1 deletion lib/Rex/Pkg/Base.pm
Expand Up @@ -62,7 +62,7 @@ sub update {
my ( $self, $pkg, $option ) = @_;

my $version = $option->{'version'} || '';
my $env = $option->{'env'} || ();
my $env = $option->{'env'} || {};

Rex::Logger::debug( "Installing $pkg" . ( $version ? "-$version" : "" ) );
my $cmd;
Expand Down
27 changes: 27 additions & 0 deletions lib/Rex/Pkg/Test.pm
@@ -0,0 +1,27 @@
#
# (c) Ferenc Erki <erkiferenc@gmail.com>
#

package Rex::Pkg::Test;

use v5.12.5;
use warnings;

our $VERSION = '9999.99.99_99'; # VERSION

use Rex::Pkg::Base;
use base qw(Rex::Pkg::Base);

sub new {
my $that = shift;
my $proto = ref($that) || $that;
my $self = $proto->SUPER::new(@_);

bless $self, $proto;

$self->{commands} = { install => 'echo %s' };

return $self;
}

1;
89 changes: 50 additions & 39 deletions t/package.t
Expand Up @@ -5,45 +5,56 @@ use warnings;

our $VERSION = '9999.99.99_99'; # VERSION

use Test::More tests => 1;
use Test::More tests => 2;
use Test::Deep;

use Rex::Pkg::Base;

my $pkg = Rex::Pkg::Base->new;

my @plist1 = (
{ name => 'vim', version => '1.0' },
{ name => 'mc', version => '2.0' },
{ name => 'rex', version => '0.51.0' },
);

my @plist2 = (
{ name => 'vim', version => '1.0' },
{ name => 'rex', version => '0.52.0' },
{ name => 'libssh2-1', version => '0.32.1' },
);

my @expected = (
{
action => 'updated',
name => 'rex',
version => '0.52.0',
},
{
action => 'removed',
name => 'mc',
version => '2.0',
},
{
action => 'installed',
name => 'libssh2-1',
version => '0.32.1',
},
);

my @mods = $pkg->diff_package_list( \@plist1, \@plist2 );

cmp_deeply( \@mods, \@expected, 'expected package modifications' );
use Test::Exception;

use Rex::Pkg::Test;

my $pkg = Rex::Pkg::Test->new;

subtest 'package list diffs' => sub {
plan tests => 1;

my @plist1 = (
{ name => 'vim', version => '1.0' },
{ name => 'mc', version => '2.0' },
{ name => 'rex', version => '0.51.0' },
);

my @plist2 = (
{ name => 'vim', version => '1.0' },
{ name => 'rex', version => '0.52.0' },
{ name => 'libssh2-1', version => '0.32.1' },
);

my @expected = (
{
action => 'updated',
name => 'rex',
version => '0.52.0',
},
{
action => 'removed',
name => 'mc',
version => '2.0',
},
{
action => 'installed',
name => 'libssh2-1',
version => '0.32.1',
},
);

my @mods = $pkg->diff_package_list( \@plist1, \@plist2 );

cmp_deeply( \@mods, \@expected, 'expected package modifications' );
};

subtest 'local package installation' => sub {
plan tests => 1;

lives_ok { $pkg->update('test_package') }, 'update test package';
};

1;

0 comments on commit c5d5742

Please sign in to comment.