nixos/testing: Embrace callTest

My conception of its input was wrong. It is quite a useful construct,
even if its name is a bit weird.
This commit is contained in:
Robert Hensing 2022-06-25 12:47:50 +02:00
parent 5297d584bc
commit 9886db059a
5 changed files with 34 additions and 20 deletions

View file

@ -26,7 +26,6 @@ rec {
extraTestModule = { extraTestModule = {
config = { config = {
hostPkgs = pkgs; hostPkgs = pkgs;
minimalResult = hydra;
}; };
}; };

View file

@ -16,22 +16,22 @@ in
''; '';
}; };
run = mkOption { test = mkOption {
type = types.package; type = types.package;
description = '' description = ''
Derivation that runs the test. Derivation that runs the test as its "build" process.
''; '';
}; };
}; };
config = { config = {
run = hostPkgs.stdenv.mkDerivation { test = lib.lazyDerivation { # lazyDerivation improves performance when only passthru items and/or meta are used.
derivation = hostPkgs.stdenv.mkDerivation {
name = "vm-test-run-${config.name}"; name = "vm-test-run-${config.name}";
requiredSystemFeatures = [ "kvm" "nixos-test" ]; requiredSystemFeatures = [ "kvm" "nixos-test" ];
buildCommand = buildCommand = ''
''
mkdir -p $out mkdir -p $out
# effectively mute the XMLLogger # effectively mute the XMLLogger
@ -44,6 +44,8 @@ in
meta = config.meta; meta = config.meta;
}; };
inherit (config) passthru meta;
};
# useful for inspection (debugging / exploration) # useful for inspection (debugging / exploration)
passthru.config = config; passthru.config = config;

View file

@ -22,8 +22,8 @@ let
import ./tests/all-tests.nix { import ./tests/all-tests.nix {
inherit system; inherit system;
pkgs = import ./.. { inherit system; }; pkgs = import ./.. { inherit system; };
callTest = t: { callTest = config: {
${system} = hydraJob t.test; ${system} = hydraJob config.test;
}; };
} // { } // {
# for typechecking of the scripts and evaluation of # for typechecking of the scripts and evaluation of
@ -32,8 +32,8 @@ let
import ./tests/all-tests.nix { import ./tests/all-tests.nix {
inherit system; inherit system;
pkgs = import ./.. { inherit system; }; pkgs = import ./.. { inherit system; };
callTest = t: { callTest = config: {
${system} = hydraJob t.test.driver; ${system} = hydraJob config.driver;
}; };
}; };
}; };

View file

@ -1,4 +1,11 @@
{ system, pkgs, callTest }: { system,
pkgs,
# Projects the test configuration into a the desired value; usually
# the test runner: `config: config.test`.
callTest,
}:
# The return value of this function will be an attrset with arbitrary depth and # The return value of this function will be an attrset with arbitrary depth and
# the `anything` returned by callTest at its test leafs. # the `anything` returned by callTest at its test leafs.
# The tests not supported by `system` will be replaced with `{}`, so that # The tests not supported by `system` will be replaced with `{}`, so that
@ -29,11 +36,17 @@ let
inherit inherit
(rec { (rec {
doRunTest = (import ../lib/testing-python.nix { inherit system pkgs; }).runTest; doRunTest = arg: (import ../lib/testing-python.nix { inherit system pkgs; }).runTest {
imports = [ arg { inherit callTest; } ];
};
findTests = tree: findTests = tree:
if tree?recurseForDerivations && tree.recurseForDerivations if tree?recurseForDerivations && tree.recurseForDerivations
then mapAttrs (k: findTests) (builtins.removeAttrs tree ["recurseForDerivations"]) then
else callTest ({ test = tree; }); mapAttrs
(k: findTests)
(builtins.removeAttrs tree ["recurseForDerivations"])
else callTest tree;
runTest = arg: let r = doRunTest arg; in findTests r; runTest = arg: let r = doRunTest arg; in findTests r;
runTestOn = systems: arg: runTestOn = systems: arg:
if elem system systems then runTest arg if elem system systems then runTest arg

View file

@ -140,14 +140,14 @@ with pkgs;
nixosTests = import ../../nixos/tests/all-tests.nix { nixosTests = import ../../nixos/tests/all-tests.nix {
inherit pkgs; inherit pkgs;
system = stdenv.hostPlatform.system; system = stdenv.hostPlatform.system;
callTest = t: t.test; callTest = config: config.test;
} // { } // {
# for typechecking of the scripts and evaluation of # for typechecking of the scripts and evaluation of
# the nodes, without running VMs. # the nodes, without running VMs.
allDrivers = import ../../nixos/tests/all-tests.nix { allDrivers = import ../../nixos/tests/all-tests.nix {
inherit pkgs; inherit pkgs;
system = stdenv.hostPlatform.system; system = stdenv.hostPlatform.system;
callTest = t: t.test.driver; callTest = config: config.test.driver;
}; };
}; };