From 8c15f58df6bd13140e247de294e456f096cdee71 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 8 Oct 2024 12:05:57 +0200 Subject: [PATCH] Inventory/tests: add more eval smoke tests --- lib/inventory/build-inventory/default.nix | 7 ++++- lib/inventory/flake-module.nix | 9 +------ lib/inventory/tests/default.nix | 33 ++++++++++++++++++++++- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index c51151322..5e39cee37 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -98,7 +98,12 @@ let roleModules = builtins.map ( role: 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 if builtins.pathExists path then path diff --git a/lib/inventory/flake-module.nix b/lib/inventory/flake-module.nix index 9a01abac9..38d14258f 100644 --- a/lib/inventory/flake-module.nix +++ b/lib/inventory/flake-module.nix @@ -17,13 +17,6 @@ in ... }: let - inventory = ( - import ./build-inventory { - clan-core = self; - inherit lib; - } - ); - getSchema = import ./interface-to-schema.nix { inherit lib self; }; # 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 legacyPackages.evalTests-inventory = import ./tests { - inherit inventory; + inherit lib; clan-core = self; }; diff --git a/lib/inventory/tests/default.nix b/lib/inventory/tests/default.nix index 5460b477d..3b85191c0 100644 --- a/lib/inventory/tests/default.nix +++ b/lib/inventory/tests/default.nix @@ -1,5 +1,12 @@ -{ inventory, clan-core, ... }: +{ clan-core, lib, ... }: let + inventory = ( + import ../build-inventory { + + inherit lib clan-core; + } + ); + inherit (inventory) buildInventory; 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 = let configs = buildInventory {