mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-21 08:59:20 +03:00
nixos/testing-python.nix: Add evalTest
This is a decomposition of the testing-python.nix and build-vms.nix files into modules. By refactoring the glue, we accomplish the following: - NixOS tests can now use `imports` and other module system features. - Network-wide test setup can now be reusable; example: - A setup with all VMs configured to use a DNS server - Split long, slow tests into multiple tests that import a common module that has most of the setup. - Type checking for the test arguments - (TBD) "generated" options reference docs - Aspects that had to be wired through all the glue are now in their own files. - Chief example: interactive.nix. - Also: network.nix In rewriting this, I've generally stuck as close as possible to the existing code; copying pieces of logic and rewiring them, without changing the logic itself. I've made two exceptions to this rule - Introduction of `extraDriverArgs` instead of hardcoded interactivity logic. - Incorporation of https://github.com/NixOS/nixpkgs/pull/144110 in testScript.nix. I might revert the latter and split it into a new commit.
This commit is contained in:
parent
1ffa30b055
commit
b3de22483c
11 changed files with 570 additions and 0 deletions
78
nixos/lib/testing/testScript.nix
Normal file
78
nixos/lib/testing/testScript.nix
Normal file
|
@ -0,0 +1,78 @@
|
|||
testModuleArgs@{ config, lib, hostPkgs, nodes, moduleType, ... }:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
inherit (types) either str functionTo;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
testScript = mkOption {
|
||||
type = either str (functionTo str);
|
||||
};
|
||||
testScriptString = mkOption {
|
||||
type = str;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
};
|
||||
|
||||
includeTestScriptReferences = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
internal = true;
|
||||
};
|
||||
withoutTestScriptReferences = mkOption {
|
||||
type = moduleType;
|
||||
description = ''
|
||||
A parallel universe where the testScript is invalid and has no references.
|
||||
'';
|
||||
};
|
||||
};
|
||||
config = {
|
||||
withoutTestScriptReferences.includeTestScriptReferences = false;
|
||||
withoutTestScriptReferences.testScript = lib.mkForce "testscript omitted";
|
||||
|
||||
testScriptString =
|
||||
if lib.isFunction config.testScript
|
||||
then
|
||||
config.testScript
|
||||
{
|
||||
nodes =
|
||||
lib.mapAttrs
|
||||
(k: v:
|
||||
if v.virtualisation.useNixStoreImage
|
||||
then
|
||||
# prevent infinite recursion when testScript would
|
||||
# reference v's toplevel
|
||||
config.withoutTestScriptReferences.nodesCompat.${k}
|
||||
else
|
||||
# reuse memoized config
|
||||
v
|
||||
)
|
||||
config.nodesCompat;
|
||||
}
|
||||
else config.testScript;
|
||||
|
||||
defaults = { config, name, ... }: {
|
||||
# Make sure all derivations referenced by the test
|
||||
# script are available on the nodes. When the store is
|
||||
# accessed through 9p, this isn't important, since
|
||||
# everything in the store is available to the guest,
|
||||
# but when building a root image it is, as all paths
|
||||
# that should be available to the guest has to be
|
||||
# copied to the image.
|
||||
virtualisation.additionalPaths =
|
||||
lib.optional
|
||||
# A testScript may evaluate nodes, which has caused
|
||||
# infinite recursions. The demand cycle involves:
|
||||
# testScript -->
|
||||
# nodes -->
|
||||
# toplevel -->
|
||||
# additionalPaths -->
|
||||
# hasContext testScript' -->
|
||||
# testScript (ad infinitum)
|
||||
# If we don't need to build an image, we can break this
|
||||
# cycle by short-circuiting when useNixStoreImage is false.
|
||||
(config.virtualisation.useNixStoreImage && builtins.hasContext testModuleArgs.config.testScriptString && testModuleArgs.config.includeTestScriptReferences)
|
||||
(hostPkgs.writeStringReferencesToFile testModuleArgs.config.testScriptString);
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue