Merge pull request #225313 from hercules-ci/testers-runNixOSTest

testers.runNixOSTest: init
This commit is contained in:
Jacek Galowicz 2023-05-12 16:04:26 +02:00 committed by GitHub
commit cc8e4ed375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -164,6 +164,26 @@ tests.fetchgit = testers.invalidateFetcherByDrvHash fetchgit {
};
```
## `runNixOSTest` {#tester-runNixOSTest}
A helper function that behaves exactly like the NixOS `runTest`, except it also assigns this Nixpkgs package set as the `pkgs` of the test and makes the `nixpkgs.*` options read-only.
If your test is part of the Nixpkgs repository, or if you need a more general entrypoint, see ["Calling a test" in the NixOS manual](https://nixos.org/manual/nixos/stable/index.html#sec-calling-nixos-tests).
Example:
```nix
pkgs.testers.runNixOSTest ({ lib, ... }: {
name = "hello";
nodes.machine = { pkgs, ... }: {
environment.systemPackages = [ pkgs.hello ];
};
testScript = ''
machine.succeed("hello")
'';
})
```
## `nixosTest` {#tester-nixosTest}
Run a NixOS VM network test using this evaluation of Nixpkgs.

View File

@ -94,6 +94,20 @@
else salted;
in checked;
# See doc/builders/testers.chapter.md or
# https://nixos.org/manual/nixpkgs/unstable/#tester-runNixOSTest
runNixOSTest =
let nixos = import ../../../nixos/lib {};
in testModule:
nixos.runTest {
_file = "pkgs.runNixOSTest implementation";
imports = [
(lib.setDefaultModuleLocation "the argument that was passed to pkgs.runNixOSTest" testModule)
];
hostPkgs = pkgs;
node.pkgs = pkgs;
};
# See doc/builders/testers.chapter.md or
# https://nixos.org/manual/nixpkgs/unstable/#tester-invalidateFetcherByDrvHash
nixosTest =

View File

@ -14,6 +14,17 @@ in
lib.recurseIntoAttrs {
hasPkgConfigModule = pkgs.callPackage ../hasPkgConfigModule/tests.nix { };
runNixOSTest-example = pkgs-with-overlay.testers.runNixOSTest ({ lib, ... }: {
name = "runNixOSTest-test";
nodes.machine = { pkgs, ... }: {
system.nixos = dummyVersioning;
environment.systemPackages = [ pkgs.proof-of-overlay-hello pkgs.figlet ];
};
testScript = ''
machine.succeed("hello | figlet >/dev/console")
'';
});
# Check that the wiring of nixosTest is correct.
# Correct operation of the NixOS test driver should be asserted elsewhere.
nixosTest-example = pkgs-with-overlay.testers.nixosTest ({ lib, pkgs, figlet, ... }: {