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:
parent
5297d584bc
commit
9886db059a
5 changed files with 34 additions and 20 deletions
|
@ -26,7 +26,6 @@ rec {
|
|||
extraTestModule = {
|
||||
config = {
|
||||
hostPkgs = pkgs;
|
||||
minimalResult = hydra;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -16,22 +16,22 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
run = mkOption {
|
||||
test = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
Derivation that runs the test.
|
||||
Derivation that runs the test as its "build" process.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
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}";
|
||||
|
||||
requiredSystemFeatures = [ "kvm" "nixos-test" ];
|
||||
|
||||
buildCommand =
|
||||
''
|
||||
buildCommand = ''
|
||||
mkdir -p $out
|
||||
|
||||
# effectively mute the XMLLogger
|
||||
|
@ -44,6 +44,8 @@ in
|
|||
|
||||
meta = config.meta;
|
||||
};
|
||||
inherit (config) passthru meta;
|
||||
};
|
||||
|
||||
# useful for inspection (debugging / exploration)
|
||||
passthru.config = config;
|
||||
|
|
|
@ -22,8 +22,8 @@ let
|
|||
import ./tests/all-tests.nix {
|
||||
inherit system;
|
||||
pkgs = import ./.. { inherit system; };
|
||||
callTest = t: {
|
||||
${system} = hydraJob t.test;
|
||||
callTest = config: {
|
||||
${system} = hydraJob config.test;
|
||||
};
|
||||
} // {
|
||||
# for typechecking of the scripts and evaluation of
|
||||
|
@ -32,8 +32,8 @@ let
|
|||
import ./tests/all-tests.nix {
|
||||
inherit system;
|
||||
pkgs = import ./.. { inherit system; };
|
||||
callTest = t: {
|
||||
${system} = hydraJob t.test.driver;
|
||||
callTest = config: {
|
||||
${system} = hydraJob config.driver;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -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 `anything` returned by callTest at its test leafs.
|
||||
# The tests not supported by `system` will be replaced with `{}`, so that
|
||||
|
@ -29,11 +36,17 @@ let
|
|||
|
||||
inherit
|
||||
(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:
|
||||
if tree?recurseForDerivations && tree.recurseForDerivations
|
||||
then mapAttrs (k: findTests) (builtins.removeAttrs tree ["recurseForDerivations"])
|
||||
else callTest ({ test = tree; });
|
||||
then
|
||||
mapAttrs
|
||||
(k: findTests)
|
||||
(builtins.removeAttrs tree ["recurseForDerivations"])
|
||||
else callTest tree;
|
||||
|
||||
runTest = arg: let r = doRunTest arg; in findTests r;
|
||||
runTestOn = systems: arg:
|
||||
if elem system systems then runTest arg
|
||||
|
|
|
@ -140,14 +140,14 @@ with pkgs;
|
|||
nixosTests = import ../../nixos/tests/all-tests.nix {
|
||||
inherit pkgs;
|
||||
system = stdenv.hostPlatform.system;
|
||||
callTest = t: t.test;
|
||||
callTest = config: config.test;
|
||||
} // {
|
||||
# for typechecking of the scripts and evaluation of
|
||||
# the nodes, without running VMs.
|
||||
allDrivers = import ../../nixos/tests/all-tests.nix {
|
||||
inherit pkgs;
|
||||
system = stdenv.hostPlatform.system;
|
||||
callTest = t: t.test.driver;
|
||||
callTest = config: config.test.driver;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue