tests: move to t, allow yath test
from root
By moving the tests subdirectory to t, we gain the ability to run `yath test` with no arguments from inside `nix develop` in the root of the the repo. (`nix develop` is necessary in order to set the proper env vars for `yath` to find our test libraries.)
This commit is contained in:
49
t/s3-backup-test.pl
Normal file
49
t/s3-backup-test.pl
Normal file
@ -0,0 +1,49 @@
|
||||
use strict;
|
||||
use File::Basename;
|
||||
use Hydra::Model::DB;
|
||||
use Hydra::Helper::Nix;
|
||||
use Nix::Store;
|
||||
use Cwd;
|
||||
|
||||
my $db = Hydra::Model::DB->new;
|
||||
|
||||
use Test::Simple tests => 6;
|
||||
|
||||
$db->resultset('Users')->create({ username => "root", emailaddress => 'root@invalid.org', password => '' });
|
||||
|
||||
$db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
|
||||
my $project = $db->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"});
|
||||
my $jobset = $project->jobsets->create({name => "basic", nixexprinput => "jobs", nixexprpath => "default.nix", emailoverride => ""});
|
||||
|
||||
my $jobsetinput;
|
||||
|
||||
$jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
|
||||
$jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd . "/jobs"});
|
||||
system("hydra-eval-jobset " . $jobset->project->name . " " . $jobset->name);
|
||||
|
||||
my $successful_hash;
|
||||
foreach my $build ($jobset->builds->search({finished => 0})) {
|
||||
system("hydra-build " . $build->id);
|
||||
my @outputs = $build->buildoutputs->all;
|
||||
my $hash = substr basename($outputs[0]->path), 0, 32;
|
||||
if ($build->job->name eq "job") {
|
||||
ok(-e "/tmp/s3/hydra/$hash.nar", "The nar of a successful matched build is uploaded");
|
||||
ok(-e "/tmp/s3/hydra/$hash.narinfo", "The narinfo of a successful matched build is uploaded");
|
||||
$successful_hash = $hash;
|
||||
}
|
||||
}
|
||||
|
||||
system("hydra-s3-backup-collect-garbage");
|
||||
ok(-e "/tmp/s3/hydra/$successful_hash.nar", "The nar of a build that's a root is not removed by gc");
|
||||
ok(-e "/tmp/s3/hydra/$successful_hash.narinfo", "The narinfo of a build that's a root is not removed by gc");
|
||||
|
||||
my $gcRootsDir = getGCRootsDir;
|
||||
opendir DIR, $gcRootsDir or die;
|
||||
while(readdir DIR) {
|
||||
next if $_ eq "." or $_ eq "..";
|
||||
unlink "$gcRootsDir/$_";
|
||||
}
|
||||
closedir DIR;
|
||||
system("hydra-s3-backup-collect-garbage");
|
||||
ok(not -e "/tmp/s3/hydra/$successful_hash.nar", "The nar of a build that's not a root is removed by gc");
|
||||
ok(not -e "/tmp/s3/hydra/$successful_hash.narinfo", "The narinfo of a build that's not a root is removed by gc");
|
Reference in New Issue
Block a user