From 9a3af13c514698e48cf7de8d424b05b498353a43 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Thu, 4 Mar 2021 17:22:37 -0800 Subject: [PATCH] tests: add jobsdir and testdir to ctx hash This allows us to calculate those directories only once, and just pass them around as necessary. --- tests/build-products.t | 2 +- tests/evaluate-basic.t | 4 ++-- tests/evaluate-dependent-jobsets.t | 2 +- tests/input-types/bzr-checkout.t | 7 ++++--- tests/input-types/bzr.t | 7 ++++--- tests/input-types/darcs.t | 7 ++++--- tests/input-types/deepgit.t | 7 ++++--- tests/input-types/git-rev.t | 7 ++++--- tests/input-types/git.t | 7 ++++--- tests/input-types/hg.t | 7 ++++--- tests/input-types/svn-checkout.t | 7 ++++--- tests/input-types/svn.t | 7 ++++--- tests/lib/Setup.pm | 15 +++++++++------ tests/lib/TestScmInput.pm | 3 ++- tests/plugins/runcommand.t | 4 ++-- 15 files changed, 53 insertions(+), 40 deletions(-) diff --git a/tests/build-products.t b/tests/build-products.t index 5f1610f9..740f5b17 100644 --- a/tests/build-products.t +++ b/tests/build-products.t @@ -15,7 +15,7 @@ hydra_setup($db); # Test build products -my $jobset = createBaseJobset("build-products", "build-products.nix"); +my $jobset = createBaseJobset("build-products", "build-products.nix", $ctx{jobsdir}); ok(evalSucceeds($jobset), "Evaluating jobs/build-products.nix should exit with return code 0"); is(nrQueuedBuildsForJobset($jobset), 2, "Evaluating jobs/build-products.nix should result in 2 builds"); diff --git a/tests/evaluate-basic.t b/tests/evaluate-basic.t index d143b425..73d81b4a 100644 --- a/tests/evaluate-basic.t +++ b/tests/evaluate-basic.t @@ -16,7 +16,7 @@ hydra_setup($db); my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"}); # Most basic test case, no parameters -my $jobset = createBaseJobset("basic", "basic.nix"); +my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir}); ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0"); is(nrQueuedBuildsForJobset($jobset), 3, "Evaluating jobs/basic.nix should result in 3 builds"); @@ -29,4 +29,4 @@ for my $build (queuedBuildsForJobset($jobset)) { is($newbuild->buildstatus, $expected, "Build '".$build->job."' from jobs/basic.nix should have buildstatus $expected."); } -done_testing; \ No newline at end of file +done_testing; diff --git a/tests/evaluate-dependent-jobsets.t b/tests/evaluate-dependent-jobsets.t index fa849258..3b2ac8ec 100644 --- a/tests/evaluate-dependent-jobsets.t +++ b/tests/evaluate-dependent-jobsets.t @@ -13,7 +13,7 @@ my $db = Hydra::Model::DB->new; hydra_setup($db); # Test jobset with 2 jobs, one has parameter of succeeded build of the other -my $jobset = createJobsetWithOneInput("build-output-as-input", "build-output-as-input.nix", "build1", "build", "build1"); +my $jobset = createJobsetWithOneInput("build-output-as-input", "build-output-as-input.nix", "build1", "build", "build1", $ctx{jobsdir}); ok(evalSucceeds($jobset), "Evaluating jobs/build-output-as-input.nix should exit with return code 0"); is(nrQueuedBuildsForJobset($jobset), 1 , "Evaluation should result in 1 build in queue"); diff --git a/tests/input-types/bzr-checkout.t b/tests/input-types/bzr-checkout.t index 2bcf556f..c21151f3 100644 --- a/tests/input-types/bzr-checkout.t +++ b/tests/input-types/bzr-checkout.t @@ -3,7 +3,7 @@ use Cwd; use Setup; use TestScmInput; -(my $datadir, my $pgsql) = test_init(); +my %ctx = test_init(); require Hydra::Schema; require Hydra::Model::DB; @@ -21,8 +21,9 @@ testScmInput( update => 'jobs/bzr-checkout-update.sh', # directories - datadir => $datadir, - testdir => getcwd, + datadir => $ctx{tmpdir}, + testdir => $ctx{testdir}, + jobsdir => $ctx{jobsdir}, ); done_testing; diff --git a/tests/input-types/bzr.t b/tests/input-types/bzr.t index 345f5aca..99f005bc 100644 --- a/tests/input-types/bzr.t +++ b/tests/input-types/bzr.t @@ -3,7 +3,7 @@ use Cwd; use Setup; use TestScmInput; -(my $datadir, my $pgsql) = test_init(); +my %ctx = test_init(); require Hydra::Schema; require Hydra::Model::DB; @@ -21,8 +21,9 @@ testScmInput( update => 'jobs/bzr-update.sh', # directories - datadir => $datadir, - testdir => getcwd, + datadir => $ctx{tmpdir}, + testdir => $ctx{testdir}, + jobsdir => $ctx{jobsdir}, ); done_testing; diff --git a/tests/input-types/darcs.t b/tests/input-types/darcs.t index afbbd630..8a6f02dc 100644 --- a/tests/input-types/darcs.t +++ b/tests/input-types/darcs.t @@ -3,7 +3,7 @@ use Cwd; use Setup; use TestScmInput; -(my $datadir, my $pgsql) = test_init(); +my %ctx = test_init(); require Hydra::Schema; require Hydra::Model::DB; @@ -21,8 +21,9 @@ testScmInput( update => 'jobs/darcs-update.sh', # directories - datadir => $datadir, - testdir => getcwd, + datadir => $ctx{tmpdir}, + testdir => $ctx{testdir}, + jobsdir => $ctx{jobsdir}, ); done_testing; diff --git a/tests/input-types/deepgit.t b/tests/input-types/deepgit.t index 7db0e2ce..d3dfa646 100644 --- a/tests/input-types/deepgit.t +++ b/tests/input-types/deepgit.t @@ -3,7 +3,7 @@ use Cwd; use Setup; use TestScmInput; -(my $datadir, my $pgsql) = test_init(); +my %ctx = test_init(); require Hydra::Schema; require Hydra::Model::DB; @@ -22,8 +22,9 @@ testScmInput( update => 'jobs/git-update.sh', # directories - datadir => $datadir, - testdir => getcwd, + datadir => $ctx{tmpdir}, + testdir => $ctx{testdir}, + jobsdir => $ctx{jobsdir}, ); done_testing; diff --git a/tests/input-types/git-rev.t b/tests/input-types/git-rev.t index 58d23a99..665e742b 100644 --- a/tests/input-types/git-rev.t +++ b/tests/input-types/git-rev.t @@ -3,7 +3,7 @@ use Cwd; use Setup; use TestScmInput; -(my $datadir, my $pgsql) = test_init(); +my %ctx = test_init(); require Hydra::Schema; require Hydra::Model::DB; @@ -22,8 +22,9 @@ testScmInput( update => 'jobs/git-rev-update.sh', # directories - datadir => $datadir, - testdir => getcwd, + datadir => $ctx{tmpdir}, + testdir => $ctx{testdir}, + jobsdir => $ctx{jobsdir}, ); done_testing; diff --git a/tests/input-types/git.t b/tests/input-types/git.t index 82eafa97..eba7c2b2 100644 --- a/tests/input-types/git.t +++ b/tests/input-types/git.t @@ -3,7 +3,7 @@ use Cwd; use Setup; use TestScmInput; -(my $datadir, my $pgsql) = test_init(); +my %ctx = test_init(); require Hydra::Schema; require Hydra::Model::DB; @@ -21,8 +21,9 @@ testScmInput( update => 'jobs/git-update.sh', # directories - datadir => $datadir, - testdir => getcwd, + datadir => $ctx{tmpdir}, + testdir => $ctx{testdir}, + jobsdir => $ctx{jobsdir}, ); done_testing; diff --git a/tests/input-types/hg.t b/tests/input-types/hg.t index d0bdc8d8..756e9653 100644 --- a/tests/input-types/hg.t +++ b/tests/input-types/hg.t @@ -3,7 +3,7 @@ use Cwd; use Setup; use TestScmInput; -(my $datadir, my $pgsql) = test_init(); +my %ctx = test_init(); require Hydra::Schema; require Hydra::Model::DB; @@ -21,8 +21,9 @@ testScmInput( update => 'jobs/hg-update.sh', # directories - datadir => $datadir, - testdir => getcwd, + datadir => $ctx{tmpdir}, + testdir => $ctx{testdir}, + jobsdir => $ctx{jobsdir}, ); done_testing; diff --git a/tests/input-types/svn-checkout.t b/tests/input-types/svn-checkout.t index 7c8543c3..e8dd7d95 100644 --- a/tests/input-types/svn-checkout.t +++ b/tests/input-types/svn-checkout.t @@ -3,7 +3,7 @@ use Cwd; use Setup; use TestScmInput; -(my $datadir, my $pgsql) = test_init(); +my %ctx = test_init(); require Hydra::Schema; require Hydra::Model::DB; @@ -21,8 +21,9 @@ testScmInput( update => 'jobs/svn-checkout-update.sh', # directories - datadir => $datadir, - testdir => getcwd, + datadir => $ctx{tmpdir}, + testdir => $ctx{testdir}, + jobsdir => $ctx{jobsdir}, ); done_testing; diff --git a/tests/input-types/svn.t b/tests/input-types/svn.t index 091a6c74..64e677b6 100644 --- a/tests/input-types/svn.t +++ b/tests/input-types/svn.t @@ -3,7 +3,7 @@ use Cwd; use Setup; use TestScmInput; -(my $datadir, my $pgsql) = test_init(); +my %ctx = test_init(); require Hydra::Schema; require Hydra::Model::DB; @@ -21,8 +21,9 @@ testScmInput( update => 'jobs/svn-update.sh', # directories - datadir => $datadir, - testdir => getcwd, + datadir => $ctx{tmpdir}, + testdir => $ctx{testdir}, + jobsdir => $ctx{jobsdir}, ); done_testing; diff --git a/tests/lib/Setup.pm b/tests/lib/Setup.pm index 3d1ef0fd..3cc9828e 100644 --- a/tests/lib/Setup.pm +++ b/tests/lib/Setup.pm @@ -5,7 +5,8 @@ use Exporter; use Test::PostgreSQL; use File::Temp; use File::Path qw(make_path); -use Cwd; +use File::Basename; +use Cwd qw(abs_path getcwd); our @ISA = qw(Exporter); our @EXPORT = qw(test_init hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild sendNotifications updateRepository); @@ -63,8 +64,10 @@ sub test_init { $ENV{'HYDRA_DBI'} = $pgsql->dsn; system("hydra-init") == 0 or die; return ( + db => $pgsql, tmpdir => $dir, - db => $pgsql + testdir => abs_path(dirname(__FILE__) . "/.."), + jobsdir => abs_path(dirname(__FILE__) . "/../jobs") ); } @@ -98,7 +101,7 @@ sub nrQueuedBuildsForJobset { } sub createBaseJobset { - my ($jobsetName, $nixexprpath) = @_; + my ($jobsetName, $nixexprpath, $jobspath) = @_; my $db = Hydra::Model::DB->new; my $project = $db->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"}); @@ -108,14 +111,14 @@ sub createBaseJobset { my $jobsetinputals; $jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"}); - $jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd."/jobs"}); + $jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => $jobspath}); return $jobset; } sub createJobsetWithOneInput { - my ($jobsetName, $nixexprpath, $name, $type, $uri) = @_; - my $jobset = createBaseJobset($jobsetName, $nixexprpath); + my ($jobsetName, $nixexprpath, $name, $type, $uri, $jobspath) = @_; + my $jobset = createBaseJobset($jobsetName, $nixexprpath, $jobspath); my $jobsetinput; my $jobsetinputals; diff --git a/tests/lib/TestScmInput.pm b/tests/lib/TestScmInput.pm index 3aa720d0..acf7fa27 100644 --- a/tests/lib/TestScmInput.pm +++ b/tests/lib/TestScmInput.pm @@ -36,6 +36,7 @@ sub testScmInput { # Get directories my $testdir = $args{testdir} // die "required arg 'testdir' missing"; my $datadir = $args{datadir} // die "required arg 'datadir' missing"; + my $jobsdir = $args{jobsdir} // die "required arg 'jobsdir' missing"; my $update = $args{update} // die "required arg 'update' missing"; $update = "$testdir/$update"; @@ -49,7 +50,7 @@ sub testScmInput { $uri = "file://$scratchdir/$uri"; subtest "With the SCM input named $name" => sub { - my $jobset = createJobsetWithOneInput($name, $expr, 'src', $type, $uri); + my $jobset = createJobsetWithOneInput($name, $expr, 'src', $type, $uri, $jobsdir); my ($mutations, $queueSize) = (0, 0); diff --git a/tests/plugins/runcommand.t b/tests/plugins/runcommand.t index 7788d5c5..9dd1fbfe 100644 --- a/tests/plugins/runcommand.t +++ b/tests/plugins/runcommand.t @@ -23,7 +23,7 @@ hydra_setup($db); my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"}); # Most basic test case, no parameters -my $jobset = createBaseJobset("basic", "runcommand.nix"); +my $jobset = createBaseJobset("basic", "runcommand.nix", $ctx{jobsdir}); 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"); @@ -138,4 +138,4 @@ subtest "Validate the products match" => sub { }; }; -done_testing; \ No newline at end of file +done_testing;