Merge pull request #1048 from DeterminateSystems/fixup-1003

Hydra::Helper::Nix::getMachines: add a test
This commit is contained in:
Graham Christensen 2021-10-24 21:38:38 -04:00 committed by GitHub
commit 802a5dfe68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 4 deletions

View file

@ -344,11 +344,19 @@ sub getMachines {
next unless -e $machinesFile;
open(my $conf, "<", $machinesFile) or die;
while (my $line = <$conf>) {
chomp;
s/\#.*$//g;
next if /^\s*$/;
my @tokens = split /\s/, $line;
chomp($line);
$line =~ s/\#.*$//g;
next if $line =~ /^\s*$/;
my @tokens = split /\s+/, $line;
if (!defined($tokens[5]) || $tokens[5] eq "-") {
$tokens[5] = "";
}
my @supportedFeatures = split(/,/, $tokens[5] || "");
if (!defined($tokens[6]) || $tokens[6] eq "-") {
$tokens[6] = "";
}
my @mandatoryFeatures = split(/,/, $tokens[6] || "");
$machines{$tokens[0]} =
{ systemTypes => [ split(/,/, $tokens[1]) ]

68
t/Helper/Nix.t Normal file
View 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;