1Rex::Test::Base(3)    User Contributed Perl Documentation   Rex::Test::Base(3)
2
3
4

NAME

6       Rex::Test::Base - Basic Test Module
7

DESCRIPTION

9       This is a basic test module to test your code with the help of local
10       VMs. You can place your tests in the "t" directory.
11

EXAMPLE

13        use Rex::Test::Base;
14        use Data::Dumper;
15        use Rex -base;
16
17        test {
18          my $t = shift;
19
20          $t->name("ubuntu test");
21
22          $t->base_vm("http://box.rexify.org/box/ubuntu-server-12.10-amd64.ova");
23          $t->vm_auth(user => "root", password => "box");
24
25          $t->run_task("setup");
26
27          $t->has_package("vim");
28          $t->has_package("ntp");
29          $t->has_package("unzip");
30
31          $t->has_file("/etc/ntp.conf");
32
33          $t->has_service_running("ntp");
34
35          $t->has_content("/etc/passwd", qr{root:x:0:}ms);
36
37          run "ls -l";
38          $t->ok($? == 0, "ls -l returns success.");
39
40          $t->finish;
41        };
42
43        1; # last line
44

METHODS

46   new(name => $test_name)
47       Constructor if used in OO mode.
48
49        my $test = Rex::Test::Base->new(name => "test_name");
50
51   name($name)
52       The name of the test. A VM called $name will be created for each test.
53       If the VM already exists, Rex will try to reuse it.
54
55   memory($amount)
56       The amount of memory the VM should use, in Megabytes.
57
58   cpus($number)
59       The number of CPUs the VM should use.
60
61   vm_auth(%auth)
62       Authentication options for the VM. It accepts the same parameters as
63       "Rex::Box::Base->auth()".
64
65   base_vm($vm)
66       The URL to a base image to be used for the test VM.
67
68   redirect_port($port)
69       Redirect local $port to the VM's SSH port (default: 2222).
70
71   run_task($task)
72       The task to run on the test VM. You can run multiple tasks by passing
73       an array reference.
74

TEST METHODS

76   has_content($file, $regexp)
77       Test if the content of $file matches against $regexp.
78
79   has_dir($path)
80       Test if $path is present and is a directory.
81
82   has_file($file)
83       Test if $file is present.
84
85   has_package($package, $version)
86       Test if $package is installed, optionally at $version.
87
88   has_service_running($service)
89       Test if $service is running.
90
91   has_service_stopped($service)
92       Test if $service is stopped.
93
94   has_stat($file, $stat)
95       Test if $file has properties described in hash reference $stat. List of
96       supported checks:
97
98       group
99       owner
100
101
102
103perl v5.32.1                      2021-03-06                Rex::Test::Base(3)
Impressum