testers.runNixOSTest: init
An up to date alternative to pkgs.nixosTest
This commit is contained in:
parent
6948ef4def
commit
ac1134f321
3 changed files with 45 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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, ... }: {
|
||||
|
|
Loading…
Reference in a new issue