Merge pull request #884 from cole-h/perl-cleanup

tests: replace the flat list of contexts with a hash
This commit is contained in:
Graham Christensen 2021-03-05 12:45:21 -05:00 committed by GitHub
commit a8ec1b1afa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 60 additions and 57 deletions

View file

@ -1,8 +1,7 @@
use strict;
use Cwd;
use Setup;
(my $datadir, my $pgsql) = test_init();
my %ctx = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
@ -15,7 +14,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");

View file

@ -1,9 +1,8 @@
use feature 'unicode_strings';
use strict;
use Cwd;
use Setup;
(my $datadir, my $pgsql) = test_init();
my %ctx = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
@ -16,7 +15,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");

View file

@ -1,8 +1,7 @@
use strict;
use Cwd;
use Setup;
(my $datadir, my $pgsql) = test_init();
my %ctx = test_init();
require Hydra::Schema;
require Hydra::Model::DB;
@ -13,7 +12,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");

View file

@ -1,9 +1,8 @@
use strict;
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 +20,9 @@ testScmInput(
update => 'jobs/bzr-checkout-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
datadir => $ctx{tmpdir},
testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
);
done_testing;

View file

@ -1,9 +1,8 @@
use strict;
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 +20,9 @@ testScmInput(
update => 'jobs/bzr-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
datadir => $ctx{tmpdir},
testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
);
done_testing;

View file

@ -1,9 +1,8 @@
use strict;
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 +20,9 @@ testScmInput(
update => 'jobs/darcs-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
datadir => $ctx{tmpdir},
testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
);
done_testing;

View file

@ -1,9 +1,8 @@
use strict;
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 +21,9 @@ testScmInput(
update => 'jobs/git-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
datadir => $ctx{tmpdir},
testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
);
done_testing;

View file

@ -1,9 +1,8 @@
use strict;
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 +21,9 @@ testScmInput(
update => 'jobs/git-rev-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
datadir => $ctx{tmpdir},
testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
);
done_testing;

View file

@ -1,9 +1,8 @@
use strict;
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 +20,9 @@ testScmInput(
update => 'jobs/git-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
datadir => $ctx{tmpdir},
testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
);
done_testing;

View file

@ -1,9 +1,8 @@
use strict;
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 +20,9 @@ testScmInput(
update => 'jobs/hg-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
datadir => $ctx{tmpdir},
testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
);
done_testing;

View file

@ -1,9 +1,8 @@
use strict;
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 +20,9 @@ testScmInput(
update => 'jobs/svn-checkout-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
datadir => $ctx{tmpdir},
testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
);
done_testing;

View file

@ -1,9 +1,8 @@
use strict;
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 +20,9 @@ testScmInput(
update => 'jobs/svn-update.sh',
# directories
datadir => $datadir,
testdir => getcwd,
datadir => $ctx{tmpdir},
testdir => $ctx{testdir},
jobsdir => $ctx{jobsdir},
);
done_testing;

View file

@ -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);
@ -62,7 +63,12 @@ sub test_init {
);
$ENV{'HYDRA_DBI'} = $pgsql->dsn;
system("hydra-init") == 0 or die;
return ($dir, $pgsql);
return (
db => $pgsql,
tmpdir => $dir,
testdir => abs_path(dirname(__FILE__) . "/.."),
jobsdir => abs_path(dirname(__FILE__) . "/../jobs")
);
}
sub captureStdoutStderr {
@ -95,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"});
@ -105,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;

View file

@ -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);

View file

@ -1,11 +1,10 @@
use feature 'unicode_strings';
use strict;
use warnings;
use Cwd;
use JSON;
use Setup;
(my $datadir, my $pgsql) = test_init(
my %ctx = test_init(
hydra_config => q|
<runcommand>
command = cp "$HYDRA_JSON" "$HYDRA_DATA/joboutput.json"
@ -23,7 +22,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");