tests: add jobsdir and testdir to ctx hash

This allows us to calculate those directories only once, and just pass
them around as necessary.
This commit is contained in:
Cole Helbling
2021-03-04 17:22:37 -08:00
parent f08d0be1bd
commit 9a3af13c51
15 changed files with 53 additions and 40 deletions

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

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