template-monorepo/scripts/e2e-up.sh

63 lines
2.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 啟動 E2E 環境但不跑測試(方便本機除錯)
#
# E2E_WITH_SMTP=1 多起一個 MailHoghttp://localhost:8025
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
# shellcheck source=scripts/e2e-lib.sh
source "${ROOT}/scripts/e2e-lib.sh"
cd "$ROOT"
E2E_CONFIG="${E2E_CONFIG:-test/e2e/fixtures/e2e.yaml}"
E2E_STATE="${E2E_STATE:-${ROOT}/test/e2e/fixtures/state.json}"
GATEWAY_PORT="${GATEWAY_PORT:-18888}"
PID_FILE="${PID_FILE:-${ROOT}/test/e2e/fixtures/gateway.pid}"
E2E_WITH_SMTP="${E2E_WITH_SMTP:-}"
e2e_step "1/5" "fresh docker compose"
docker compose down -v >/dev/null 2>&1 || true
if [[ "$E2E_WITH_SMTP" == "1" ]]; then
docker compose --profile smtp up -d mongo redis mailhog
else
docker compose up -d mongo redis
fi
e2e_step "2/5" "wait for healthcheck"
for i in $(seq 1 60); do
if docker compose ps mongo 2>/dev/null | grep -q "(healthy)" && docker compose ps redis 2>/dev/null | grep -q "(healthy)"; then
e2e_ok "mongo / redis healthy${i}s"
break
fi
sleep 1
done
e2e_step "3/5" "建立 Mongo 索引"
go run ./cmd/mongo-index -f "${E2E_CONFIG}"
e2e_ok "indexes ready"
e2e_step "4/5" "seed E2E 資料 + JWT"
go run ./cmd/e2e-seed -f "${E2E_CONFIG}" -out "${E2E_STATE}"
e2e_ok "state.json written"
e2e_step "5/5" "啟動 Gateway:${GATEWAY_PORT}"
if [[ -f "${PID_FILE}" ]] && kill -0 "$(cat "${PID_FILE}")" 2>/dev/null && curl -sf "http://127.0.0.1:${GATEWAY_PORT}/api/v1/health" >/dev/null; then
e2e_warn "gateway already running pid=$(cat "${PID_FILE}")"
else
pid="$(e2e_start_gateway "${ROOT}" "${E2E_CONFIG}" "${GATEWAY_PORT}" "${PID_FILE}")"
e2e_ok "gateway started pid=${pid}"
fi
e2e_wait_gateway "${GATEWAY_PORT}"
e2e_print_services "$E2E_WITH_SMTP"
echo "${E2E_BOLD}下一步${E2E_RESET}"
echo " ${E2E_DIM}# 列出有哪些 E2E 測試${E2E_RESET}"
echo " make e2e-list"
echo " ${E2E_DIM}# 全部測試(每個會顯示 ▶ [ID] METHOD path — 中文情境)${E2E_RESET}"
echo " make test-e2e"
echo " ${E2E_DIM}# 單一測試${E2E_RESET}"
echo " GATEWAY_E2E=1 go test -tags=e2e -v -count=1 ./test/e2e/ -run TestMember_GetMe"
echo " ${E2E_DIM}# 結束${E2E_RESET}"
echo " make e2e-down"