diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-10-30 15:15:04 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-10-30 15:15:04 +0100 |
| commit | 43dac390967e2e85da0b3fcd84043a77cfaddfd0 (patch) | |
| tree | 93f09b804bcded8b59db6f619e18ec4b6265b8c2 /tests/old/README.md | |
| parent | treewide: Align files with the same files in the `nixos-server` repo (diff) | |
| download | nixos-config-43dac390967e2e85da0b3fcd84043a77cfaddfd0.zip | |
treewide: Align the rest of the files with the server repository
Diffstat (limited to 'tests/old/README.md')
| -rw-r--r-- | tests/old/README.md | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/tests/old/README.md b/tests/old/README.md new file mode 100644 index 00000000..34dc9255 --- /dev/null +++ b/tests/old/README.md @@ -0,0 +1,109 @@ +<!-- +nixos-config - My current NixOS configuration + +Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +SPDX-License-Identifier: GPL-3.0-or-later + +This file is part of my nixos-config. + +You should have received a copy of the License along with this program. +If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. +--> + +# How to write a test + +Test are simple derivations, put into the `by-name` directory. As you +often want to test configuration, the 'standard' nixos-vm-test function +starts a vm with the specified configuration and lets you run a python +test script. + +But, I've noticed, that most of my tests in this nixos-configuration are +actually testing the home-manager config of a program. As such I've built +a test infrastructure on top of the pre-existing nixos-vm-tests. It is +further described in the `mkTest` section. + +## `mkTest` + +A standard application test would look somewhat like this: + +```nix +{mkTest}: +mkTest { + name = "my-tests"; + + # The configuration to add. + # In this case, the less config is being tested. + configuration = { + imports = [ + ../../../../modules/by-name/le/less/module.nix + ]; + config.soispha.programs.less.enable = true; + }; + + # Files that are provided at the test directory. + # In this case, the test dir would have a `./data/test.file` + # path pre-populated with the + # contents of the file at the lhs. + testData = { + "data/test.file" = ./data/test.file; + }; + + # The description of what to do in the test. + description = ./test.desc; + + # A sha256 hashsum of the concatenated output of the program. + # This can be `null` to disable the checksum mechanism. + hash = "87901231393b51cdd45bbb4339a32db2894a3a5ab164cb5c7a8fa14721fdcba7"; +} +``` + +### The test description file + +All line starting with `#` or only containing white space are +ignored. Additionally, all leading and trailing white space is stripped +before evaluating. + +The general syntax is: + +``` +COMMAND ARGS +``` + +where `COMMAND` is one of the commands listed in [Commands](#commands) + +The `ARGS` are the verbatim content from the space after the `COMMAND` +to the end of line character. + +You can run the description file, similarly as in the tests via the `run_test_description` +package exported by the flake. + +#### Commands + +##### `Type` + +Send the `ARGS` to the application. This interprets `ARGS` as specified +by the TMUX (1) man page on `send-keys`. + +#### `Sleep` + +Sleep for `ARGS` seconds. + +#### `Expect` + +Grep the currently visible screen for the regex `ARGS`. This regex +must match. + +#### `ExpectNot` + +Does the same thing as [Expect](#expect), but enforces, that the +regex does not match. + +#### `SetGolden` + +Set the golden file (the file used for the hash generation) to `ARGS`. +`ARGS` must be a valid file path. + +#### `Exec` + +Executes the command (`ARGS`) and waits until it finishes. +This will hang forever, when the command that does not exit. |
