Rex::Test::Base(3)
π Rex::Test::Base(3) β Basic Test Module π
hey bestie!! welcome to the Rex::Test::Base page β itβs giving βbasic test module but make it usefulβ and Iβm obsessed π«Άβ¨
β¨ NAME β¨
Rex::Test::Base β Basic Test Module
πΈ DESCRIPTION πΈ
okay so bestie, this is a basic test module to test your code with the help of local VMs. You can place your tests in the t directory. thatβs it, thatβs the vibe π
π EXAMPLE π
hereβs the example, exactly as it lives β copy it with love, no cap:
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. A VM called $name will be created for each test. If the VM already exists, Rex will try to reuse it. reuse era β»οΈβ¨
π memory($amount)
The amount of memory the VM should use, in Megabytes π°
π§ cpus($number)
The number of CPUs the VM should use. CPU budget bestie β‘
π vm_auth(%auth)
Authentication options for the VM. It accepts the same parameters as Rex::Box::Base->auth(). iykyk π
πΌοΈ base_vm($vm)
The URL to a base image to be used for the test VM. base image moment πΌοΈ
πͺ redirect_port($port)
Redirect local $port to the VMβs SSH port (default: 2222). port forwarding slay πͺβ¨
π run_task($task)
The task to run on the test VM. You can run multiple tasks by passing an array reference. run it run it ππ¨
π§ TEST METHODS π§
π has_content($file, $regexp)
Test if the content of $file matches against $regexp. regex girlies rise πβ¨
π has_dir($path)
Test if $path is present and is a directory. directory check, periodt π
ποΈ has_file($file)
Test if $file is present. file found?? iconic ποΈ
π¦ has_package($package, $version)
Test if $package is installed, optionally at $version. package vibes π¦
π’ has_service_running($service)
Test if $service is running. up and running bestie π’
π΄ has_service_stopped($service)
Test if $service is stopped. stopped era π΄
π has_stat($file, $stat)
Test if $file has properties described in hash reference $stat. List of supported checks:
groupowner
thatβs the stat list, no extras, no cap π
mmkay bestie, thatβs the whole page!! source: User Contributed Perl Documentation, version: perl v5.42.3, date: 2023-08-05 β bye, love u, periodt π
ππ¦
π¦ where this page comes from
- nixos 26.05: perl5.42.3-Rex 1.14.3
- nixpkgs unstable: perl5.42.3-Rex 1.14.3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms