summary refs log tree commit diff
path: root/nixos/lib/testing-python.nix
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2022-03-18 01:20:21 +0100
committerNaïm Favier <n@monade.li>2022-03-18 02:44:11 +0100
commit79a234567c01399c5f1ae1d0b60ac84d12075b3b (patch)
tree3d6f15fc8db8d420ed3f47a547e0b2571ef4c645 /nixos/lib/testing-python.nix
parent9077b1a63145b7cbf54a9331ca12e6d8440b6030 (diff)
downloadnixpkgs-79a234567c01399c5f1ae1d0b60ac84d12075b3b.tar
nixpkgs-79a234567c01399c5f1ae1d0b60ac84d12075b3b.tar.gz
nixpkgs-79a234567c01399c5f1ae1d0b60ac84d12075b3b.tar.bz2
nixpkgs-79a234567c01399c5f1ae1d0b60ac84d12075b3b.tar.lz
nixpkgs-79a234567c01399c5f1ae1d0b60ac84d12075b3b.tar.xz
nixpkgs-79a234567c01399c5f1ae1d0b60ac84d12075b3b.tar.zst
nixpkgs-79a234567c01399c5f1ae1d0b60ac84d12075b3b.zip
nixos/testing: restrict arguments to makeTest
Disallow passing arbitrary arguments to makeTest since they are not
used; this can help catch mistakes.
Diffstat (limited to 'nixos/lib/testing-python.nix')
-rw-r--r--nixos/lib/testing-python.nix27
1 files changed, 15 insertions, 12 deletions
diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix
index 0d3c3a89e78..8c4cdb31791 100644
--- a/nixos/lib/testing-python.nix
+++ b/nixos/lib/testing-python.nix
@@ -146,26 +146,28 @@ rec {
 
   # Make a full-blown test
   makeTest =
-    { testScript
+    { machine ? null
+    , nodes ? {}
+    , testScript
     , enableOCR ? false
     , name ? "unnamed"
       # Skip linting (mainly intended for faster dev cycles)
     , skipLint ? false
     , passthru ? {}
+    , meta ? {}
     , # For meta.position
       pos ? # position used in error messages and for meta.position
-        (if t.meta.description or null != null
-          then builtins.unsafeGetAttrPos "description" t.meta
+        (if meta.description or null != null
+          then builtins.unsafeGetAttrPos "description" meta
           else builtins.unsafeGetAttrPos "testScript" t)
-    , ...
     } @ t:
     let
-      nodes = qemu_pkg:
+      mkNodes = qemu_pkg:
         let
           testScript' =
             # Call the test script with the computed nodes.
             if lib.isFunction testScript
-            then testScript { nodes = nodes qemu_pkg; }
+            then testScript { nodes = mkNodes qemu_pkg; }
             else testScript;
 
           build-vms = import ./build-vms.nix {
@@ -205,33 +207,34 @@ rec {
           };
         in
           build-vms.buildVirtualNetwork (
-              t.nodes or (if t ? machine then { machine = t.machine; } else { })
+              nodes // lib.optionalAttrs (machine != null) { inherit machine; }
           );
 
       driver = setupDriverForTest {
         inherit testScript enableOCR skipLint passthru;
         testName = name;
         qemu_pkg = pkgs.qemu_test;
-        nodes = nodes pkgs.qemu_test;
+        nodes = mkNodes pkgs.qemu_test;
       };
       driverInteractive = setupDriverForTest {
         inherit testScript enableOCR skipLint passthru;
         testName = name;
         qemu_pkg = pkgs.qemu;
-        nodes = nodes pkgs.qemu;
+        nodes = mkNodes pkgs.qemu;
         interactive = true;
       };
 
       test =
         let
-          passMeta = drv: drv // lib.optionalAttrs (t ? meta) {
-            meta = (drv.meta or { }) // t.meta;
+          passMeta = drv: drv // lib.optionalAttrs (meta != {}) {
+            meta = (drv.meta or { }) // meta;
           };
         in passMeta (runTests { inherit driver pos driverInteractive; });
 
     in
       test // {
-        inherit test driver driverInteractive nodes;
+        inherit test driver driverInteractive;
+        inherit (driver) nodes;
       };
 
   abortForFunction = functionName: abort ''The ${functionName} function was