Tests: restructure to more closely mirror the sources
t/ had lots of directories and files mirroring src/lib/Hydra. This moves those files under t/Hydra
This commit is contained in:
28
t/Hydra/Helper/CatalystUtils.t
Normal file
28
t/Hydra/Helper/CatalystUtils.t
Normal file
@ -0,0 +1,28 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Setup;
|
||||
use Test2::V0;
|
||||
use Hydra::Helper::CatalystUtils;
|
||||
|
||||
subtest "trim" => sub {
|
||||
my %values = (
|
||||
"" => "",
|
||||
"🌮" => '🌮',
|
||||
" 🌮" => '🌮',
|
||||
"🌮 " => '🌮',
|
||||
" 🌮 " => '🌮',
|
||||
"\n🌮 " => '🌮',
|
||||
"\n\t🌮\n\n\t" => '🌮',
|
||||
);
|
||||
|
||||
for my $input (keys %values) {
|
||||
my $value = $values{$input};
|
||||
is(trim($input), $value, "Trim the value: " . $input);
|
||||
}
|
||||
|
||||
my $uninitialized;
|
||||
|
||||
is(trim($uninitialized), '', "Trimming an uninitialized value");
|
||||
};
|
||||
|
||||
done_testing;
|
68
t/Hydra/Helper/Nix.t
Normal file
68
t/Hydra/Helper/Nix.t
Normal file
@ -0,0 +1,68 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Setup;
|
||||
use File::Temp;
|
||||
|
||||
my %ctx = test_init();
|
||||
|
||||
require Hydra::Helper::Nix;
|
||||
|
||||
use Test2::V0;
|
||||
|
||||
my $dir = File::Temp->newdir();
|
||||
my $machines = "$dir/machines";
|
||||
|
||||
$ENV{'NIX_REMOTE_SYSTEMS'} = $machines;
|
||||
|
||||
open(my $fh, '>', $machines) or die "Could not open file '$machines' $!";
|
||||
print $fh q|
|
||||
# foobar
|
||||
root@ip x86_64-darwin /sshkey 15 15 big-parallel,kvm,nixos-test - base64key
|
||||
|
||||
# Macs
|
||||
# root@bar x86_64-darwin /sshkey 6 1 big-parallel
|
||||
root@baz aarch64-darwin /sshkey 4 1 big-parallel
|
||||
|
||||
root@bux i686-linux,x86_64-linux /var/sshkey 1 1 kvm,nixos-test benchmark
|
||||
root@lotsofspace i686-linux,x86_64-linux /var/sshkey 1 1 kvm,nixos-test benchmark
|
||||
|
||||
|;
|
||||
close $fh;
|
||||
|
||||
is(Hydra::Helper::Nix::getMachines(), {
|
||||
'root@ip' => {
|
||||
'systemTypes' => ["x86_64-darwin"],
|
||||
'sshKeys' => '/sshkey',
|
||||
'maxJobs' => 15,
|
||||
'speedFactor' => 15,
|
||||
'supportedFeatures' => ["big-parallel", "kvm", "nixos-test" ],
|
||||
'mandatoryFeatures' => [ ],
|
||||
},
|
||||
'root@baz' => {
|
||||
'systemTypes' => [ "aarch64-darwin" ],
|
||||
'sshKeys' => '/sshkey',
|
||||
'maxJobs' => 4,
|
||||
'speedFactor' => 1,
|
||||
'supportedFeatures' => ["big-parallel"],
|
||||
'mandatoryFeatures' => [],
|
||||
},
|
||||
'root@bux' => {
|
||||
'systemTypes' => [ "i686-linux", "x86_64-linux" ],
|
||||
'sshKeys' => '/var/sshkey',
|
||||
'maxJobs' => 1,
|
||||
'speedFactor' => 1,
|
||||
'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ],
|
||||
'mandatoryFeatures' => [ "benchmark" ],
|
||||
},
|
||||
'root@lotsofspace' => {
|
||||
'systemTypes' => [ "i686-linux", "x86_64-linux" ],
|
||||
'sshKeys' => '/var/sshkey',
|
||||
'maxJobs' => 1,
|
||||
'speedFactor' => 1,
|
||||
'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ],
|
||||
'mandatoryFeatures' => [ "benchmark" ],
|
||||
},
|
||||
|
||||
}, ":)");
|
||||
|
||||
done_testing;
|
54
t/Hydra/Helper/attributeset.t
Normal file
54
t/Hydra/Helper/attributeset.t
Normal file
@ -0,0 +1,54 @@
|
||||
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");
|
||||
|
||||
my @enumerated = $attrs->enumerate();
|
||||
is(
|
||||
\@enumerated,
|
||||
[
|
||||
# "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;
|
45
t/Hydra/Helper/escape.t
Normal file
45
t/Hydra/Helper/escape.t
Normal file
@ -0,0 +1,45 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
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;
|
Reference in New Issue
Block a user