Rex
view release on metacpan or search on metacpan
lib/Rex/Test/Base.pm view on Meta::CPAN
Redirect local $port to the VM's SSH port (default: 2222).
=cut
sub redirect_port {
my ( $self, $port ) = @_;
$self->{redirect_port} = $port;
}
=head2 run_task($task)
The task to run on the test VM. You can run multiple tasks by passing an array reference.
=cut
sub run_task {
my ( $self, $task ) = @_;
# allow multiple calls to run_task() without setting up new box
if ( $self->{box} ) {
$self->{box}->provision_vm($task);
return;
}
my $box;
box {
$box = shift;
$box->name( $self->{name} );
$box->url( $self->{vm} );
$box->memory( $self->{memory} );
$box->cpus( $self->{cpus} );
$box->network(
1 => {
type => "nat",
}
);
$box->forward_port( ssh => [ $self->{redirect_port}, 22 ] );
$box->auth( %{ $self->{auth} } );
if ( ref $task eq 'ARRAY' ) {
$box->setup(@$task);
}
else {
$box->setup($task);
}
};
$self->{box} = $box;
# connect to the machine
Rex::connect(
server => $box->ip,
%{ $self->{auth} },
);
}
sub ok() {
my ( $self, $test, $msg ) = @_;
my $tb = Rex::Test::Base->builder;
$tb->ok( $test, $msg );
}
sub like {
my ( $self, $thing, $want, $name ) = @_;
my $tb = Rex::Test::Base->builder;
$tb->like( $thing, $want, $name );
}
sub diag {
my ( $self, $msg ) = @_;
my $tb = Rex::Test::Base->builder;
$tb->diag($msg);
}
sub finish {
my $tb = Rex::Test::Base->builder;
$tb->done_testing();
$tb->is_passing()
? print "PASS\n"
: print "FAIL\n";
if ( !$tb->is_passing() ) {
Rex::Test::push_exit("FAIL");
}
$tb->reset();
Rex::pop_connection();
}
=head1 TEST METHODS
=head2 has_content($file, $regexp)
Test if the content of $file matches against $regexp.
=head2 has_dir($path)
Test if $path is present and is a directory.
=head2 has_file($file)
Test if $file is present.
=head2 has_package($package, $version)
Test if $package is installed, optionally at $version.
=head2 has_service_running($service)
Test if $service is running.
=head2 has_service_stopped($service)
Test if $service is stopped.
=head2 has_stat($file, $stat)
Test if $file has properties described in hash reference $stat. List of supported checks:
( run in 4.355 seconds using v1.01-cache-2.11-cpan-c966e8aa7e8 )