feat: add non-destructive file-restore mode to restore.sh
This commit is contained in:
@@ -59,10 +59,44 @@ test_list_archives() {
|
||||
rm -rf "$mockdir"
|
||||
}
|
||||
|
||||
test_file_restore_extracts_to_dest() {
|
||||
local mockdir dest out final
|
||||
mockdir="$(mktemp -d)"
|
||||
dest="$(mktemp -d)"
|
||||
setup_mock_bin "$mockdir"
|
||||
out="$(PATH="$mockdir:$PATH" bash "$RESTORE" file photos/img.jpg --dest "$dest")"
|
||||
final="$dest/home/srv/files/content/photos/img.jpg"
|
||||
assert_contains "$out" "Restored file available at: $final" "file mode reports final path"
|
||||
if [[ -f "$final" ]]; then
|
||||
echo "PASS: extracted file exists on disk"
|
||||
else
|
||||
echo "FAIL: extracted file missing at $final"
|
||||
FAILURES=$((FAILURES + 1))
|
||||
fi
|
||||
rm -rf "$mockdir" "$dest"
|
||||
}
|
||||
|
||||
test_file_restore_dry_run_makes_no_borg_call() {
|
||||
local mockdir dest
|
||||
mockdir="$(mktemp -d)"
|
||||
dest="$(mktemp -d)"
|
||||
setup_mock_bin "$mockdir"
|
||||
PATH="$mockdir:$PATH" bash "$RESTORE" file photos/img.jpg --dest "$dest" --dry-run >/dev/null
|
||||
if [[ -s "$mockdir/mock.log" ]] && grep -q "^borg extract" "$mockdir/mock.log"; then
|
||||
echo "FAIL: dry-run invoked borg extract"
|
||||
FAILURES=$((FAILURES + 1))
|
||||
else
|
||||
echo "PASS: dry-run made no borg extract call"
|
||||
fi
|
||||
rm -rf "$mockdir" "$dest"
|
||||
}
|
||||
|
||||
test_help_exits_zero
|
||||
test_no_args_exits_one
|
||||
test_unknown_command_exits_one
|
||||
test_list_archives
|
||||
test_file_restore_extracts_to_dest
|
||||
test_file_restore_dry_run_makes_no_borg_call
|
||||
|
||||
echo "-----"
|
||||
if [[ "$FAILURES" -gt 0 ]]; then
|
||||
|
||||
Reference in New Issue
Block a user