Implement nixos-modules/static-page test
All checks were successful
CI / build (push) Successful in 2m40s
All checks were successful
CI / build (push) Successful in 2m40s
This commit is contained in:
parent
c3962b9738
commit
7930f9191d
10 changed files with 180 additions and 15 deletions
17
checks/README.md
Normal file
17
checks/README.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Tests
|
||||
|
||||
## Module Tests
|
||||
|
||||
We test our nixos modules with [NixOS tests](https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests).
|
||||
Running nixos tests requires QEMU virtualisation, so make sure you have KVM virtualisation support enabled.
|
||||
|
||||
Run all: `nix build .#checks.x86_64-linux.nixos-modules`
|
||||
Run single test: `nix build .#checks.x86_64-linux.nixos-modules.entries.vm-test-run-testNameAsInDerivationName`
|
||||
|
||||
### Run Test Interactively
|
||||
|
||||
```bash
|
||||
nix run .#checks.x86_64-linux.nixos-modules.entries.vm-test-run-testNameAsInDerivationName.driverInteractive
|
||||
```
|
||||
|
||||
See [upstream documentation](https://nixos.org/manual/nixos/stable/#sec-running-nixos-tests-interactively) for more details.
|
|
@ -4,7 +4,7 @@
|
|||
pkgs,
|
||||
deployPkgs,
|
||||
...
|
||||
}@inputs:
|
||||
}:
|
||||
{
|
||||
${system} = {
|
||||
|
||||
|
@ -16,6 +16,10 @@
|
|||
mkdir $out
|
||||
'';
|
||||
|
||||
nixos-modules = pkgs.callPackage ./nixos-modules {
|
||||
inherit (self.lib) getSubDirs isFolderWithFile;
|
||||
};
|
||||
|
||||
#TODO(#29): Integration/System tests
|
||||
|
||||
# Import deploy-rs tests
|
||||
|
|
60
checks/nixos-modules/default.nix
Normal file
60
checks/nixos-modules/default.nix
Normal file
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
linkFarmFromDrvs,
|
||||
isFolderWithFile,
|
||||
getSubDirs,
|
||||
lib,
|
||||
testers,
|
||||
}:
|
||||
let
|
||||
inherit (lib)
|
||||
filter
|
||||
path
|
||||
mkDefault
|
||||
readFile
|
||||
attrNames
|
||||
concatStringsSep
|
||||
pipe
|
||||
;
|
||||
modulesBaseDir = ../../nixos-modules;
|
||||
mkTest =
|
||||
name:
|
||||
let
|
||||
getFilePath = file: path.append modulesBaseDir "./${name}/${file}";
|
||||
in
|
||||
testers.runNixOSTest {
|
||||
inherit name;
|
||||
imports = [
|
||||
(import (getFilePath "test.nix") {
|
||||
inherit name;
|
||||
inherit lib;
|
||||
})
|
||||
];
|
||||
|
||||
defaults.imports = [ (getFilePath "default.nix") ];
|
||||
|
||||
# Calls a `test(...)` python function in the test's python file with the list of nodes and helper functions.
|
||||
# Helper symbols may be added as function args when needed and can be found in:
|
||||
# https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/test-driver/src/test_driver/driver.py#L121
|
||||
testScript = mkDefault (
|
||||
{ nodes, ... }:
|
||||
let
|
||||
script = readFile (getFilePath "test.py");
|
||||
nodeArgs = pipe nodes [
|
||||
attrNames
|
||||
(map (val: "${val}=${val}"))
|
||||
(concatStringsSep ", ")
|
||||
];
|
||||
in
|
||||
''
|
||||
${script}
|
||||
test(${nodeArgs}, subtest=subtest)
|
||||
''
|
||||
);
|
||||
};
|
||||
in
|
||||
pipe modulesBaseDir [
|
||||
getSubDirs
|
||||
(filter (isFolderWithFile "test.nix" modulesBaseDir))
|
||||
(map mkTest)
|
||||
(linkFarmFromDrvs "nixos-modules")
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue