#!/usr/bin/env bash set -euo pipefail # Config matches examples/tests PGHOST=${PGHOST:-localhost} PGPORT=${PGPORT:-5432} PGUSER=${PGUSER:-postgres} PGPASSWORD=${PGPASSWORD:-test123} export PGPASSWORD echo "[test.sh] Checking Postgres at ${PGHOST}:${PGPORT} (user=${PGUSER})..." # Require pg_isready if ! command -v pg_isready >/dev/null 2>&1; then echo "[test.sh] ERROR: pg_isready not found. Install PostgreSQL client tools (e.g., brew install libpq && brew link --force libpq)." >&2 exit 1 fi # Wait for Postgres to be ready (30s timeout) ATTEMPTS=30 until pg_isready -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" >/dev/null 2>&1; do ((ATTEMPTS--)) || { echo "[test.sh] ERROR: Postgres not ready after 30s. Ensure it's running with user=$PGUSER password=$PGPASSWORD host=$PGHOST port=$PGPORT." >&2 exit 1 } sleep 1 echo "[test.sh] Waiting for Postgres..." done echo "[test.sh] Postgres is ready. Running tests..." # Run fast OurDB test first (no Postgres dependency) echo "[test.sh] Running OurDB test: grid4_ourdb" cargo test -p heromodels --test grid4_ourdb # Run Postgres-backed tests (marked ignored) echo "[test.sh] Running Postgres test: heroledger_postgres (ignored)" cargo test -p heromodels --test heroledger_postgres -- --ignored echo "[test.sh] Running Postgres test: grid4_postgres (ignored)" cargo test -p heromodels --test grid4_postgres -- --ignored echo "[test.sh] Done."