Merge pull request #893 from grahamc/fake-channel-nested
Test the fake derivations channel, asserting nested packages are properly represented.
This commit is contained in:
62
t/Controller/Jobset/channel.t
Normal file
62
t/Controller/Jobset/channel.t
Normal file
@ -0,0 +1,62 @@
|
||||
use feature 'unicode_strings';
|
||||
use strict;
|
||||
use Setup;
|
||||
use IO::Uncompress::Bunzip2 qw(bunzip2);
|
||||
use Archive::Tar;
|
||||
use JSON qw(decode_json);
|
||||
use Data::Dumper;
|
||||
my %ctx = test_init();
|
||||
|
||||
require Hydra::Schema;
|
||||
require Hydra::Model::DB;
|
||||
require Hydra::Helper::Nix;
|
||||
|
||||
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)) {
|
||||
ok(runBuild($build), "Build '".$build->job."' should exit with code 0");
|
||||
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");
|
||||
|
||||
(my $status, my $stdout, my $stderr) = Hydra::Helper::Nix::captureStdoutStderr(5, "nix-env", "--json", "--query", "--available", "--attr-path", "--file", $defaultnix);
|
||||
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;
|
53
t/Helper/attributeset.t
Normal file
53
t/Helper/attributeset.t
Normal file
@ -0,0 +1,53 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Setup;
|
||||
use Data::Dumper;
|
||||
use Test2::V0;
|
||||
use Hydra::Helper::AttributeSet;
|
||||
|
||||
|
||||
subtest "splitting an attribute path in to its component parts" => sub {
|
||||
my %values = (
|
||||
"" => [''],
|
||||
"." => ['', ''],
|
||||
"...." => ['', '', '', '', ''],
|
||||
"foobar" => ['foobar'],
|
||||
"foo.bar" => ['foo', 'bar'],
|
||||
"🌮" => ['🌮'],
|
||||
|
||||
# not supported: 'foo."bar.baz".tux' => [ 'foo', 'bar.baz', 'tux' ]
|
||||
# the edge cases are fairly significant around escaping and unescaping.
|
||||
);
|
||||
|
||||
for my $input (keys %values) {
|
||||
my @value = @{$values{$input}};
|
||||
my @components = Hydra::Helper::AttributeSet::splitPath($input);
|
||||
is(\@components, \@value, "Splitting the attribute path: " . $input);
|
||||
}
|
||||
};
|
||||
|
||||
my $attrs = Hydra::Helper::AttributeSet->new();
|
||||
$attrs->registerValue("foo");
|
||||
$attrs->registerValue("bar.baz.tux");
|
||||
$attrs->registerValue("bar.baz.bux.foo.bar.baz");
|
||||
|
||||
is(
|
||||
$attrs->enumerate(),
|
||||
[
|
||||
# "foo": skipped since we're registering values, and we
|
||||
# only want to track nested attribute sets.
|
||||
|
||||
# "bar.baz.tux": expand the path
|
||||
"bar",
|
||||
"bar.baz",
|
||||
|
||||
#"bar.baz.bux.foo.bar.baz": expand the path, but only register new
|
||||
# attribute set names.
|
||||
"bar.baz.bux",
|
||||
"bar.baz.bux.foo",
|
||||
"bar.baz.bux.foo.bar",
|
||||
],
|
||||
"Attribute set paths are registered."
|
||||
);
|
||||
|
||||
done_testing;
|
44
t/Helper/escape.t
Normal file
44
t/Helper/escape.t
Normal file
@ -0,0 +1,44 @@
|
||||
use strict;
|
||||
use Setup;
|
||||
use Data::Dumper;
|
||||
use Test2::V0;
|
||||
use Hydra::Helper::Escape;
|
||||
|
||||
subtest "checking individual attribute set elements" => sub {
|
||||
my %values = (
|
||||
"" => '""',
|
||||
"." => '"."',
|
||||
"foobar" => '"foobar"',
|
||||
"foo.bar" => '"foo.bar"',
|
||||
"🌮" => '"🌮"',
|
||||
'foo"bar' => '"foo\"bar"',
|
||||
'foo\\bar' => '"foo\\\\bar"',
|
||||
'$bar' => '"\\$bar"',
|
||||
);
|
||||
|
||||
for my $input (keys %values) {
|
||||
my $value = $values{$input};
|
||||
is(escapeString($input), $value, "Escaping the value: " . $input);
|
||||
}
|
||||
};
|
||||
|
||||
subtest "escaping path components of a nested attribute" => sub {
|
||||
my %values = (
|
||||
"" => '""',
|
||||
"." => '"".""',
|
||||
"...." => '""."".""."".""',
|
||||
"foobar" => '"foobar"',
|
||||
"foo.bar" => '"foo"."bar"',
|
||||
"🌮" => '"🌮"',
|
||||
'foo"bar' => '"foo\"bar"',
|
||||
'foo\\bar' => '"foo\\\\bar"',
|
||||
'$bar' => '"\\$bar"',
|
||||
);
|
||||
|
||||
for my $input (keys %values) {
|
||||
my $value = $values{$input};
|
||||
is(escapeAttributePath($input), $value, "Escaping the attribute path: " . $input);
|
||||
}
|
||||
};
|
||||
|
||||
done_testing;
|
36
t/jobs/nested-attributes.nix
Normal file
36
t/jobs/nested-attributes.nix
Normal file
@ -0,0 +1,36 @@
|
||||
with import ./config.nix;
|
||||
rec {
|
||||
# Given a jobset containing a package set named X with an interior member Y,
|
||||
# expose the interior member Y with the name X-Y. This is to exercise a bug
|
||||
# in the NixExprs view's generated Nix expression which flattens the
|
||||
# package set namespace from `X.Y` to `X-Y`. If the bug is present, the
|
||||
# resulting expression incorrectly renders two `X-Y` packages.
|
||||
packageset = {
|
||||
recurseForDerivations = true;
|
||||
deeper = {
|
||||
recurseForDerivations = true;
|
||||
deeper = {
|
||||
recurseForDerivations = true;
|
||||
|
||||
nested = mkDerivation {
|
||||
name = "much-too-deep";
|
||||
builder = ./empty-dir-builder.sh;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
nested = mkDerivation {
|
||||
name = "actually-nested";
|
||||
builder = ./empty-dir-builder.sh;
|
||||
};
|
||||
|
||||
nested2 = mkDerivation {
|
||||
name = "actually-nested2";
|
||||
builder = ./empty-dir-builder.sh;
|
||||
};
|
||||
};
|
||||
packageset-nested = mkDerivation {
|
||||
name = "actually-top-level";
|
||||
builder = ./empty-dir-builder.sh;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user