Inventory: fix tests

This commit is contained in:
Johannes Kirschbauer 2024-07-15 16:52:24 +02:00
parent 9afed2295d
commit 7b18caca9b
Signed by: hsjobeki
SSH Key Fingerprint: SHA256:vX3utDqig7Ph5L0JPv87ZTPb/w7cMzREKVZzzLFg9qU
3 changed files with 64 additions and 48 deletions

View File

@ -93,7 +93,6 @@ let
roleServiceConfigs = builtins.map (
role: serviceConfig.roles.${role}.config or { }
) inverseRoles.${machineName} or [ ];
dbg = v: lib.traceSeq v v;
customImports = map (s: "${directory}/${s}") (
globalImports ++ machineImports ++ roleServiceImports
@ -104,7 +103,7 @@ let
acc2
++ [
{
imports = dbg ([ clan-core.clanModules.${moduleName} ] ++ roleModules ++ customImports);
imports = [ clan-core.clanModules.${moduleName} ] ++ roleModules ++ customImports;
config.clan.${moduleName} = lib.mkMerge (
[
globalConfig

View File

@ -43,7 +43,6 @@ let
importsOption = lib.mkOption {
default = [ ];
type = t.listOf t.str;
# apply = map (pathOrString: "${pathOrString}");
};
in
{

View File

@ -2,25 +2,31 @@
{
test_inventory_empty = {
# Empty inventory should return an empty module
expr = buildInventory { };
expr = buildInventory {
inventory = { };
directory = ./.;
};
expected = { };
};
test_inventory_role_imports =
let
configs = buildInventory {
services = {
borgbackup.instance_1 = {
roles.server.machines = [ "backup_server" ];
roles.client.machines = [
"client_1_machine"
"client_2_machine"
];
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
roles.server.machines = [ "backup_server" ];
roles.client.machines = [
"client_1_machine"
"client_2_machine"
];
};
};
machines = {
"backup_server" = { };
"client_1_machine" = { };
"client_2_machine" = { };
};
};
machines = {
"backup_server" = { };
"client_1_machine" = { };
"client_2_machine" = { };
};
};
in
@ -49,18 +55,21 @@
test_inventory_tag_resolve =
let
configs = buildInventory {
services = {
borgbackup.instance_1 = {
roles.client.tags = [ "backup" ];
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
roles.client.tags = [ "backup" ];
};
};
};
machines = {
"not_used_machine" = { };
"client_1_machine" = {
tags = [ "backup" ];
};
"client_2_machine" = {
tags = [ "backup" ];
machines = {
"not_used_machine" = { };
"client_1_machine" = {
tags = [ "backup" ];
};
"client_2_machine" = {
tags = [ "backup" ];
};
};
};
};
@ -85,14 +94,17 @@
test_inventory_multiple_roles =
let
configs = buildInventory {
services = {
borgbackup.instance_1 = {
roles.client.machines = [ "machine_1" ];
roles.server.machines = [ "machine_1" ];
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
roles.client.machines = [ "machine_1" ];
roles.server.machines = [ "machine_1" ];
};
};
machines = {
"machine_1" = { };
};
};
machines = {
"machine_1" = { };
};
};
in
@ -112,13 +124,16 @@
test_inventory_role_doesnt_exist =
let
configs = buildInventory {
services = {
borgbackup.instance_1 = {
roles.roleXYZ.machines = [ "machine_1" ];
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
roles.roleXYZ.machines = [ "machine_1" ];
};
};
machines = {
"machine_1" = { };
};
};
machines = {
"machine_1" = { };
};
};
in
@ -132,15 +147,18 @@
test_inventory_tag_doesnt_exist =
let
configs = buildInventory {
services = {
borgbackup.instance_1 = {
roles.client.machines = [ "machine_1" ];
roles.client.tags = [ "tagXYZ" ];
directory = ./.;
inventory = {
services = {
borgbackup.instance_1 = {
roles.client.machines = [ "machine_1" ];
roles.client.tags = [ "tagXYZ" ];
};
};
};
machines = {
"machine_1" = {
tags = [ "tagABC" ];
machines = {
"machine_1" = {
tags = [ "tagABC" ];
};
};
};
};