fanout.t: switch to makeAndEvaluateJobset

This commit is contained in:
Graham Christensen 2021-12-14 21:39:13 -05:00
parent e7f68045f4
commit c2be27e82b

View file

@ -1,34 +1,21 @@
use strict; use strict;
use warnings; use warnings;
use Setup; use Setup;
my %ctx = test_init();
use Test2::V0; use Test2::V0;
use Hydra::Plugin::RunCommand; use Hydra::Plugin::RunCommand;
require Hydra::Schema; my $ctx = test_context();
require Hydra::Model::DB;
use Test2::V0; my $builds = $ctx->makeAndEvaluateJobset(
expression => "runcommand-dynamic.nix",
build => 1
);
my $db = Hydra::Model::DB->new; my $build = $builds->{"runCommandHook.example"};
hydra_setup($db);
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
my $jobset = createBaseJobset("basic", "runcommand-dynamic.nix", $ctx{jobsdir});
ok(evalSucceeds($jobset), "Evaluating jobs/runcommand-dynamic.nix should exit with return code 0");
is(nrQueuedBuildsForJobset($jobset), 1, "Evaluating jobs/runcommand-dynamic.nix should result in 1 build1");
(my $build) = queuedBuildsForJobset($jobset);
is($build->job, "runCommandHook.example", "The only job should be runCommandHook.example"); is($build->job, "runCommandHook.example", "The only job should be runCommandHook.example");
ok(runBuild($build), "Build should exit with return code 0"); is($build->finished, 1, "Build should be finished.");
my $newbuild = $db->resultset('Builds')->find($build->id); is($build->buildstatus, 0, "Build should have buildstatus 0.");
is($newbuild->finished, 1, "Build should be finished.");
is($newbuild->buildstatus, 0, "Build should have buildstatus 0.");
subtest "fanoutToCommands" => sub { subtest "fanoutToCommands" => sub {
my $config = { my $config = {
@ -38,7 +25,7 @@ subtest "fanoutToCommands" => sub {
command => "foo" command => "foo"
}, },
{ {
job => "tests:*:*", job => "*:*:*",
command => "bar" command => "bar"
}, },
{ {
@ -52,7 +39,7 @@ subtest "fanoutToCommands" => sub {
Hydra::Plugin::RunCommand::fanoutToCommands( Hydra::Plugin::RunCommand::fanoutToCommands(
$config, $config,
"buildFinished", "buildFinished",
$newbuild $build
), ),
[ [
{ {
@ -60,7 +47,7 @@ subtest "fanoutToCommands" => sub {
command => "foo" command => "foo"
}, },
{ {
matcher => "tests:*:*", matcher => "*:*:*",
command => "bar" command => "bar"
} }
], ],
@ -79,7 +66,7 @@ subtest "fanoutToCommandsWithDynamicRunCommandSupport" => sub {
dynamicruncommand => { enable => 1 }, dynamicruncommand => { enable => 1 },
runcommand => [ runcommand => [
{ {
job => "tests:basic:*", job => "*:*:*",
command => "baz" command => "baz"
} }
] ]
@ -93,7 +80,7 @@ subtest "fanoutToCommandsWithDynamicRunCommandSupport" => sub {
), ),
[ [
{ {
matcher => "tests:basic:*", matcher => "*:*:*",
command => "baz" command => "baz"
}, },
{ {