The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Rex::Test::Base - Basic Test Module

DESCRIPTION

This module is a basic Test module to test your Code with the help of local VMs. To create a test you first have to create the "t" directory. Then you can create your test files inside this directory.

EXAMPLE

 use Rex::Test::Base;
 use Data::Dumper;
 use Rex -base;
 
 test {
   my $t = shift;
 
   $t->name("ubuntu test");
 
   $t->base_vm("http://box.rexify.org/box/ubuntu-server-12.10-amd64.ova");
   $t->vm_auth(user => "root", password => "box");
 
   $t->run_task("setup");
 
   $t->has_package("vim");
   $t->has_package("ntp");
   $t->has_package("unzip");
 
   $t->has_file("/etc/ntp.conf");
 
   $t->has_service_running("ntp");
 
   $t->has_content("/etc/passwd", qr{root:x:0:}ms);
 
   run "ls -l";
   $t->ok($? == 0, "ls -l returns success.");
 
   $t->finish;
 };
 
 1; # last line

METHODS

new(name => $test_name)

Constructor if used in OO mode.

 my $test = Rex::Test::Base->new(name => "test_name");
name($name)

The name of the test. For each test a new vm will be created named after $name.

vm_auth(%auth)

Authentication option for the VM.

base_vm($vm)

The url to a vm that should be used as base VM.

redirect_port($port)

The redirected SSH port. Default 2222.

run_task($task)

The task to run on the test vm. You can run multiple tasks by passing an array reference.

TEST METHODS

has_content($file, $regexp)

Test if the content of $file matches against $regexp.

has_package($package, $version)

Test if the package $package is installed, optionally at $version.

has_file($file)

Test if the file $file is present.

has_service_running($service)

Test if the service $service is running.

has_service_stopped($service)

Test if the service $service is stopped.

has_stat($file, $stat)

Test if the file $file has properties described in hash reference $stat. List of supported checks:

- group
- owner