diff options
| author | tv <tv@krebsco.de> | 2026-11-11 21:25:03 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-11 21:25:03 +0000 |
| commit | a018f44c9132ffa5c7b987369010868d0bc95c74 (patch) | |
| tree | 62f59ff4cb8c3b44978eb6485153ecb25b742876 /tests/lib.sh | |
| parent | 1dc0ba39d8103e072d8cc8676f0ac19dbe3f8e1b (diff) | |
tests: add NixOS VM tests for populate
tests/default.nix provides one VM test per source type, and one for
features spanning sources. Each test runs scenarios from
tests/scenarios.nix, which cover every combination of a source type's
options, deployed to the deploying machine itself, to a remote target as
root, and to a remote target using sudo. A scenario prepares the target
directory, deploys, checks the result, and deploys and checks again.
Scenarios expecting populate to fail check its error message, or check
at evaluation time if populate is expected not to evaluate.
The deploying machine creates fixtures using tests/fixtures.sh and serves
them via HTTP and git daemon, so flakes can be fetched on the target
without further network access. Checks evaluate delivered flakes without
network access to the fixtures after collecting garbage, so they verify
that the delivered store paths are complete and rooted.
Diffstat (limited to 'tests/lib.sh')
| -rw-r--r-- | tests/lib.sh | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/lib.sh b/tests/lib.sh new file mode 100644 index 0000000..13b1ded --- /dev/null +++ b/tests/lib.sh @@ -0,0 +1,43 @@ +# Helpers for preparing and checking scenarios, sourced on the machine +# populate deploys to. +set -efu + +fail() { + printf 'FAIL: %s\n' "$*" >&2 + exit 1 +} + +# usage: expect_eq WHAT ACTUAL EXPECTED +expect_eq() { + if test "$2" != "$3"; then + fail "$1: expected '$3', got '$2'" + fi +} + +nix() { + command nix --extra-experimental-features 'nix-command flakes' "$@" +} + +# Evaluates a flake output without network access to the fixtures, so all +# inputs must be in the store. +nix_eval() { + env \ + http_proxy=http://127.0.0.1:9 https_proxy=http://127.0.0.1:9 \ + HTTP_PROXY=http://127.0.0.1:9 HTTPS_PROXY=http://127.0.0.1:9 \ + all_proxy=http://127.0.0.1:9 ALL_PROXY=http://127.0.0.1:9 \ + no_proxy= NO_PROXY= \ + nix --extra-experimental-features 'nix-command flakes' eval --raw "$@" +} + +# Evaluates a flake output, fetching missing inputs. +nix_eval_online() { + nix eval --raw "$@" +} + +# Collects garbage if KROPS_TEST_GC is set, so evaluating afterwards checks +# that delivered store paths are registered as garbage collector roots. +gc() { + if test -n "${KROPS_TEST_GC-}"; then + nix-store --gc >/dev/null + fi +} |
