makeTestClan: simplify - move parameters into module

... in preparation of removing the makeTestClan wrapper and make this a module instead that can be imported into any test.
This commit is contained in:
DavHau
2025-06-02 12:14:06 +07:00
parent 9069421c7f
commit 9cb6382cec
5 changed files with 83 additions and 85 deletions

View File

@@ -6,8 +6,6 @@
}:
clanLib.test.makeTestClan {
inherit pkgs self;
# TODO: container driver does not support: sleep, wait_for_window, send_chars, wait_for_text
useContainers = false;
nixosTest = (
{ lib, ... }:
let
@@ -31,6 +29,8 @@ clanLib.test.makeTestClan {
clan = {
directory = ./.;
# TODO: container driver does not support: sleep, wait_for_window, send_chars, wait_for_text
test.useContainers = false;
inventory = {
machines = lib.genAttrs machines (_: { });
services = {

View File

@@ -6,8 +6,6 @@
}:
clanLib.test.makeTestClan {
inherit pkgs self;
# TODO: container driver does not support wait_for_file() yet
useContainers = false;
nixosTest = (
{ lib, ... }:
{
@@ -15,6 +13,8 @@ clanLib.test.makeTestClan {
clan = {
directory = ./.;
# TODO: container driver does not support wait_for_file() yet
test.useContainers = false;
inventory = {
machines = lib.genAttrs [
"introducer"

View File

@@ -7,7 +7,6 @@
}:
clanLib.test.makeTestClan {
inherit pkgs self;
useContainers = false;
nixosTest = (
{ ... }:
{
@@ -15,6 +14,7 @@ clanLib.test.makeTestClan {
clan = {
directory = ./.;
test.useContainers = false;
modules."@clan/wifi" = module;
inventory = {

View File

@@ -36,7 +36,7 @@ let
machineNames = map (name: "${name}: Machine;") pythonizedNames;
pythonizedNames = map pythonizeName nodeHostNames;
in
{
lib.mkIf (config.clan.test.useContainers or true) {
defaults.imports = [
./nixos-module.nix
];

View File

@@ -15,10 +15,9 @@ let
in
{
#
containerTest = import ./container-test.nix;
baseTest = import ./test-base.nix;
#
flakeModules = clanLib.callLib ./flakeModules.nix { };
minifyModule = ./minify.nix;
@@ -30,32 +29,34 @@ in
nixosTest,
pkgs,
self,
useContainers ? true,
# Displayed for better error messages, otherwise the placeholder
attrName ? "<check_name>",
...
}:
let
nixos-lib = import (pkgs.path + "/nixos/lib") { };
testName = test.config.name;
test = (
nixos-lib.runTest (
{ config, ... }:
let
clanFlakeResult = config.clan;
testName = config.name;
update-vars-script = "${self.packages.${pkgs.system}.generate-test-vars}/bin/generate-test-vars";
relativeDir = removePrefix ("${self}/") (toString test.config.clan.directory);
relativeDir = removePrefix ("${self}/") (toString config.clan.directory);
update-vars = pkgs.writeShellScriptBin "update-vars" ''
${update-vars-script} $PRJ_ROOT/${relativeDir} ${testName}
'';
testSrc = lib.cleanSource test.config.clan.directory;
testSrc = lib.cleanSource config.clan.directory;
inputsForMachine =
machine:
flip mapAttrsToList machine.clan.core.vars.generators (_name: generator: generator.runtimeInputs);
generatorRuntimeInputs = unique (
flatten (flip mapAttrsToList test.config.nodes (_machineName: machine: inputsForMachine machine))
flatten (flip mapAttrsToList config.nodes (_machineName: machine: inputsForMachine machine))
);
vars-check =
@@ -98,16 +99,12 @@ in
fi
touch $out
'';
test =
(nixos-lib.runTest (
{ config, ... }:
let
clanFlakeResult = config.clan;
in
{
imports = [
nixosTest
] ++ lib.optionals useContainers [ ./container-test-driver/driver-module.nix ];
./container-test-driver/driver-module.nix
];
options = {
clanSettings = mkOption {
default = { };
@@ -136,10 +133,17 @@ in
_prefix = [
"checks"
"<system>"
attrName
config.name
"config"
"clan"
];
options = {
test.useContainers = mkOption {
default = true;
type = types.bool;
description = "Whether to use containers for the test.";
};
};
}
];
};
@@ -201,17 +205,11 @@ in
}
);
# TODO: figure out if we really need this
# I am proposing for less magic in the test-framework
# People may add this in their own tests
# _module.args = { inherit self; };
# node.specialArgs.self = self;
result = { inherit update-vars vars-check; };
};
}
)).config.result;
)
);
in
test
// {
inherit update-vars vars-check;
};
test;
}