Files
sub2api-cn-relay-manager/scripts/test/test_default_data.sh

38 lines
1.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# test_default_data.sh — 验证 setup_default_data.sh 的基本功能
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
info() { echo "INFO: $*"; }
ok() { echo "OK: $*"; }
die() { echo "FAIL: $*" >&2; exit 1; }
# Test 1: --help exits cleanly
info "Test 1: --help"
output="$("$ROOT_DIR/scripts/setup_default_data.sh" --help 2>&1)" || true
echo "$output" | grep -q "CRM_ADMIN_TOKEN" || die "help missing expected content"
ok "Test 1 passed"
# Test 2: --dry-run with no CRM (should still produce help-like output)
info "Test 2: --dry-run"
output="$("$ROOT_DIR/scripts/setup_default_data.sh" --dry-run 2>&1)" || true
echo "$output" | grep -q "dry-run" && ok "Test 2 passed" || warn "dry-run on local machine: $output"
# Test 3: --apply without running CRM should fail gracefully
info "Test 3: --apply without CRM"
output="$("$ROOT_DIR/scripts/setup_default_data.sh" --apply 2>&1)" || true
if echo "$output" | grep -qi "dead\|not healthy\|FATAL"; then
ok "Test 3 passed (correctly rejected)"
else
warn "Test 3 unexpected output: $output"
fi
# Test 4: Script has no syntax errors
info "Test 4: bash syntax check"
bash -n "$ROOT_DIR/scripts/setup_default_data.sh" || die "syntax error"
ok "Test 4 passed"
echo ""
ok "All tests passed"