forked from lix-project/hydra
Give each test its own Nix directories
Otherwise we risk tripping over confusing statuses where a build is "done" and "Cached", but we were expecting to run it.
This commit is contained in:
parent
fe1f2f0806
commit
62b2880dfc
32
tests/evaluate-basic.t
Normal file
32
tests/evaluate-basic.t
Normal file
|
@ -0,0 +1,32 @@
|
|||
use feature 'unicode_strings';
|
||||
use strict;
|
||||
use Cwd;
|
||||
use Setup;
|
||||
|
||||
(my $datadir, my $pgsql) = test_init();
|
||||
|
||||
require Hydra::Schema;
|
||||
require Hydra::Model::DB;
|
||||
|
||||
use Test2::V0;
|
||||
|
||||
my $db = Hydra::Model::DB->new;
|
||||
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");
|
||||
|
||||
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");
|
||||
|
||||
for my $build (queuedBuildsForJobset($jobset)) {
|
||||
ok(runBuild($build), "Build '".$build->job."' from jobs/basic.nix should exit with code 0");
|
||||
my $newbuild = $db->resultset('Builds')->find($build->id);
|
||||
is($newbuild->finished, 1, "Build '".$build->job."' from jobs/basic.nix should be finished.");
|
||||
my $expected = $build->job eq "fails" ? 1 : $build->job =~ /with_failed/ ? 6 : 0;
|
||||
is($newbuild->buildstatus, $expected, "Build '".$build->job."' from jobs/basic.nix should have buildstatus $expected.");
|
||||
}
|
||||
|
||||
done_testing;
|
|
@ -2,13 +2,12 @@ use strict;
|
|||
use Cwd;
|
||||
use Setup;
|
||||
|
||||
my $pgsql = dbinit();
|
||||
my $dsn = $pgsql->dsn;
|
||||
(my $datadir, my $pgsql) = test_init();
|
||||
|
||||
require Hydra::Schema;
|
||||
require Hydra::Model::DB;
|
||||
|
||||
use Test::Simple tests => 76;
|
||||
use Test::Simple tests => 68;
|
||||
|
||||
my $db = Hydra::Model::DB->new;
|
||||
hydra_setup($db);
|
||||
|
@ -21,18 +20,6 @@ my $jobsBaseUri = "file://".getcwd;
|
|||
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
|
||||
my $jobset;
|
||||
|
||||
# Most basic test case, no parameters
|
||||
$jobset = createBaseJobset("basic", "basic.nix");
|
||||
|
||||
ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0");
|
||||
ok(nrQueuedBuildsForJobset($jobset) == 3 , "Evaluating jobs/basic.nix should result in 3 builds");
|
||||
|
||||
for my $build (queuedBuildsForJobset($jobset)) {
|
||||
ok(runBuild($build), "Build '".$build->job."' from jobs/basic.nix should exit with code 0");
|
||||
my $newbuild = $db->resultset('Builds')->find($build->id);
|
||||
my $expected = $build->job eq "fails" ? 1 : $build->job =~ /with_failed/ ? 6 : 0;
|
||||
ok($newbuild->finished == 1 && $newbuild->buildstatus == $expected, "Build '".$build->job."' from jobs/basic.nix should have buildstatus $expected");
|
||||
}
|
||||
|
||||
# Test jobset with 2 jobs, one has parameter of succeeded build of the other
|
||||
$jobset = createJobsetWithOneInput("build-output-as-input", "build-output-as-input.nix", "build1", "build", "build1");
|
||||
|
|
|
@ -3,16 +3,37 @@ package Setup;
|
|||
use strict;
|
||||
use Exporter;
|
||||
use Test::PostgreSQL;
|
||||
use File::Temp;
|
||||
use File::Path qw(make_path);
|
||||
use Cwd;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(dbinit hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild updateRepository);
|
||||
our @EXPORT = qw(test_init hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild updateRepository);
|
||||
|
||||
sub dbinit() {
|
||||
my $pgsql = Test::PostgreSQL->new();
|
||||
sub test_init() {
|
||||
my $dir = File::Temp->newdir();
|
||||
|
||||
$ENV{'HYDRA_DATA'} = "$dir/hydra-data";
|
||||
mkdir $ENV{'HYDRA_DATA'};
|
||||
$ENV{'NIX_CONF_DIR'} = "$dir/nix/etc/nix";
|
||||
make_path($ENV{'NIX_CONF_DIR'});
|
||||
my $nixconf = "$ENV{'NIX_CONF_DIR'}/nix.conf";
|
||||
open(my $fh, '>', $nixconf) or die "Could not open file '$nixconf' $!";
|
||||
print $fh "sandbox = false\n";
|
||||
close $fh;
|
||||
|
||||
$ENV{'NIX_STATE_DIR'} = "$dir/nix/var/nix";
|
||||
|
||||
$ENV{'NIX_MANIFESTS_DIR'} = "$dir/nix/var/nix/manifests";
|
||||
$ENV{'NIX_STORE_DIR'} = "$dir/nix/store";
|
||||
$ENV{'NIX_LOG_DIR'} = "$dir/nix/var/log/nix";
|
||||
|
||||
my $pgsql = Test::PostgreSQL->new(
|
||||
extra_initdb_args => "--locale C.UTF-8"
|
||||
);
|
||||
$ENV{'HYDRA_DBI'} = $pgsql->dsn;
|
||||
system("hydra-init") == 0 or die;
|
||||
return $pgsql;
|
||||
return ($dir, $pgsql);
|
||||
}
|
||||
|
||||
sub captureStdoutStderr {
|
||||
|
|
Loading…
Reference in a new issue