Initial commit
This commit is contained in:
61
scripts/smoke-real.sh
Executable file
61
scripts/smoke-real.sh
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
PG_BIN="${PG_BIN:-/opt/homebrew/opt/postgresql@17/bin}"
|
||||
SMOKE_PORT="${SMOKE_PORT:-18081}"
|
||||
TEST_DB="queue_phone_smoke_$$"
|
||||
API_PID=""
|
||||
API_LOG="${TMPDIR:-/tmp}/${TEST_DB}.log"
|
||||
API_BIN="${TMPDIR:-/tmp}/${TEST_DB}-api"
|
||||
|
||||
cleanup() {
|
||||
if [[ -n "$API_PID" ]] && kill -0 "$API_PID" 2>/dev/null; then
|
||||
kill -TERM "$API_PID" 2>/dev/null || true
|
||||
wait "$API_PID" 2>/dev/null || true
|
||||
fi
|
||||
"$PG_BIN/dropdb" --if-exists --force "$TEST_DB" >/dev/null 2>&1 || true
|
||||
rm -f "$API_LOG" "$API_BIN"
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
"$PG_BIN/createdb" -O queue "$TEST_DB"
|
||||
|
||||
set -a
|
||||
source "$ROOT_DIR/server/.env"
|
||||
set +a
|
||||
export APP_ENV=development
|
||||
export HTTP_ADDR=":$SMOKE_PORT"
|
||||
export DATABASE_URL="postgres://queue:queue@localhost:5432/$TEST_DB?sslmode=disable"
|
||||
export SESSION_COOKIE_NAME="queue_smoke_session_$$"
|
||||
export SESSION_COOKIE_SECURE=false
|
||||
export ADMIN_PASSWORD="${ADMIN_PASSWORD:-ChangeMe123!}"
|
||||
export ADMIN_USERNAME=smokeadmin
|
||||
export SEED_MODE=smoke
|
||||
export DEMO_DISPLAY_TOKEN="$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')"
|
||||
|
||||
SEED_JSON="$(cd "$ROOT_DIR/server" && go run ./cmd/seed)"
|
||||
DISPLAY_TOKEN="$(printf '%s' "$SEED_JSON" | python3 -c 'import json, sys; projects=json.load(sys.stdin).get("projects", []); print(projects[0]["display_url"].rstrip("/").rsplit("/", 1)[-1])')"
|
||||
|
||||
(cd "$ROOT_DIR/server" && go build -o "$API_BIN" ./cmd/api)
|
||||
"$API_BIN" >"$API_LOG" 2>&1 &
|
||||
API_PID=$!
|
||||
|
||||
READY=0
|
||||
for _ in {1..50}; do
|
||||
if curl -fsS "http://127.0.0.1:$SMOKE_PORT/readyz" >/dev/null 2>&1; then
|
||||
READY=1
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
if [[ "$READY" != "1" ]]; then
|
||||
echo "Real smoke API did not become ready. Log follows:" >&2
|
||||
sed -n '1,160p' "$API_LOG" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
python3 "$ROOT_DIR/scripts/smoke.py" \
|
||||
--base-url "http://127.0.0.1:$SMOKE_PORT" \
|
||||
--admin-username="$ADMIN_USERNAME" \
|
||||
--display-token="$DISPLAY_TOKEN"
|
||||
Reference in New Issue
Block a user