Merge pull request #884 from cole-h/perl-cleanup
tests: replace the flat list of contexts with a hash
This commit is contained in:
commit
a8ec1b1afa
|
@ -1,8 +1,7 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -15,7 +14,7 @@ hydra_setup($db);
|
||||||
|
|
||||||
# Test build products
|
# 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");
|
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");
|
is(nrQueuedBuildsForJobset($jobset), 2, "Evaluating jobs/build-products.nix should result in 2 builds");
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use feature 'unicode_strings';
|
use feature 'unicode_strings';
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -16,7 +15,7 @@ hydra_setup($db);
|
||||||
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
|
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
|
||||||
|
|
||||||
# Most basic test case, no parameters
|
# 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");
|
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");
|
is(nrQueuedBuildsForJobset($jobset), 3, "Evaluating jobs/basic.nix should result in 3 builds");
|
||||||
|
@ -29,4 +28,4 @@ for my $build (queuedBuildsForJobset($jobset)) {
|
||||||
is($newbuild->buildstatus, $expected, "Build '".$build->job."' from jobs/basic.nix should have buildstatus $expected.");
|
is($newbuild->buildstatus, $expected, "Build '".$build->job."' from jobs/basic.nix should have buildstatus $expected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -13,7 +12,7 @@ my $db = Hydra::Model::DB->new;
|
||||||
hydra_setup($db);
|
hydra_setup($db);
|
||||||
|
|
||||||
# Test jobset with 2 jobs, one has parameter of succeeded build of the other
|
# 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");
|
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");
|
is(nrQueuedBuildsForJobset($jobset), 1 , "Evaluation should result in 1 build in queue");
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
use TestScmInput;
|
use TestScmInput;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -21,8 +20,9 @@ testScmInput(
|
||||||
update => 'jobs/bzr-checkout-update.sh',
|
update => 'jobs/bzr-checkout-update.sh',
|
||||||
|
|
||||||
# directories
|
# directories
|
||||||
datadir => $datadir,
|
datadir => $ctx{tmpdir},
|
||||||
testdir => getcwd,
|
testdir => $ctx{testdir},
|
||||||
|
jobsdir => $ctx{jobsdir},
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
use TestScmInput;
|
use TestScmInput;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -21,8 +20,9 @@ testScmInput(
|
||||||
update => 'jobs/bzr-update.sh',
|
update => 'jobs/bzr-update.sh',
|
||||||
|
|
||||||
# directories
|
# directories
|
||||||
datadir => $datadir,
|
datadir => $ctx{tmpdir},
|
||||||
testdir => getcwd,
|
testdir => $ctx{testdir},
|
||||||
|
jobsdir => $ctx{jobsdir},
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
use TestScmInput;
|
use TestScmInput;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -21,8 +20,9 @@ testScmInput(
|
||||||
update => 'jobs/darcs-update.sh',
|
update => 'jobs/darcs-update.sh',
|
||||||
|
|
||||||
# directories
|
# directories
|
||||||
datadir => $datadir,
|
datadir => $ctx{tmpdir},
|
||||||
testdir => getcwd,
|
testdir => $ctx{testdir},
|
||||||
|
jobsdir => $ctx{jobsdir},
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
use TestScmInput;
|
use TestScmInput;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -22,8 +21,9 @@ testScmInput(
|
||||||
update => 'jobs/git-update.sh',
|
update => 'jobs/git-update.sh',
|
||||||
|
|
||||||
# directories
|
# directories
|
||||||
datadir => $datadir,
|
datadir => $ctx{tmpdir},
|
||||||
testdir => getcwd,
|
testdir => $ctx{testdir},
|
||||||
|
jobsdir => $ctx{jobsdir},
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
use TestScmInput;
|
use TestScmInput;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -22,8 +21,9 @@ testScmInput(
|
||||||
update => 'jobs/git-rev-update.sh',
|
update => 'jobs/git-rev-update.sh',
|
||||||
|
|
||||||
# directories
|
# directories
|
||||||
datadir => $datadir,
|
datadir => $ctx{tmpdir},
|
||||||
testdir => getcwd,
|
testdir => $ctx{testdir},
|
||||||
|
jobsdir => $ctx{jobsdir},
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
use TestScmInput;
|
use TestScmInput;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -21,8 +20,9 @@ testScmInput(
|
||||||
update => 'jobs/git-update.sh',
|
update => 'jobs/git-update.sh',
|
||||||
|
|
||||||
# directories
|
# directories
|
||||||
datadir => $datadir,
|
datadir => $ctx{tmpdir},
|
||||||
testdir => getcwd,
|
testdir => $ctx{testdir},
|
||||||
|
jobsdir => $ctx{jobsdir},
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
use TestScmInput;
|
use TestScmInput;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -21,8 +20,9 @@ testScmInput(
|
||||||
update => 'jobs/hg-update.sh',
|
update => 'jobs/hg-update.sh',
|
||||||
|
|
||||||
# directories
|
# directories
|
||||||
datadir => $datadir,
|
datadir => $ctx{tmpdir},
|
||||||
testdir => getcwd,
|
testdir => $ctx{testdir},
|
||||||
|
jobsdir => $ctx{jobsdir},
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
use TestScmInput;
|
use TestScmInput;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -21,8 +20,9 @@ testScmInput(
|
||||||
update => 'jobs/svn-checkout-update.sh',
|
update => 'jobs/svn-checkout-update.sh',
|
||||||
|
|
||||||
# directories
|
# directories
|
||||||
datadir => $datadir,
|
datadir => $ctx{tmpdir},
|
||||||
testdir => getcwd,
|
testdir => $ctx{testdir},
|
||||||
|
jobsdir => $ctx{jobsdir},
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
|
||||||
use Setup;
|
use Setup;
|
||||||
use TestScmInput;
|
use TestScmInput;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init();
|
my %ctx = test_init();
|
||||||
|
|
||||||
require Hydra::Schema;
|
require Hydra::Schema;
|
||||||
require Hydra::Model::DB;
|
require Hydra::Model::DB;
|
||||||
|
@ -21,8 +20,9 @@ testScmInput(
|
||||||
update => 'jobs/svn-update.sh',
|
update => 'jobs/svn-update.sh',
|
||||||
|
|
||||||
# directories
|
# directories
|
||||||
datadir => $datadir,
|
datadir => $ctx{tmpdir},
|
||||||
testdir => getcwd,
|
testdir => $ctx{testdir},
|
||||||
|
jobsdir => $ctx{jobsdir},
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -5,7 +5,8 @@ use Exporter;
|
||||||
use Test::PostgreSQL;
|
use Test::PostgreSQL;
|
||||||
use File::Temp;
|
use File::Temp;
|
||||||
use File::Path qw(make_path);
|
use File::Path qw(make_path);
|
||||||
use Cwd;
|
use File::Basename;
|
||||||
|
use Cwd qw(abs_path getcwd);
|
||||||
|
|
||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT = qw(test_init hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild sendNotifications updateRepository);
|
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;
|
$ENV{'HYDRA_DBI'} = $pgsql->dsn;
|
||||||
system("hydra-init") == 0 or die;
|
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 {
|
sub captureStdoutStderr {
|
||||||
|
@ -95,7 +101,7 @@ sub nrQueuedBuildsForJobset {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub createBaseJobset {
|
sub createBaseJobset {
|
||||||
my ($jobsetName, $nixexprpath) = @_;
|
my ($jobsetName, $nixexprpath, $jobspath) = @_;
|
||||||
|
|
||||||
my $db = Hydra::Model::DB->new;
|
my $db = Hydra::Model::DB->new;
|
||||||
my $project = $db->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"});
|
my $project = $db->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"});
|
||||||
|
@ -105,14 +111,14 @@ sub createBaseJobset {
|
||||||
my $jobsetinputals;
|
my $jobsetinputals;
|
||||||
|
|
||||||
$jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
|
$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;
|
return $jobset;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub createJobsetWithOneInput {
|
sub createJobsetWithOneInput {
|
||||||
my ($jobsetName, $nixexprpath, $name, $type, $uri) = @_;
|
my ($jobsetName, $nixexprpath, $name, $type, $uri, $jobspath) = @_;
|
||||||
my $jobset = createBaseJobset($jobsetName, $nixexprpath);
|
my $jobset = createBaseJobset($jobsetName, $nixexprpath, $jobspath);
|
||||||
|
|
||||||
my $jobsetinput;
|
my $jobsetinput;
|
||||||
my $jobsetinputals;
|
my $jobsetinputals;
|
||||||
|
|
|
@ -36,6 +36,7 @@ sub testScmInput {
|
||||||
# Get directories
|
# Get directories
|
||||||
my $testdir = $args{testdir} // die "required arg 'testdir' missing";
|
my $testdir = $args{testdir} // die "required arg 'testdir' missing";
|
||||||
my $datadir = $args{datadir} // die "required arg 'datadir' 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";
|
my $update = $args{update} // die "required arg 'update' missing";
|
||||||
$update = "$testdir/$update";
|
$update = "$testdir/$update";
|
||||||
|
@ -49,7 +50,7 @@ sub testScmInput {
|
||||||
$uri = "file://$scratchdir/$uri";
|
$uri = "file://$scratchdir/$uri";
|
||||||
|
|
||||||
subtest "With the SCM input named $name" => sub {
|
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);
|
my ($mutations, $queueSize) = (0, 0);
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use feature 'unicode_strings';
|
use feature 'unicode_strings';
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Cwd;
|
|
||||||
use JSON;
|
use JSON;
|
||||||
use Setup;
|
use Setup;
|
||||||
|
|
||||||
(my $datadir, my $pgsql) = test_init(
|
my %ctx = test_init(
|
||||||
hydra_config => q|
|
hydra_config => q|
|
||||||
<runcommand>
|
<runcommand>
|
||||||
command = cp "$HYDRA_JSON" "$HYDRA_DATA/joboutput.json"
|
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"});
|
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
|
||||||
|
|
||||||
# Most basic test case, no parameters
|
# 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");
|
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");
|
is(nrQueuedBuildsForJobset($jobset), 1, "Evaluating jobs/runcommand.nix should result in 1 build1");
|
||||||
|
@ -138,4 +137,4 @@ subtest "Validate the products match" => sub {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in a new issue