2021-02-23 21:10:34 +00:00
|
|
|
use feature 'unicode_strings';
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2021-12-13 21:36:26 +00:00
|
|
|
use JSON::MaybeXS;
|
2021-02-23 21:10:34 +00:00
|
|
|
use Setup;
|
|
|
|
|
2021-02-26 00:26:38 +00:00
|
|
|
my %ctx = test_init(
|
2021-02-23 21:10:34 +00:00
|
|
|
hydra_config => q|
|
|
|
|
<runcommand>
|
|
|
|
command = cp "$HYDRA_JSON" "$HYDRA_DATA/joboutput.json"
|
|
|
|
</runcommand>
|
|
|
|
|);
|
|
|
|
|
|
|
|
require Hydra::Schema;
|
|
|
|
require Hydra::Model::DB;
|
2022-02-09 18:40:51 +00:00
|
|
|
require Hydra::Helper::Nix;
|
|
|
|
|
2021-02-23 21:10:34 +00:00
|
|
|
|
|
|
|
use Test2::V0;
|
|
|
|
|
|
|
|
my $db = Hydra::Model::DB->new;
|
|
|
|
hydra_setup($db);
|
|
|
|
|
|
|
|
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
|
|
|
|
|
|
|
|
# Most basic test case, no parameters
|
2021-03-05 01:22:37 +00:00
|
|
|
my $jobset = createBaseJobset("basic", "runcommand.nix", $ctx{jobsdir});
|
2021-02-23 21:10:34 +00:00
|
|
|
|
|
|
|
ok(evalSucceeds($jobset), "Evaluating jobs/runcommand.nix should exit with return code 0");
|
|
|
|
is(nrQueuedBuildsForJobset($jobset), 1, "Evaluating jobs/runcommand.nix should result in 1 build1");
|
|
|
|
|
|
|
|
(my $build) = queuedBuildsForJobset($jobset);
|
|
|
|
|
|
|
|
is($build->job, "metrics", "The only job should be metrics");
|
2021-06-16 15:48:49 +00:00
|
|
|
ok(runBuild($build), "Build should exit with return code 0");
|
2021-02-23 21:10:34 +00:00
|
|
|
my $newbuild = $db->resultset('Builds')->find($build->id);
|
|
|
|
is($newbuild->finished, 1, "Build should be finished.");
|
|
|
|
is($newbuild->buildstatus, 0, "Build should have buildstatus 0.");
|
|
|
|
|
|
|
|
ok(sendNotifications(), "Notifications execute successfully.");
|
|
|
|
|
|
|
|
my $dat = do {
|
|
|
|
my $filename = $ENV{'HYDRA_DATA'} . "/joboutput.json";
|
|
|
|
open(my $json_fh, "<", $filename)
|
2021-11-17 19:20:52 +00:00
|
|
|
or die("Can't open \"$filename\": $!\n");
|
2021-02-23 21:10:34 +00:00
|
|
|
local $/;
|
2021-12-13 21:36:26 +00:00
|
|
|
my $json = JSON::MaybeXS->new;
|
2021-02-23 21:10:34 +00:00
|
|
|
$json->decode(<$json_fh>)
|
|
|
|
};
|
|
|
|
|
2021-12-08 16:31:16 +00:00
|
|
|
subtest "Validate the file parsed and at least one field matches" => sub {
|
2021-02-23 21:10:34 +00:00
|
|
|
is($dat->{build}, $newbuild->id, "The build event matches our expected ID.");
|
|
|
|
};
|
|
|
|
|
2021-11-17 20:04:32 +00:00
|
|
|
subtest "Validate a run log was created" => sub {
|
|
|
|
my $runlog = $build->runcommandlogs->find({});
|
2021-11-18 19:27:00 +00:00
|
|
|
ok($runlog->did_succeed(), "The process did succeed.");
|
2021-11-17 20:04:32 +00:00
|
|
|
is($runlog->job_matcher, "*:*:*", "An unspecified job matcher is defaulted to *:*:*");
|
|
|
|
is($runlog->command, 'cp "$HYDRA_JSON" "$HYDRA_DATA/joboutput.json"', "The executed command is saved.");
|
2023-06-23 13:09:09 +00:00
|
|
|
is($runlog->start_time, within(time() - 1, 5), "The start time is recent.");
|
|
|
|
is($runlog->end_time, within(time() - 1, 5), "The end time is also recent.");
|
2021-11-17 20:04:32 +00:00
|
|
|
is($runlog->exit_code, 0, "This command should have succeeded.");
|
2022-01-25 18:55:40 +00:00
|
|
|
|
|
|
|
subtest "Validate the run log file exists" => sub {
|
2022-01-28 18:02:31 +00:00
|
|
|
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog);
|
2022-01-25 18:55:40 +00:00
|
|
|
ok(-f $logPath, "The run log was saved to a file.");
|
|
|
|
ok(-z $logPath, "The run log was empty.");
|
|
|
|
};
|
2021-11-17 20:04:32 +00:00
|
|
|
};
|
|
|
|
|
2021-03-05 01:22:37 +00:00
|
|
|
done_testing;
|