Files
renamer/scripts/smoke-test-remove.sh

70 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BIN="go run"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
mkdir -p "$TMP_DIR/nested"
touch "$TMP_DIR/report copy draft.txt"
touch "$TMP_DIR/nested/notes draft.txt"
echo "Previewing removals..."
preview_output="$($BIN "$ROOT_DIR/main.go" remove " copy" " draft" --path "$TMP_DIR" --recursive --dry-run)"
if [[ "$preview_output" != *"report copy draft.txt -> report.txt"* ]]; then
echo "expected preview to show mapping for report copy draft.txt" >&2
echo "$preview_output" >&2
exit 1
fi
if [[ "$preview_output" != *"Preview complete."* ]]; then
echo "expected preview completion message" >&2
echo "$preview_output" >&2
exit 1
fi
if [[ ! -f "$TMP_DIR/report copy draft.txt" ]]; then
echo "preview should not modify files" >&2
exit 1
fi
echo "Applying removals..."
$BIN "$ROOT_DIR/main.go" remove " copy" " draft" --path "$TMP_DIR" --recursive --yes >/dev/null
if [[ ! -f "$TMP_DIR/report.txt" ]]; then
echo "expected report.txt to exist after removal" >&2
exit 1
fi
if [[ ! -f "$TMP_DIR/nested/notes.txt" ]]; then
echo "expected nested/notes.txt to exist after removal" >&2
exit 1
fi
if [[ -f "$TMP_DIR/report copy draft.txt" ]]; then
echo "source file still exists after apply" >&2
exit 1
fi
echo "Undoing removals..."
$BIN "$ROOT_DIR/main.go" undo --path "$TMP_DIR" >/dev/null
if [[ ! -f "$TMP_DIR/report copy draft.txt" ]]; then
echo "undo failed to restore report copy draft.txt" >&2
exit 1
fi
if [[ ! -f "$TMP_DIR/nested/notes draft.txt" ]]; then
echo "undo failed to restore nested/notes draft.txt" >&2
exit 1
fi
if [[ -f "$TMP_DIR/report.txt" ]]; then
echo "undo failed to clean up report.txt" >&2
exit 1
fi
echo "Remove smoke test succeeded."