diff options
Diffstat (limited to 'pkgs/populate/tests')
| -rw-r--r-- | pkgs/populate/tests/lib.sh | 8 | ||||
| -rw-r--r-- | pkgs/populate/tests/scenarios.nix | 77 | ||||
| -rw-r--r-- | pkgs/populate/tests/smoke.nix | 1 |
3 files changed, 86 insertions, 0 deletions
diff --git a/pkgs/populate/tests/lib.sh b/pkgs/populate/tests/lib.sh index a8f2594..0e2ae28 100644 --- a/pkgs/populate/tests/lib.sh +++ b/pkgs/populate/tests/lib.sh @@ -18,6 +18,14 @@ nix() { command nix --extra-experimental-features 'nix-command flakes' "$@" } +# usage: record ATTRPATH +# Prints what's at ATTRPATH, e.g. sources.x.changed, in the record of the +# last run in the target directory $T, as JSON. +record() { + nix-instantiate --eval --json --strict -E \ + "(builtins.fromJSON (builtins.readFile $T/.populate/run.json)).$1" +} + # Evaluates a flake output without network access to the fixtures, so all # inputs must be in the store. An empty cache directory keeps Nix from # restoring inputs from its fetcher cache. diff --git a/pkgs/populate/tests/scenarios.nix b/pkgs/populate/tests/scenarios.nix index 4b7a42b..bd3bf83 100644 --- a/pkgs/populate/tests/scenarios.nix +++ b/pkgs/populate/tests/scenarios.nix @@ -813,6 +813,77 @@ in } ]; })) + # The record of a run: what got delivered, and whether anything changed + # since the last record, also in runs that failed, which leave the + # record as it was. + (s "record" (let + sources = { + g.git = { url = gitUrl; ref = gitHead; }; + l.symlink = "x"; + x.file = "/fixtures/alt"; + }; + # Whether x, and g and l, changed. + changed = x: others: '' + expect_eq changed "$(record changed)" ${if x || others then "true" else "false"} + expect_eq "x changed" "$(record sources.x.changed)" ${lib.boolToString x} + expect_eq "g changed" "$(record sources.g.changed)" ${lib.boolToString others} + expect_eq "l changed" "$(record sources.l.changed)" ${lib.boolToString others} + ''; + in { + phases = [ + { + inherit sources; + check = changed true true + '' + expect_eq version "$(record version)" 0 + expect_eq "x type" "$(record sources.x.type)" '"file"' + expect_eq "g commit" "$(record sources.g.commit)" '"${gitHead}"' + expect_eq "l target" "$(record sources.l.target)" '"x"' + test ! -e "$T"/.populate/journal || fail "journal remains" + ''; + } + { + inherit sources; + check = changed false false + '' + cp "$T"/.populate/run.json "$T".record + ''; + mutate = '' + echo changed > "$T"/x/flake.nix + ''; + } + { + # x, which comes before y, gets delivered again. + sources = sources // { y.pipe = "/run/current-system/sw/bin/false"; }; + expect = { fail = ""; status = 1; }; + check = '' + cmp "$T"/.populate/run.json "$T".record || fail "record changed" + test -e "$T"/.populate/journal || fail "journal missing" + ''; + } + { + # What the failed run changed. + inherit sources; + check = changed true false; + } + ]; + })) + # A consumer of the target directory holding a shared lock delays the + # next run. + (s "lock" { + phases = [ + { + sources.x.file = "/fixtures/alt"; + mutate = '' + setsid flock --shared "$T"/.populate/lock sleep 5 \ + </dev/null >/dev/null 2>&1 & + sleep 1 + ''; + } + { + sources.x.file = "/fixtures/alt"; + output = [ "waiting for the lock on" ]; + } + ]; + }) # A materialized input is a writable copy, patched and with a rewritten # lock file, which gets made again only when what it derives from # changes, and becomes a link again when not materialized anymore. @@ -1819,6 +1890,12 @@ in }) (state "backup" { entry = ".populate/backup"; backup = true; }) (map + (file: state file { + entry = ".populate/${file}"; + message = "/.populate/${file} is a symlink, but populate needs a file of its own there"; + }) + [ "lock" "journal" ]) + (map (entry: state (lib.replaceStrings ["/"] ["-"] entry) { entry = ".populate/${entry}"; }) diff --git a/pkgs/populate/tests/smoke.nix b/pkgs/populate/tests/smoke.nix index 0765c7c..a677469 100644 --- a/pkgs/populate/tests/smoke.nix +++ b/pkgs/populate/tests/smoke.nix @@ -15,6 +15,7 @@ "flake-input-dep-remote-fetchOnTarget0-inputsgenerated-materialize0" "flake-input-sub-local-fetchOnTarget0-materialize0" "state-sentinel-local" + "record-sudo" "prune-remote" "names-local" "paths-local" |
