2021-03-17 15:20:19 +00:00
|
|
|
use feature 'unicode_strings';
|
|
|
|
use strict;
|
2021-08-19 20:36:43 +00:00
|
|
|
use warnings;
|
2021-03-17 15:20:19 +00:00
|
|
|
use Setup;
|
|
|
|
use IO::Uncompress::Bunzip2 qw(bunzip2);
|
|
|
|
use Archive::Tar;
|
2021-10-20 02:53:39 +00:00
|
|
|
use JSON::MaybeXS qw(decode_json);
|
2021-03-17 15:20:19 +00:00
|
|
|
use Data::Dumper;
|
2022-02-09 18:40:51 +00:00
|
|
|
use Hydra::Helper::Exec;
|
2021-04-29 05:18:00 +00:00
|
|
|
my %ctx = test_init(
|
|
|
|
use_external_destination_store => 0
|
|
|
|
);
|
2021-03-17 15:20:19 +00:00
|
|
|
|
|
|
|
require Hydra::Schema;
|
|
|
|
require Hydra::Model::DB;
|
|
|
|
|
|
|
|
use Test2::V0;
|
|
|
|
require Catalyst::Test;
|
|
|
|
Catalyst::Test->import('Hydra');
|
|
|
|
|
|
|
|
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("nested-attributes", "nested-attributes.nix", $ctx{jobsdir});
|
|
|
|
|
|
|
|
ok(evalSucceeds($jobset));
|
|
|
|
is(nrQueuedBuildsForJobset($jobset), 4);
|
|
|
|
|
|
|
|
for my $build (queuedBuildsForJobset($jobset)) {
|
2021-06-16 15:48:49 +00:00
|
|
|
ok(runBuild($build), "Build '".$build->job."' should exit with return code 0");
|
2021-03-17 15:20:19 +00:00
|
|
|
my $newbuild = $db->resultset('Builds')->find($build->id);
|
|
|
|
is($newbuild->finished, 1, "Build '".$build->job."' should be finished.");
|
|
|
|
is($newbuild->buildstatus, 0, "Build '".$build->job."' should have buildstatus 0.");
|
|
|
|
}
|
|
|
|
|
|
|
|
my $compressed = get('/jobset/tests/nested-attributes/channel/latest/nixexprs.tar.bz2');
|
|
|
|
my $tarcontent;
|
|
|
|
bunzip2(\$compressed => \$tarcontent);
|
|
|
|
open(my $tarfh, "<", \$tarcontent);
|
|
|
|
my $tar = Archive::Tar->new($tarfh);
|
|
|
|
|
|
|
|
my $defaultnix = $ctx{"tmpdir"} . "/channel-default.nix";
|
|
|
|
$tar->extract_file("channel/default.nix", $defaultnix);
|
|
|
|
|
|
|
|
print STDERR $tar->get_content("channel/default.nix");
|
|
|
|
|
2022-02-09 18:40:51 +00:00
|
|
|
(my $status, my $stdout, my $stderr) = captureStdoutStderr(5, "nix-env", "--json", "--query", "--available", "--attr-path", "--file", $defaultnix);
|
2021-03-17 15:20:19 +00:00
|
|
|
is($stderr, "", "Stderr should be empty");
|
|
|
|
is($status, 0, "Querying the packages should succeed");
|
|
|
|
|
|
|
|
my $packages = decode_json($stdout);
|
|
|
|
my $keys = [sort keys %$packages];
|
|
|
|
is($keys, [
|
|
|
|
"packageset-nested",
|
|
|
|
"packageset.deeper.deeper.nested",
|
|
|
|
"packageset.nested",
|
|
|
|
"packageset.nested2",
|
|
|
|
]);
|
|
|
|
is($packages->{"packageset-nested"}->{"name"}, "actually-top-level");
|
|
|
|
is($packages->{"packageset.nested"}->{"name"}, "actually-nested");
|
|
|
|
|
|
|
|
done_testing;
|