Files
ukmesh/scripts/test-healthcheck-backup.sh

24 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
umask 077
repo=$(cd "$(dirname "$0")/.." && pwd)
work=$(mktemp -d)
trap 'rm -rf -- "$work"' EXIT
mkdir "$work/source"
printf '{}\n' > "$work/source/observer.json"
for results in '[]' '{"version":1,"sessions":[]}'; do
printf '%s\n' "$results" > "$work/source/session-results.json"
node "$repo/scripts/lib/healthcheck-snapshot.cjs" "$work/source" > "$work/snapshot.json"
bash "$repo/scripts/lib/restore-healthcheck.sh" "$work/snapshot.json" "$work/restore"
for name in observer.json session-results.json; do cmp "$work/source/$name" "$work/restore/$name"; done
rm -r "$work/restore"
done
printf 'invalid-private-sentinel' > "$work/source/observer.json"
if node "$repo/scripts/lib/healthcheck-snapshot.cjs" "$work/source" > "$work/stdout" 2> "$work/stderr"; then exit 1; fi
test ! -s "$work/stdout"
if grep -q sentinel "$work/stderr"; then exit 1; fi
rm "$work/source/observer.json"
ln -s session-results.json "$work/source/observer.json"
if node "$repo/scripts/lib/healthcheck-snapshot.cjs" "$work/source" >/dev/null 2>&1; then exit 1; fi
echo "Health Check backup and restore cases passed"