aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-13 20:36:10 +0000
committertv <tv@krebsco.de>2026-11-13 22:01:46 +0100
commitce2cd2553a937d84f1a78386ab28502e89f247d6 (patch)
treefd598a289771894a6eb82157d192a5fa4f784b3f /tests
parent7768c71fd8083ea21572de2859fed39c17524baf (diff)
populate: exit with the status of the command that failed
The shell implementation runs under set -e, so it exits with the status of the command that failed, e.g. 255 if ssh can't reach the target, which wrappers retrying on connection failures rely on, or 128 if git fetch fails. The program does the same, instead of exiting with 1, and with 128 plus the signal for a command a signal ended. A phase's expect.status is the exit status it expects populate to fail with; git-status checks git fetch's.
Diffstat (limited to 'tests')
-rw-r--r--tests/scenarios.nix13
-rw-r--r--tests/vm.nix4
2 files changed, 16 insertions, 1 deletions
diff --git a/tests/scenarios.nix b/tests/scenarios.nix
index 9f1e037..ca2fd20 100644
--- a/tests/scenarios.nix
+++ b/tests/scenarios.nix
@@ -109,7 +109,9 @@ let
# evaluation fail. env sets environment variables for populate, as
# arguments of env. interrupt ends populate after that many seconds,
# which it's expected not to finish before. output lists what a
- # succeeding populate is expected to print.
+ # succeeding populate is expected to print. expect.fail is what a
+ # failing populate is expected to print, and expect.status, if given,
+ # its exit status.
phase = {
sources, backup ? false, prune ? false, deploy ? null,
targetPath ? path, env ? "", interrupt ? null, output ? [],
@@ -149,6 +151,7 @@ let
populate = toString (command sources targetPath);
inherit env interrupt output;
expect = if expect == "success" then null else expect.fail;
+ status = if expect == "success" then null else expect.status or null;
# No phase gets around checking the canaries.
check = script (check + "\ncanary_check\n");
mutate = script mutate;
@@ -2252,6 +2255,14 @@ assert !(krops.isLocalTarget (targets.remote "/"));
}
];
}))
+ # populate exits with the status of the command that failed, here git
+ # fetch's.
+ (s "git-status" {
+ phases = [{
+ sources.x.git = { url = gitUrl; ref = "nonexistent"; };
+ expect = { fail = "couldn't find remote ref"; status = 128; };
+ }];
+ })
# A .git that a materialized flake got, and one that a file source
# keeps, which Nix uses for the git+file: URL of the flake there: writing
# its lock file, Nix runs Git, with that repository's configuration.
diff --git a/tests/vm.nix b/tests/vm.nix
index d7b2f60..25a12a4 100644
--- a/tests/vm.nix
+++ b/tests/vm.nix
@@ -173,6 +173,10 @@ in pkgs.testers.runNixOSTest {
raise Exception(
f"populate {i} doesn't fail with {phase['expect']!r}:\n{out}"
)
+ elif phase["status"] is not None and status != phase["status"]:
+ raise Exception(
+ f"populate {i} exits with {status} instead of {phase['status']}:\n{out}"
+ )
run(node, f"KROPS_TEST_GC=1 sh {phase['check']}")
if phase["checkDeployer"] is not None:
run(deployer, f"sh {phase['checkDeployer']}")