From 66ca99bda30a8afc7b3148c49054f8f7a560b502 Mon Sep 17 00:00:00 2001 From: Tobias Kaupat Date: Sun, 18 Oct 2026 10:36:37 +0200 Subject: [PATCH] test: make snapshot_count fail loudly on restic errors Co-Authored-By: Claude Sonnet 5.5 --- test/lib.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/lib.sh b/test/lib.sh index 5acc01b..a91e79b 100644 --- a/test/lib.sh +++ b/test/lib.sh @@ -176,9 +176,16 @@ write_file() { } # snapshot_count -> number of snapshots in the repository +# A restic error (wrong password, missing repository) is not "zero snapshots": +# the function prints the error text and returns 1, so assert_eq on the result +# fails loudly instead of matching an expected "0". snapshot_count() { - docker exec "$CONTAINER" sh -c \ - 'restic snapshots --json 2>/dev/null | grep -o "\"short_id\"" | wc -l' | tr -d ' \r' + local out + if ! out="$(docker exec "$CONTAINER" restic snapshots --json 2>&1)"; then + echo "restic snapshots failed: $(echo "$out" | tail -n 3 | tr '\n\r' ' ')" + return 1 + fi + printf '%s' "$out" | grep -o '"short_id"' | wc -l | tr -d ' \r' } # ---------------------------------------------------------------------------