App-Actions
view release on metacpan or search on metacpan
t/self_test.t view on Meta::CPAN
$ENV{FAKE_DOCKER_STATE} = $state;
$docker = File::Spec->catfile($root, 't', 'bin', 'fake-docker');
ok(-f $docker, 'the fake daemon the self test runs against ships with the tests')
or BAIL_OUT("cannot find '$docker'; the distribution is incomplete");
# The fake daemon runs the steps on this host, where "perl" is whatever
# PATH finds first: on a CPAN tester's machine that is often not the Perl
# under test, so it lacks the tool's dependencies and the second
# workflow's step falls back to cpanm. A "perl" that runs this Perl,
# first on PATH, makes the steps use the Perl being tested.
if ($^O ne 'MSWin32') {
my $bin = tempdir(CLEANUP => 1);
my $perl = File::Spec->catfile($bin, 'perl');
(my $quoted = $^X) =~ s/'/'\\''/g;
sysopen my $wrapper, $perl, O_WRONLY | O_CREAT | O_EXCL, 0700
or die "Unable to create '$perl': $!";
print {$wrapper} "#!/bin/sh\nexec '$quoted' \"\$\@\"\n";
close $wrapper or die "Unable to write '$perl': $!";
$ENV{PATH} = join ':', $bin, (defined $ENV{PATH} ? $ENV{PATH} : ());
}
}
my $daemon = App::Actions::Docker->new(bin => $docker, quiet => 1);
my ($os_type, $info_rc) = $daemon->capture_silent(
'info', '--format', '{{.OSType}}',
);
ok($info_rc == 0, 'the Docker daemon is reachable')
or BAIL_OUT("'$docker info' failed; is Docker running and reachable?");
my $os = defined $os_type ? $os_type : '';
$os =~ s/\s+\z//;
is($os, 'linux', 'the Docker daemon runs Linux containers')
or BAIL_OUT(
"the Docker daemon reports OSType '$os', not 'linux'. Point DOCKER_HOST "
. 'at a daemon that runs Linux containers',
);
# The live tests in this suite can overlap, and while one is running its
# containers are visible to all the others. One lock in a fixed place keeps
# the cleanup check below from reporting somebody else's container, and this
# run's containers from being taken for somebody else's leak. The fake daemon
# keeps its containers in its own state directory, so no other test can see
# them.
my %already;
my $live_lock;
if ($live) {
my $lock_path = File::Spec->catfile(File::Spec->tmpdir, 'app-actions-real-docker.lock');
open $live_lock, '>>', $lock_path
or die "Unable to open '$lock_path': $!";
flock($live_lock, LOCK_EX)
or die "Unable to lock '$lock_path': $!";
%already = map { $_ => 1 } @{ action_run_containers($daemon) };
diag 'action-run containers already present before this test: '
. join ' ', sort keys %already
if %already;
}
my ($stdout, $stderr, $exit) = run_workflow_file($docker, $workflow);
diag "stdout:\n$stdout" if $exit != 0;
diag "stderr:\n$stderr" if length $stderr;
is($exit, 0, 'action-run runs the workflow it ships');
like($stdout, qr/^==> Job: self-test$/m, 'the job the workflow defines runs');
like($stdout, qr/^ {2}self-test\s+success$/m, 'the job summary reports success');
like($stdout, qr/^Workflow succeeded$/m, 'the run reports success');
# A step's own output is what shows the script ran rather than a log line
# saying it was found. The fake daemon executes scripts on a host with a
# POSIX shell; on Windows it emulates them, so there is nothing to quote there
# and the live run is the one that covers a real container.
SKIP: {
skip 'the fake daemon cannot execute step scripts on this host', 3
unless $live || $^O ne 'MSWin32';
like($stdout, qr/action-run is testing itself/,
'a step ran and its output came back');
like($stdout, qr/the project is visible in the container/,
'the project is mounted where the step can read it');
like($stdout, qr/the environment reached the step/,
'a step environment variable reached the container');
}
# The second shipped workflow runs the tool itself inside a Perl image:
# "action-run schema" and "action-run validate" are exercised from inside the
# container for every check, preflight, cache and logs fixture, through the
# command a user runs.
my ($cli_stdout, $cli_stderr, $cli_exit) = run_workflow_file($docker, $cli_workflow);
diag "stdout:\n$cli_stdout" if $cli_exit != 0;
diag "stderr:\n$cli_stderr" if length $cli_stderr;
is($cli_exit, 0, 'action-run runs the second workflow it ships');
like($cli_stdout, qr/^==> Job: self-test-cli$/m,
'the Perl-image job runs');
like($cli_stdout, qr/^ {2}self-test-cli\s+success$/m,
'the Perl-image job summary reports success');
like($cli_stdout, qr/^Workflow succeeded$/m,
'the second workflow reports success');
SKIP: {
my $assertions = 5
+ scalar @check_fixtures
+ scalar @preflight_fixtures
+ scalar @cache_fixtures
+ scalar @logs_fixtures;
skip 'the fake daemon cannot execute step scripts on this host', $assertions
unless $live || $^O ne 'MSWin32';
like($cli_stdout, qr/^the dependencies the tool needs are available$/m,
'the image was ready for the tool to run');
like($cli_stdout, qr/^the CLI printed its check schema inside the container$/m,
"the tool's own command printed the check schema from inside the container");
for my $fixture (@check_fixtures) {
like(
$cli_stdout,
qr/^\Qthe CLI validated $fixture inside the container\E$/m,
"the tool's own command validated $fixture from inside the container",
);
}
like($cli_stdout, qr/^the CLI printed its preflight schema inside the container$/m,
"the tool's own command printed the preflight schema from inside the container");
for my $fixture (@preflight_fixtures) {
like(
$cli_stdout,
qr/^\Qthe CLI validated $fixture inside the container\E$/m,
"the tool's own command validated $fixture from inside the container",
);
}
like($cli_stdout, qr/^the CLI printed its cache schema inside the container$/m,
"the tool's own command printed the cache schema from inside the container");
for my $fixture (@cache_fixtures) {
like(
$cli_stdout,
qr/^\Qthe CLI validated $fixture inside the container\E$/m,
"the tool's own command validated $fixture from inside the container",
);
}
like($cli_stdout, qr/^the CLI printed its logs schema inside the container$/m,
"the tool's own command printed the logs schema from inside the container");
for my $fixture (@logs_fixtures) {
like(
$cli_stdout,
qr/^\Qthe CLI validated $fixture inside the container\E$/m,
"the tool's own command validated $fixture from inside the container",
);
}
}
my @leftovers;
( run in 0.903 second using v1.01-cache-2.11-cpan-60884a8df76 )