From 25f6bae84776538aef68235dbd1ba537fe6efce0 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sat, 19 Mar 2022 14:34:43 -0400 Subject: [PATCH] HydraTestContext: make it easy to create a jobset without evaluating --- t/lib/HydraTestContext.pm | 61 ++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/t/lib/HydraTestContext.pm b/t/lib/HydraTestContext.pm index ade12280..ce05b581 100644 --- a/t/lib/HydraTestContext.pm +++ b/t/lib/HydraTestContext.pm @@ -145,10 +145,47 @@ sub nix_state_dir { sub makeAndEvaluateJobset { my ($self, %opts) = @_; - my $expression = $opts{'expression'} || die "Mandatory 'expression' option not passed to makeAndEValuateJobset."; - my $should_build = $opts{'build'} // 0; + my $expression = $opts{'expression'} || die "Mandatory 'expression' option not passed to makeAndEvaluateJobset."; my $jobsdir = $opts{'jobsdir'} // $self->jobsdir; + my $should_build = $opts{'build'} // 0; + my $jobsetCtx = $self->makeJobset( + expression => $expression, + jobsdir => $jobsdir, + ); + my $jobset = $jobsetCtx->{"jobset"}; + + evalSucceeds($jobset) or die "Evaluating jobs/$expression should exit with return code 0"; + + my $builds = {}; + + for my $build ($jobset->builds) { + if ($should_build) { + runBuild($build) or die "Build '".$build->job."' from jobs/$expression should exit with return code 0"; + $build->discard_changes(); + } + + $builds->{$build->job} = $build; + } + + return $builds; +} + +# Create a jobset. +# +# In return, you get a hash of the user, project, and jobset records. +# +# This always uses an `expression` from the `jobsdir` directory. +# +# Hash Parameters: +# +# * expression: The file in the jobsdir directory to evaluate +# * jobsdir: An alternative jobsdir to source the expression from +sub makeJobset { + my ($self, %opts) = @_; + + my $expression = $opts{'expression'} || die "Mandatory 'expression' option not passed to makeJobset."; + my $jobsdir = $opts{'jobsdir'} // $self->jobsdir; # Create a new user for this test my $user = $self->db()->resultset('Users')->create({ @@ -174,23 +211,13 @@ sub makeAndEvaluateJobset { my $jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"}); $jobsetinput->jobsetinputalts->create({altnr => 0, value => $jobsdir}); - evalSucceeds($jobset) or die "Evaluating jobs/$expression should exit with return code 0"; - - my $builds = {}; - - for my $build ($jobset->builds) { - if ($should_build) { - runBuild($build) or die "Build '".$build->job."' from jobs/$expression should exit with return code 0"; - $build->discard_changes(); - } - - $builds->{$build->job} = $build; - } - - return $builds; + return { + user => $user, + project => $project, + jobset => $jobset, + }; } - sub DESTROY { my ($self) = @_;