Rex::Test::Base(3pm)
β¨ Rex::Test::Base β¨
okay so bestie, welcome to the User Contributed Perl Documentation for Rex::Test::Base, the module you reach for when you wanna run your tests against actual local VMs. it's giving "I own a tiny datacenter in my laptop" energy and honestly? iconic. π
πΈ NAME πΈ
Rex::Test::Base β the Basic Test Module. that's it, that's the name, no notes. π
π¦ DESCRIPTION π¦
so this is a basic test module that lets you test your code with the help of local VMs. yes, like, real ones. virtual machines. for your tests. slay. π₯οΈβ¨
you can drop all your tests into the t directory and Rex will find them. that's the vibe. no cap. π«Ά
π EXAMPLE π
here's the whole thing, verbatim, don't @ me, it's the actual code:
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
look at that. $t->finish; at the end like a proper little bow. π and yeah, 1; # last line really is the last line, we're not being cute about it (okay maybe a little). π
π METHODS π
π new(name => $test_name)
the constructor!!! use this if you're living that OO mode life:
my $test = Rex::Test::Base->new(name => "test_name");
π name($name)
sets the name of the test. here's the tea tho: a VM called $name will be created for each test. and if that VM already exists? Rex will try to reuse it. convenient! π
π memory($amount)
how much memory the VM should use, in Megabytes. feed it a number, bestie. don't starve your VM. π§
π cpus($number)
how many CPUs the VM should use. go off, give it the whole core collection. π₯
π vm_auth(%auth)
authentication options for the VM. it accepts the exact same parameters as Rex::Box::Base->auth(). so like, go read that one if you need the full spread. π
π base_vm($vm)
the URL to a base image that gets used for the test VM. this is where your little VM is born. π₯π¦
π redirect_port($port)
redirects local $port to the VM's SSH port. and the default SSH port? 2222. so if you don't pass anything, that's what you're getting. πͺβ¨
π run_task($task)
the task to run on the test VM. and!! you can run multiple tasks by passing an array reference. go multi-task, main character. π
π TEST METHODS π
okay these are the actual assertions, the moment we've all been waiting for. π₯
π has_content($file, $regexp)
tests if the content of $file matches against $regexp. π
π has_dir($path)
tests if $path is present and is a directory. π
π has_file($file)
tests if $file is present. π
π has_package($package, $version)
tests if $package is installed, and optionally that it's installed at $version. π¦
π has_service_running($service)
tests if $service is running. π’
π has_service_stopped($service)
tests if $service is stopped. π΄
π has_stat($file, $stat)
tests if $file has the properties described in the hash reference $stat. here's the full list of supported checks, no gatekeeping:
groupowner
and that's the whole page, bestie!! π«Ά no missing bits, no skipped options, we kept it π―.
ngl the vibe check passed, and if your tests are flaky it's not the module's fault, it's the VM's. π
perl v5.40.1 Β· 2025-10-03 β mwah, that's the version and date, go forth and test responsibly. π β¨π
π¦ where this page comes from
- ubuntu resolute: rex 1.16.1-1 Β· Apache-2.0
- ubuntu stonking: rex 1.16.1-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms