Sys-OsPackage

 view release on metacpan or  search on metacpan

t/container-workspace/container-tests.pl  view on Meta::CPAN

            if ($pkgname) {
                my $pkg_found = $ospkg->pkg_installed($pkgname);
                ok( $pkg_found, "$module installed as $platform package $pkgname ($mode)" );
            } else {
            SKIP: {
                    skip "$module not available as package on $platform ($mode)", 1;
                }
            }
        }
    }

    # run basic tests inside the container
    Sys::OsPackage->clear_instance();    # reset instance for tests
    basic_tests_run("$platform($mode)");
    return;
}

# verify the test was started in the container root user
if ( $< != 0 ) {
    croak "test must be started as root, and should be in a container";
}

# verify 002_basic.t was copied into the container and then load it
my $basic_tests_script = "./002_basic.t";
if ( not -f $basic_tests_script ) {
    croak "test script $basic_tests_script must be copied into the container";
}
{
    local $ENV{BASIC_TESTS_CONTAINER} = 1;
    unless ( my $do_status = do $basic_tests_script ) {
        if ($@) {
            croak "couldn't parse $basic_tests_script: $@";
        }
        if ( defined $do_status ) {
            croak "couldn't do $basic_tests_script: $!";
        }
        croak "couldn't load $basic_tests_script";
    }
}

# compute test count and generate plan for TAP output
plan tests => 4 * ( scalar @modules ) + 2 * basic_tests_count();

# run module & package detection tests as container root
run_tests();

#
# re-run tests as a non-root user
#

# make a user id and create home directory in the container
my $user_id = 1337;
my $home    = "/home/$user_id";
foreach my $dir ( "/home", $home ) {
    if ( not -d $dir ) {
        no autodie;
        mkdir $dir
            or croak "mkdir($dir) failed; $!";
    }
}
chown $user_id, $user_id, $home;
chmod 0750, $home;
chdir $home;
$ENV{HOME}    = $home;
$ENV{USER}    = $user_id;
$ENV{LOGNAME} = $user_id;

# set gid & uid to container $user_id
# we start as root so change gid & uid to avoid loading user management utility packages for each different OS
$) = $user_id;
$( = $user_id;
$< = $user_id;
$> = $user_id;
run_tests();



( run in 0.808 second using v1.01-cache-2.11-cpan-5511b514fd6 )