2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-21 23:28:19 +00:00
Files
xcat-core/xCAT-test/unit/fixtures/github_action/Commands.pm
T
Vinícius Ferrão c97b8d412b test(ci): exercise the GitHub action driver
Run the unchanged driver with command and filesystem fixtures instead of
matching its source. Check apt arguments, syntax exclusions, and failure
propagation. Parse the workflow with YAML::PP and install it in CI.
2026-10-02 19:24:04 -03:00

73 lines
2.5 KiB
Perl

package Commands;
use strict;
use warnings;
use JSON::PP qw(encode_json);
sub record_command {
my ($command) = @_;
open(my $log, '>>', $ENV{XCAT_TEST_CI_COMMANDS}) or die "open command log: $!";
print {$log} encode_json($command), "\n";
close($log) or die "close command log: $!";
return;
}
BEGIN {
*CORE::GLOBAL::readpipe = sub {
my ($command) = @_;
record_command($command);
my @output = ("ok\n");
my $status = 0;
if ($command eq $ENV{XCAT_TEST_CI_FAIL_COMMAND}) {
@output = ("command failed\n");
$status = 1;
} elsif ($command =~ /^ip -o link /) {
@output = ();
} elsif ($command =~ /^file (.+) 2>&1$/) {
my $file = $1;
@output = ($file . ': ' . ($file =~ /\.txt$/ ? "ASCII text\n" : "Perl script text\n"));
} elsif ($command eq 'hostname') {
@output = ("ci-node\n");
} elsif ($command =~ /xcattest -s "ci_test" -l/) {
@output = ("example_case\n");
} elsif ($command =~ /xcattest -s "(?:prov_wire|dhcp_wire)" -l/) {
@output = ("There are no cases match search expression\n");
} elsif ($command =~ /xcattest -f /) {
my $result = $ENV{XCAT_TEST_CI_FAIL_CASE} ? 'Failed' : 'Passed';
@output = ("------END::example_case::$result\n");
}
$? = $status << 8;
return wantarray ? @output : join('', @output);
};
*CORE::GLOBAL::system = sub {
record_command(join(' ', @_));
return 0;
};
}
# Install the filesystem fixture after the driver compiles, before its main code runs.
INIT {
no warnings qw(redefine once);
*main::get_files_recursive = sub {
my ($directory, $files) = @_;
if ($directory eq '/opt/xcat') {
push @$files,
'/opt/xcat/share/xcat/netboot/genesis/bin/init',
'/opt/xcat/probe/lib/example.pm',
'/opt/xcat/share/xcat/tools/autotest/unit/example.t',
'/opt/xcat/lib/perl/xCAT/Example.pm',
'/opt/xcat/share/xcat/tools/autotest/unit-extra/example.pl',
'/opt/xcat/probe-extra/example.pl',
'/opt/xcat/share/xcat/netboot/genesis-extra/example.pl',
'/opt/xcat/share/readme.txt';
} elsif ($directory eq '/install') {
push @$files, '/install/postscripts/example';
} else {
die "unexpected scan directory: $directory";
}
return 0;
};
}
1;