diff --git a/tests/alt_mysql_user_restore_post_pre_cleanup_tiers_test.sh b/tests/alt_mysql_user_restore_post_pre_cleanup_tiers_test.sh index 2847b59..cbfb676 100755 --- a/tests/alt_mysql_user_restore_post_pre_cleanup_tiers_test.sh +++ b/tests/alt_mysql_user_restore_post_pre_cleanup_tiers_test.sh @@ -51,4 +51,69 @@ grep -q "CALLED native_staging_migrate" "$CALL_LOG" || fail "expected the native # imported, so it never touches demo_ok again. grep -q "\-\-skip demo_ok" "$CALL_LOG" || fail "expected native-staging-migrate to be told to skip demo_ok, log: $(cat "$CALL_LOG")" +### Scenario A: native-backup-restore script unavailable must not abort the restore. +mkdir -p "$TMP_DIR/fake_bin_a" + +cat > "$TMP_DIR/fake_bin_a/da_restore_native_staging_to_alt_mysql.sh" <<'EOF' +#!/bin/bash +echo "CALLED native_staging_migrate $*" >> "$FAKE_CALL_LOG" +EOF +chmod 755 "$TMP_DIR/fake_bin_a/da_restore_native_staging_to_alt_mysql.sh" + +mkdir -p "$TMP_DIR/empty_restore_root_a" + +CALL_LOG="$TMP_DIR/calls_a.log" +: > "$CALL_LOG" + +DA_ALT_MYSQL_RESTORE_LOG="$TMP_DIR/restore_a.log" \ +DA_ALT_MYSQL_NATIVE_BACKUP_RESTORE_BIN="$TMP_DIR/fake_bin_a/does-not-exist.sh" \ +DA_ALT_MYSQL_NATIVE_STAGING_BIN="$TMP_DIR/fake_bin_a/da_restore_native_staging_to_alt_mysql.sh" \ +DA_ALT_MYSQL_SETTINGS_FILE="$TMP_DIR/missing-settings.conf" \ +FAKE_CALL_LOG="$CALL_LOG" \ +restore_path="$TMP_DIR/empty_restore_root_a" \ +username="demo" \ +bash "$SCRIPT" demo && rc=0 || rc=$? +[ "$rc" -eq 0 ] || fail "expected the hook to exit 0 even when the native-backup-restore script is unavailable, got rc=$rc" + +if grep -q "CALLED native_backup_restore" "$CALL_LOG"; then + fail "did not expect the native-backup-restore tier to be invoked when its script is missing" +fi +grep -q "CALLED native_staging_migrate" "$CALL_LOG" || fail "expected the native-staging-migrate fallback to still run when native-backup-restore is unavailable" + +### Scenario B: zero databases imported must still invoke the fallback, with no stray/malformed --skip argument. +mkdir -p "$TMP_DIR/fake_bin_b" + +cat > "$TMP_DIR/fake_bin_b/alt_mysql_native_backup_restore.sh" <<'EOF' +#!/bin/bash +echo "CALLED native_backup_restore $*" >> "$FAKE_CALL_LOG" +echo "SKIPPED demo_only import-failed" +EOF +chmod 755 "$TMP_DIR/fake_bin_b/alt_mysql_native_backup_restore.sh" + +cat > "$TMP_DIR/fake_bin_b/da_restore_native_staging_to_alt_mysql.sh" <<'EOF' +#!/bin/bash +echo "CALLED native_staging_migrate $*" >> "$FAKE_CALL_LOG" +EOF +chmod 755 "$TMP_DIR/fake_bin_b/da_restore_native_staging_to_alt_mysql.sh" + +mkdir -p "$TMP_DIR/empty_restore_root_b" + +CALL_LOG="$TMP_DIR/calls_b.log" +: > "$CALL_LOG" + +DA_ALT_MYSQL_RESTORE_LOG="$TMP_DIR/restore_b.log" \ +DA_ALT_MYSQL_NATIVE_BACKUP_RESTORE_BIN="$TMP_DIR/fake_bin_b/alt_mysql_native_backup_restore.sh" \ +DA_ALT_MYSQL_NATIVE_STAGING_BIN="$TMP_DIR/fake_bin_b/da_restore_native_staging_to_alt_mysql.sh" \ +DA_ALT_MYSQL_SETTINGS_FILE="$TMP_DIR/missing-settings.conf" \ +FAKE_CALL_LOG="$CALL_LOG" \ +restore_path="$TMP_DIR/empty_restore_root_b" \ +username="demo" \ +bash "$SCRIPT" demo + +grep -q "CALLED native_staging_migrate" "$CALL_LOG" || fail "expected the native-staging-migrate fallback to still run when zero databases were imported" + +if grep "CALLED native_staging_migrate" "$CALL_LOG" | grep -q -- "--skip"; then + fail "did not expect a --skip argument to be passed when zero databases were imported, log: $(cat "$CALL_LOG")" +fi + echo "alt_mysql_user_restore_post_pre_cleanup_tiers_test: OK"