Inventory/tests: add more eval smoke tests

This commit is contained in:
Johannes Kirschbauer
2024-10-08 12:05:57 +02:00
parent f7bef7c5ed
commit 52b26f6cda
3 changed files with 39 additions and 10 deletions

View File

@@ -98,7 +98,12 @@ let
roleModules = builtins.map ( roleModules = builtins.map (
role: role:
let let
path = clan-core.clanModules.${serviceName} + "/roles/${role}.nix"; # Check the module exists
module =
clan-core.clanModules.${serviceName}
or (throw "ClanModule not found: '${serviceName}'. Make sure the module is added in the 'clanModules' attribute of clan-core.");
path = module + "/roles/${role}.nix";
in in
if builtins.pathExists path then if builtins.pathExists path then
path path

View File

@@ -17,13 +17,6 @@ in
... ...
}: }:
let let
inventory = (
import ./build-inventory {
clan-core = self;
inherit lib;
}
);
getSchema = import ./interface-to-schema.nix { inherit lib self; }; getSchema = import ./interface-to-schema.nix { inherit lib self; };
# The schema for the inventory, without default values, from the module system. # The schema for the inventory, without default values, from the module system.
@@ -125,7 +118,7 @@ in
# Run: nix-unit --extra-experimental-features flakes --flake .#legacyPackages.x86_64-linux.evalTests # Run: nix-unit --extra-experimental-features flakes --flake .#legacyPackages.x86_64-linux.evalTests
legacyPackages.evalTests-inventory = import ./tests { legacyPackages.evalTests-inventory = import ./tests {
inherit inventory; inherit lib;
clan-core = self; clan-core = self;
}; };

View File

@@ -1,5 +1,12 @@
{ inventory, clan-core, ... }: { clan-core, lib, ... }:
let let
inventory = (
import ../build-inventory {
inherit lib clan-core;
}
);
inherit (inventory) buildInventory; inherit (inventory) buildInventory;
in in
{ {
@@ -120,6 +127,30 @@ in
}; };
}; };
test_inventory_module_doesnt_exist =
let
configs = buildInventory {
directory = ./.;
inventory = {
services = {
fanatasy.instance_1 = {
roles.default.machines = [ "machine_1" ];
};
};
machines = {
"machine_1" = { };
};
};
};
in
{
expr = configs;
expectedError = {
type = "ThrownError";
msg = "ClanModule not found*";
};
};
test_inventory_role_doesnt_exist = test_inventory_role_doesnt_exist =
let let
configs = buildInventory { configs = buildInventory {