forked from baron/baron-sso
kratos SSOT 재설계
This commit is contained in:
76
test/restore_input_path_test.sh
Executable file
76
test/restore_input_path_test.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
tmp_dir="$(mktemp -d /tmp/baron-sso-restore-input.XXXXXX)"
|
||||
|
||||
cleanup() {
|
||||
rm -rf "$tmp_dir"
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
fail() {
|
||||
echo "ERROR: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
assert_contains() {
|
||||
local output="$1"
|
||||
local expected="$2"
|
||||
grep -Fq -- "$expected" <<<"$output" || fail "output must contain: $expected"
|
||||
}
|
||||
|
||||
run_restore_plan() {
|
||||
local output
|
||||
output="$("$@" 2>&1)"
|
||||
assert_contains "$output" "Restore plan for"
|
||||
assert_contains "$output" "Services: config"
|
||||
}
|
||||
|
||||
backup_dir="$tmp_dir/baron-sso-backup-test"
|
||||
mkdir -p "$backup_dir"
|
||||
printf '{"restore_policy":{}}\n' >"$backup_dir/manifest.json"
|
||||
|
||||
tar_zst="$tmp_dir/baron-sso-backup-test.tar.zst"
|
||||
tar_gz="$tmp_dir/baron-sso-backup-test.tar.gz"
|
||||
zip_file="$tmp_dir/baron-sso-backup-test.zip"
|
||||
unsupported_file="$tmp_dir/baron-sso-backup-test.tar.bz2"
|
||||
|
||||
tar --zstd -cf "$tar_zst" -C "$tmp_dir" "$(basename "$backup_dir")"
|
||||
tar -czf "$tar_gz" -C "$tmp_dir" "$(basename "$backup_dir")"
|
||||
(cd "$tmp_dir" && python3 -m zipfile -c "$zip_file" "$(basename "$backup_dir")")
|
||||
: >"$unsupported_file"
|
||||
|
||||
run_restore_plan \
|
||||
env RESTORE_INPUT="$backup_dir" RESTORE_SERVICES=config CONFIRM_RESTORE=baron-sso RESTORE_REPORT="$tmp_dir/dir-report.json" \
|
||||
"$repo_root/scripts/backup/restore.sh" --dry-run
|
||||
|
||||
run_restore_plan \
|
||||
env RESTORE_INPUT="$tar_zst" RESTORE_SERVICES=config CONFIRM_RESTORE=baron-sso RESTORE_REPORT="$tmp_dir/tar-zst-report.json" \
|
||||
"$repo_root/scripts/backup/restore.sh" --dry-run
|
||||
|
||||
run_restore_plan \
|
||||
env RESTORE_INPUT="$tar_gz" RESTORE_SERVICES=config CONFIRM_RESTORE=baron-sso RESTORE_REPORT="$tmp_dir/tar-gz-report.json" \
|
||||
"$repo_root/scripts/backup/restore.sh" --dry-run
|
||||
|
||||
run_restore_plan \
|
||||
env RESTORE_INPUT="$zip_file" RESTORE_SERVICES=config CONFIRM_RESTORE=baron-sso RESTORE_REPORT="$tmp_dir/zip-report.json" \
|
||||
"$repo_root/scripts/backup/restore.sh" --dry-run
|
||||
|
||||
run_restore_plan \
|
||||
env DUMP_FILE="$zip_file" RESTORE_SERVICES=config CONFIRM_RESTORE=baron-sso RESTORE_REPORT="$tmp_dir/direct-zip-report.json" \
|
||||
"$repo_root/scripts/backup/restore.sh" --dry-run
|
||||
|
||||
if env RESTORE_INPUT="$unsupported_file" RESTORE_SERVICES=config CONFIRM_RESTORE=baron-sso RESTORE_REPORT="$tmp_dir/unsupported-report.json" \
|
||||
"$repo_root/scripts/backup/restore.sh" --dry-run >/tmp/baron-sso-restore-unsupported.out 2>&1; then
|
||||
fail "unsupported restore archive extension must fail."
|
||||
fi
|
||||
assert_contains "$(cat /tmp/baron-sso-restore-unsupported.out)" "unsupported restore input file extension"
|
||||
|
||||
if env RESTORE_INPUT="$backup_dir" BACKUP="$backup_dir" RESTORE_SERVICES=config CONFIRM_RESTORE=baron-sso RESTORE_REPORT="$tmp_dir/ambiguous-report.json" \
|
||||
"$repo_root/scripts/backup/restore.sh" --dry-run >/tmp/baron-sso-restore-ambiguous.out 2>&1; then
|
||||
fail "ambiguous restore inputs must fail."
|
||||
fi
|
||||
assert_contains "$(cat /tmp/baron-sso-restore-ambiguous.out)" "set only one restore input"
|
||||
|
||||
echo "OK: restore input path inference supports directories, tar archives, and zip archives"
|
||||
Reference in New Issue
Block a user