mirror of
https://github.com/lobaro/restic-backup-docker.git
synced 2026-11-14 16:02:43 +00:00
test: make snapshot_count fail loudly on restic errors
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0d841ee98e
commit
66ca99bda3
1 file changed
+9
-2
+9
-2
@@ -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'
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user