Inventory: fix tests

This commit is contained in:
Johannes Kirschbauer
2024-07-15 16:52:24 +02:00
parent 9afed2295d
commit 7b18caca9b
3 changed files with 64 additions and 48 deletions

View File

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

View File

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

View File

@@ -2,12 +2,17 @@
{ {
test_inventory_empty = { test_inventory_empty = {
# Empty inventory should return an empty module # Empty inventory should return an empty module
expr = buildInventory { }; expr = buildInventory {
inventory = { };
directory = ./.;
};
expected = { }; expected = { };
}; };
test_inventory_role_imports = test_inventory_role_imports =
let let
configs = buildInventory { configs = buildInventory {
directory = ./.;
inventory = {
services = { services = {
borgbackup.instance_1 = { borgbackup.instance_1 = {
roles.server.machines = [ "backup_server" ]; roles.server.machines = [ "backup_server" ];
@@ -23,6 +28,7 @@
"client_2_machine" = { }; "client_2_machine" = { };
}; };
}; };
};
in in
{ {
expr = { expr = {
@@ -49,6 +55,8 @@
test_inventory_tag_resolve = test_inventory_tag_resolve =
let let
configs = buildInventory { configs = buildInventory {
directory = ./.;
inventory = {
services = { services = {
borgbackup.instance_1 = { borgbackup.instance_1 = {
roles.client.tags = [ "backup" ]; roles.client.tags = [ "backup" ];
@@ -64,6 +72,7 @@
}; };
}; };
}; };
};
in in
{ {
expr = { expr = {
@@ -85,6 +94,8 @@
test_inventory_multiple_roles = test_inventory_multiple_roles =
let let
configs = buildInventory { configs = buildInventory {
directory = ./.;
inventory = {
services = { services = {
borgbackup.instance_1 = { borgbackup.instance_1 = {
roles.client.machines = [ "machine_1" ]; roles.client.machines = [ "machine_1" ];
@@ -95,6 +106,7 @@
"machine_1" = { }; "machine_1" = { };
}; };
}; };
};
in in
{ {
expr = { expr = {
@@ -112,6 +124,8 @@
test_inventory_role_doesnt_exist = test_inventory_role_doesnt_exist =
let let
configs = buildInventory { configs = buildInventory {
directory = ./.;
inventory = {
services = { services = {
borgbackup.instance_1 = { borgbackup.instance_1 = {
roles.roleXYZ.machines = [ "machine_1" ]; roles.roleXYZ.machines = [ "machine_1" ];
@@ -121,6 +135,7 @@
"machine_1" = { }; "machine_1" = { };
}; };
}; };
};
in in
{ {
expr = configs; expr = configs;
@@ -132,6 +147,8 @@
test_inventory_tag_doesnt_exist = test_inventory_tag_doesnt_exist =
let let
configs = buildInventory { configs = buildInventory {
directory = ./.;
inventory = {
services = { services = {
borgbackup.instance_1 = { borgbackup.instance_1 = {
roles.client.machines = [ "machine_1" ]; roles.client.machines = [ "machine_1" ];
@@ -144,6 +161,7 @@
}; };
}; };
}; };
};
in in
{ {
expr = configs; expr = configs;