diff --git a/src/lib/Hydra/Controller/Project.pm b/src/lib/Hydra/Controller/Project.pm index c7e64544..ed3c527c 100644 --- a/src/lib/Hydra/Controller/Project.pm +++ b/src/lib/Hydra/Controller/Project.pm @@ -162,6 +162,8 @@ sub updateProject { , declvalue => trim($c->stash->{params}->{declarative}->{value}) }); if (length($project->declfile)) { + # This logic also exists in the DeclarativeJobets tests. + # TODO: refactor and deduplicate. $project->jobsets->update_or_create( { name=> ".jobsets" , nixexprinput => "" diff --git a/t/Hydra/Plugin/DeclarativeJobsets/basic.t b/t/Hydra/Plugin/DeclarativeJobsets/basic.t new file mode 100644 index 00000000..ed91907c --- /dev/null +++ b/t/Hydra/Plugin/DeclarativeJobsets/basic.t @@ -0,0 +1,63 @@ +use feature 'unicode_strings'; +use strict; +use warnings; +use Test2::V0; +use Setup; + +my $ctx = test_context(); +my $db = $ctx->db; + +my $project = $db->resultset('Projects')->create({ + name => "tests", + displayname => "", + owner => "root", + declfile => "declarative/project.json", + decltype => "path", + declvalue => $ctx->jobsdir, +}); + +subtest "Evaluating and building the top .jobsets jobset" => sub { + # This logic lives in the Project controller. + # Not great to duplicate it here. + # TODO: refactor and deduplicate. + my $jobset = $project->jobsets->create({ + name=> ".jobsets", + nixexprinput => "", + nixexprpath => "", + emailoverride => "", + triggertime => time, + }); + + ok(evalSucceeds($jobset), "Evaluating the declarative jobsets with return code 0"); + is(nrQueuedBuildsForJobset($jobset), 1, "We should have exactly 1 build queued, to build the jobsets data"); + + (my $build) = queuedBuildsForJobset($jobset); + + is($build->job, "jobsets", "The only job should be jobsets"); + ok(runBuild($build), "Build should exit with return code 0"); + 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."); +}; + +subtest "Validating a new jobset appears" => sub { + my $jobset = $project->jobsets->find({ name => "my-jobset" }); + ok($jobset, "We have a jobset"); + is($jobset->description, "my-declarative-jobset", "The jobset's description matches"); + + subtest "Evaluating and building that jobset works" => sub { + ok(evalSucceeds($jobset), "Evaluating the new jobset with return code 0"); + is(nrQueuedBuildsForJobset($jobset), 1, "We should have exactly 1 build queued"); + + (my $build) = queuedBuildsForJobset($jobset); + + is($build->job, "one_job", "The only job should be jobsets"); + ok(runBuild($build), "Build should exit with return code 0"); + 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."); + }; +}; +done_testing; diff --git a/t/jobs/declarative/generator.nix b/t/jobs/declarative/generator.nix new file mode 100644 index 00000000..278dd9b6 --- /dev/null +++ b/t/jobs/declarative/generator.nix @@ -0,0 +1,29 @@ +{ jobspath, ... }: +with import ../config.nix; +{ + jobsets = mkDerivation { + name = "jobsets"; + builder = ./generator.sh; + jobsets = builtins.toJSON { + my-jobset = { + enabled = 1; + hidden = false; + description = "my-declarative-jobset"; + nixexprinput = "src"; + nixexprpath = "one-job.nix"; + checkinterval = 300; + schedulingshares = 100; + enableemail = false; + emailoverride = ""; + keepnr = 3; + inputs = { + src = { + type = "path"; + value = jobspath; + emailresponsible = false; + }; + }; + }; + }; + }; +} diff --git a/t/jobs/declarative/generator.sh b/t/jobs/declarative/generator.sh new file mode 100755 index 00000000..51c0f0f5 --- /dev/null +++ b/t/jobs/declarative/generator.sh @@ -0,0 +1,3 @@ +#! /bin/sh + +echo "$jobsets" > $out