feat: add restore.sh scaffold with arg parsing and usage
This commit is contained in:
Executable
+59
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
RESTORE="$HERE/../restore.sh"
|
||||
FAILURES=0
|
||||
|
||||
assert_eq() {
|
||||
local expected="$1" actual="$2" msg="$3"
|
||||
if [[ "$expected" != "$actual" ]]; then
|
||||
echo "FAIL: $msg (expected '$expected', got '$actual')"
|
||||
FAILURES=$((FAILURES + 1))
|
||||
else
|
||||
echo "PASS: $msg"
|
||||
fi
|
||||
}
|
||||
|
||||
assert_contains() {
|
||||
local haystack="$1" needle="$2" msg="$3"
|
||||
if [[ "$haystack" != *"$needle"* ]]; then
|
||||
echo "FAIL: $msg (expected to contain '$needle', got '$haystack')"
|
||||
FAILURES=$((FAILURES + 1))
|
||||
else
|
||||
echo "PASS: $msg"
|
||||
fi
|
||||
}
|
||||
|
||||
test_help_exits_zero() {
|
||||
local out rc
|
||||
out="$(bash "$RESTORE" -h)"
|
||||
rc=$?
|
||||
assert_eq "0" "$rc" "help exits 0"
|
||||
assert_contains "$out" "Usage:" "help prints usage"
|
||||
}
|
||||
|
||||
test_no_args_exits_one() {
|
||||
local rc
|
||||
bash "$RESTORE" >/dev/null 2>&1
|
||||
rc=$?
|
||||
assert_eq "1" "$rc" "no args exits 1"
|
||||
}
|
||||
|
||||
test_unknown_command_exits_one() {
|
||||
local rc
|
||||
bash "$RESTORE" bogus >/dev/null 2>&1
|
||||
rc=$?
|
||||
assert_eq "1" "$rc" "unknown command exits 1"
|
||||
}
|
||||
|
||||
test_help_exits_zero
|
||||
test_no_args_exits_one
|
||||
test_unknown_command_exits_one
|
||||
|
||||
echo "-----"
|
||||
if [[ "$FAILURES" -gt 0 ]]; then
|
||||
echo "$FAILURES failure(s)"
|
||||
exit 1
|
||||
fi
|
||||
echo "All tests passed"
|
||||
Reference in New Issue
Block a user