test: make snapshot_count fail loudly on restic errors

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Tobias KaupatandClaude Sonnet 5.5 committed 2026-10-18 10:36:37 +02:00
1 parent 0d841ee98e
commit 66ca99bda3
1 file changed
+9 -2
+9 -2
View File
@@ -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'
}
# ---------------------------------------------------------------------------