Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
30 lines
1004 B
Bash
Executable File
30 lines
1004 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Runs the store tests against a throwaway Postgres 16 container.
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
# A unique container per run, on a port Docker picks, so concurrent runs never collide.
|
|
name="nmon-test-pg-$$-$RANDOM"
|
|
trap 'docker rm -f "$name" >/dev/null 2>&1 || true' EXIT
|
|
|
|
docker run --rm -d --name "$name" -p "127.0.0.1::5432" \
|
|
-e POSTGRES_USER=nmon -e POSTGRES_PASSWORD=nmon -e POSTGRES_DB=nmon postgres:16 >/dev/null
|
|
port=$(docker port "$name" 5432/tcp | head -n1 | sed 's/.*://')
|
|
|
|
# The image restarts the server once after init, so require two consecutive successes.
|
|
ok=0
|
|
for _ in $(seq 1 60); do
|
|
if docker exec "$name" pg_isready -U nmon -d nmon -q 2>/dev/null; then
|
|
ok=$((ok + 1))
|
|
[ "$ok" -ge 2 ] && break
|
|
else
|
|
ok=0
|
|
fi
|
|
sleep 1
|
|
done
|
|
[ "$ok" -ge 2 ] || { echo "postgres did not become ready" >&2; exit 1; }
|
|
|
|
NMON_TEST_PG_DSN="postgres://nmon:nmon@localhost:$port/nmon?sslmode=disable" \
|
|
go test -race -count=1 ${NMON_TEST_FLAGS:-} ./internal/store/...
|