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:
@@ -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 = {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
|
||||
@@ -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
|
||||
];
|
||||
|
||||
@@ -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,84 +29,82 @@ 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;
|
||||
|
||||
update-vars-script = "${self.packages.${pkgs.system}.generate-test-vars}/bin/generate-test-vars";
|
||||
|
||||
relativeDir = removePrefix ("${self}/") (toString test.config.clan.directory);
|
||||
|
||||
update-vars = pkgs.writeShellScriptBin "update-vars" ''
|
||||
${update-vars-script} $PRJ_ROOT/${relativeDir} ${testName}
|
||||
'';
|
||||
|
||||
testSrc = lib.cleanSource test.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))
|
||||
);
|
||||
|
||||
vars-check =
|
||||
pkgs.runCommand "update-vars-check"
|
||||
{
|
||||
nativeBuildInputs = generatorRuntimeInputs ++ [
|
||||
pkgs.nix
|
||||
pkgs.git
|
||||
pkgs.age
|
||||
pkgs.sops
|
||||
pkgs.bubblewrap
|
||||
];
|
||||
closureInfo = pkgs.closureInfo {
|
||||
rootPaths = generatorRuntimeInputs ++ [
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
pkgs.jq.dev
|
||||
pkgs.stdenv
|
||||
pkgs.stdenvNoCC
|
||||
pkgs.shellcheck-minimal
|
||||
pkgs.age
|
||||
pkgs.sops
|
||||
];
|
||||
};
|
||||
}
|
||||
''
|
||||
${self.legacyPackages.${pkgs.system}.setupNixInNix}
|
||||
cp -r ${testSrc} ./src
|
||||
chmod +w -R ./src
|
||||
find ./src/sops ./src/vars | sort > filesBefore
|
||||
${update-vars-script} ./src ${testName} \
|
||||
--repo-root ${self.packages.${pkgs.system}.clan-core-flake} \
|
||||
--clean
|
||||
find ./src/sops ./src/vars | sort > filesAfter
|
||||
if ! diff -q filesBefore filesAfter; then
|
||||
echo "The update-vars script changed the files in ${testSrc}."
|
||||
echo "Diff:"
|
||||
diff filesBefore filesAfter || true
|
||||
exit 1
|
||||
fi
|
||||
touch $out
|
||||
'';
|
||||
test =
|
||||
(nixos-lib.runTest (
|
||||
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 config.clan.directory);
|
||||
|
||||
update-vars = pkgs.writeShellScriptBin "update-vars" ''
|
||||
${update-vars-script} $PRJ_ROOT/${relativeDir} ${testName}
|
||||
'';
|
||||
|
||||
testSrc = lib.cleanSource config.clan.directory;
|
||||
|
||||
inputsForMachine =
|
||||
machine:
|
||||
flip mapAttrsToList machine.clan.core.vars.generators (_name: generator: generator.runtimeInputs);
|
||||
|
||||
generatorRuntimeInputs = unique (
|
||||
flatten (flip mapAttrsToList config.nodes (_machineName: machine: inputsForMachine machine))
|
||||
);
|
||||
|
||||
vars-check =
|
||||
pkgs.runCommand "update-vars-check"
|
||||
{
|
||||
nativeBuildInputs = generatorRuntimeInputs ++ [
|
||||
pkgs.nix
|
||||
pkgs.git
|
||||
pkgs.age
|
||||
pkgs.sops
|
||||
pkgs.bubblewrap
|
||||
];
|
||||
closureInfo = pkgs.closureInfo {
|
||||
rootPaths = generatorRuntimeInputs ++ [
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
pkgs.jq.dev
|
||||
pkgs.stdenv
|
||||
pkgs.stdenvNoCC
|
||||
pkgs.shellcheck-minimal
|
||||
pkgs.age
|
||||
pkgs.sops
|
||||
];
|
||||
};
|
||||
}
|
||||
''
|
||||
${self.legacyPackages.${pkgs.system}.setupNixInNix}
|
||||
cp -r ${testSrc} ./src
|
||||
chmod +w -R ./src
|
||||
find ./src/sops ./src/vars | sort > filesBefore
|
||||
${update-vars-script} ./src ${testName} \
|
||||
--repo-root ${self.packages.${pkgs.system}.clan-core-flake} \
|
||||
--clean
|
||||
find ./src/sops ./src/vars | sort > filesAfter
|
||||
if ! diff -q filesBefore filesAfter; then
|
||||
echo "The update-vars script changed the files in ${testSrc}."
|
||||
echo "Diff:"
|
||||
diff filesBefore filesAfter || true
|
||||
exit 1
|
||||
fi
|
||||
touch $out
|
||||
'';
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user