From 0aced54891ed2d6badd94f8b0071a30e2cd8dafe Mon Sep 17 00:00:00 2001 From: Tobias Kaupat Date: Sat, 17 Oct 2026 23:30:57 +0200 Subject: [PATCH] test: prove restic check actually fails on a corrupted repository compat.sh only grepped the check output for "Check Successful". check.sh prints that string whenever restic exits 0, so a `restic check` that had been turned into a no-op kept the suite green - the integrity check, half the purpose of this image, was untested. Adds a section that backs up, overwrites the first pack file under /mnt/restic/data with garbage and then requires the failure path: "Check Failed with Status", no "Check Successful", and /var/log/check-error-last.log written. It uses its own throwaway container so the later tests do not inherit the broken repository. Verification on Git-Bash: bash test/compat.sh -> 36 passed, 0 failed sabotage (check.sh: restic check -> true), rebuilt image IMAGE=rbd-sab-check bash test/compat.sh -> 33 passed, 3 failed, exit 1 - restic check detects a corrupted repository - a corrupted repository is not reported as successful - failing check writes check-error-last.log check.sh was restored with git checkout and the sabotage image removed. Co-Authored-By: Claude Opus 5 (1M context) Agent-Id: agent-4966d0e6-7f4d-4b37-be3d-0648ed56cb8a --- test/compat.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/compat.sh b/test/compat.sh index fa2f2d8..e261caa 100644 --- a/test/compat.sh +++ b/test/compat.sh @@ -92,6 +92,33 @@ assert_contains "$hook_log" "POST-HOOK-RAN with rc=0" \ stop_container +echo +echo "=== compat: a corrupted repository is reported as failed ===" +# The success path above is not enough: check.sh prints "Check Successful" +# whenever restic exits 0, so a `restic check` that does nothing at all would +# keep this suite green. Damage the repository and require the failure path. +# Runs in its own throwaway container, the repository stays broken afterwards. + +start_container corrupt +wait_for_start || { fail "container starts for the corruption test"; summary "compat"; exit 1; } +write_file /data/hello.txt "backup me" +in_container /bin/backup >/dev/null 2>&1 +assert_eq "1" "$(snapshot_count)" \ + "the repository to be corrupted has a snapshot" + +in_container sh -c 'f=$(find /mnt/restic/data -type f | head -n1); chmod u+w "$f"; printf garbage > "$f"' +broken_check_log="$(in_container /bin/check 2>&1)" +assert_contains "$broken_check_log" "Check Failed with Status" \ + "restic check detects a corrupted repository" +assert_not_contains "$broken_check_log" "Check Successful" \ + "a corrupted repository is not reported as successful" +if in_container test -f /var/log/check-error-last.log; then + pass "failing check writes check-error-last.log" +else + fail "failing check writes check-error-last.log" "file is missing" +fi +stop_container + echo echo "=== compat: RESTIC_FORGET_ARGS ==="