diff options
| author | tv <tv@krebsco.de> | 2026-11-12 02:15:26 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-12 02:15:26 +0000 |
| commit | d4c352a402aec1682625144c0440ca31c232ee74 (patch) | |
| tree | 898da22caf12a75227fe517c6f7330ffa840b032 /tests/scenarios.nix | |
| parent | 1c7621261c4e9df8d572aef5eb6369d20eea23aa (diff) | |
tests: add edge cases of flakes
A new test, edge-cases, covers paths that work but have no scenario yet:
a flake given by an indirect reference, which the target fetches by its
locked reference; a remote flake in a subdirectory; a flake in a
subdirectory drawing inputs from sources; a dirty Git work tree; a flake
whose lock file needs updating; drawing inputs from a source that isn't
a directory; nested names of missing inputs; several sources sharing one
flake; and an input locked to a path that the target has.
The deploying machine gets a registry entry for the indirect reference.
Resolving it fails if the global registry can't be downloaded, which it
can't in the VM, and disabling the global registry with flake-registry
needs flakes, so the deploying machine enables them, like any deploying
machine using indirect references does. The target doesn't, so checks
for flake support on targets still mean something.
Diffstat (limited to 'tests/scenarios.nix')
| -rw-r--r-- | tests/scenarios.nix | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/scenarios.nix b/tests/scenarios.nix index d8081d3..ef80d05 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -692,4 +692,96 @@ assert !(krops.isLocalTarget (targets.remote "/")); }) ]) targetKinds; + # Edge cases of the flake source types and of generated flakes: unusual lock + # files, references, and changes between deploys. + edge-cases = concatMap (targetKind: let + s = name: args: scenario ({ + name = "${name}-${targetKind}"; + inherit targetKind; + isolate = true; + } // args); + copying = targetKind != "sudo"; + fetchOnTarget = !copying; + roots = n: '' + expect_eq roots "$(ls "$T"/.populate/flake-inputs/x 2>/dev/null | wc -l)" ${toString n} + ''; + in [ + # The registry entry kropsremote, which fixtures.sh adds on the deploying + # machine, points at ${url}/remote.tar.gz. The deploying machine has no + # global registry, which it couldn't download. + (s "indirect" { + phases = twice { + sources.x.flake = { flake = "kropsremote"; inherit fetchOnTarget; }; + check = checkFlake { attr = "msg"; expected = "remote:dep+inner"; }; + }; + }) + (s "remote-subdir" { + phases = twice { + sources.x.flake = { flake = "${url}/mono.tar.gz?dir=sub"; inherit fetchOnTarget; }; + check = checkFlake { attr = "who"; expected = "sub"; subdir = true; }; + }; + }) + (s "subdir-inputs" { + phases = twice { + sources = alt // { + x.flake = { + flake = "git+file:/fixtures/monoin?dir=sub"; inherit fetchOnTarget; + inputs.dep.follows = "alt"; + }; + }; + check = checkFlake { attr = "msg"; expected = "monoin:alt"; subdir = true; generated = true; }; + }; + }) + (s "dirty" { + phases = twice { + sources.x.flake = { flake = "/fixtures/dirty"; inherit fetchOnTarget; }; + check = checkFlake { attr = "msg"; expected = "dirty:dep+inner,sub"; } + '' + test ! -e "$T"/x/untracked || fail "untracked file delivered" + ''; + }; + }) + (s "unlocked" { + phases = [{ + sources.x.flake = { flake = "/fixtures/unlocked"; inherit fetchOnTarget; }; + expect.fail = "requires lock file changes"; + }]; + }) + (s "notdir" { + phases = [{ + sources = { + x.file = { path = "/fixtures/filesrc"; inputs.dep.follows = "p"; }; + p.pipe = "/fixtures/pipe"; + }; + expect.fail = "error: source p is not a directory"; + }]; + }) + (s "noinput-nested" { + phases = [{ + sources.x.flake-input = { flake = "/fixtures/top"; name = "dep/nope"; inherit fetchOnTarget; }; + expect.fail = "error: flake /fixtures/top has no input dep/nope"; + }]; + }) + (s "shared" { + phases = twice { + sources = { + x.flake = { flake = "/fixtures/top"; inherit fetchOnTarget; }; + dep.flake-input = { flake = "/fixtures/top"; name = "dep"; inherit fetchOnTarget; }; + sub.flake-input = { flake = "/fixtures/top"; name = "sub"; fetchOnTarget = true; }; + }; + check = checkFlake { attr = "msg"; expected = "top:dep+inner,sub"; } + '' + expect_eq dep "$(nix_eval "$T"/dep#greeting)" dep+inner + expect_eq sub "$(nix_eval "$T"/sub#who)" sub + ''; + }; + }) + ] ++ lib.optional (targetKind == "local") + # The target has the path the input is locked to. + (s "uselocal" { + phases = twice { + sources.x.flake = { flake = "/fixtures/uselocal"; fetchOnTarget = true; }; + check = checkFlake { attr = "msg"; expected = "uselocal:alt"; }; + }; + }) + ) targetKinds; + } |
