You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.8 KiB
Bash
100 lines
3.8 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# Run backend integration tests (Rust).
|
|
# Uses the e2e/docker-compose.test.yml for Postgres (port 5433).
|
|
#
|
|
# Usage:
|
|
# ./scripts/run-integration-tests.sh # all tests
|
|
# ./scripts/run-integration-tests.sh --test pipeline_test # one test file
|
|
# ./scripts/run-integration-tests.sh --test api_admin_test config_providers # one test by name
|
|
# ./scripts/run-integration-tests.sh --lib # unit tests only
|
|
# ./scripts/run-integration-tests.sh --db-check # just check DB connectivity
|
|
#
|
|
# All arguments (except --db-check) are passed directly to `cargo test`.
|
|
#
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
|
E2E_DIR="$PROJECT_DIR/e2e"
|
|
|
|
PG_HOST="127.0.0.1"
|
|
PG_PORT=5433
|
|
PG_USER="ai_synth_test"
|
|
PG_PASS="testpassword"
|
|
PG_DB="ai_synth_test"
|
|
|
|
export TEST_DATABASE_URL="postgres://${PG_USER}:${PG_PASS}@${PG_HOST}:${PG_PORT}/${PG_DB}"
|
|
export SKIP_SSRF_CHECK=1 # Allow wiremock on localhost for pipeline tests
|
|
|
|
# ── DB check mode ──────────────────────────────────────────────────
|
|
if [ "${1:-}" = "--db-check" ]; then
|
|
echo "Checking DB connectivity at ${PG_HOST}:${PG_PORT}..."
|
|
if docker exec ai-synth-test-db pg_isready -U "$PG_USER" -d "$PG_DB" 2>/dev/null; then
|
|
echo "DB is ready."
|
|
echo "Testing SQL query..."
|
|
docker exec ai-synth-test-db psql -U "$PG_USER" -d "$PG_DB" -c "SELECT 1 AS ok" 2>&1
|
|
echo ""
|
|
echo "Testing connection from host..."
|
|
if command -v psql >/dev/null 2>&1; then
|
|
PGPASSWORD="$PG_PASS" psql -h "$PG_HOST" -p "$PG_PORT" -U "$PG_USER" -d "$PG_DB" -c "SELECT 1 AS ok" 2>&1 || echo "Host psql connection failed"
|
|
else
|
|
echo "(psql not installed on host, skipping host connection test)"
|
|
fi
|
|
else
|
|
echo "DB container not running. Start it with:"
|
|
echo " cd $E2E_DIR && docker compose -f docker-compose.test.yml up -d db"
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
# ── Start DB if not running ────────────────────────────────────────
|
|
echo "=== Ensuring test Postgres is running ==="
|
|
cd "$E2E_DIR"
|
|
|
|
# Start only the DB service (not the app)
|
|
docker compose -f docker-compose.test.yml up -d db
|
|
|
|
echo "Waiting for Postgres to be ready..."
|
|
for i in $(seq 1 30); do
|
|
if docker exec ai-synth-test-db pg_isready -U "$PG_USER" -d "$PG_DB" >/dev/null 2>&1; then
|
|
echo "Postgres is ready on port ${PG_PORT}."
|
|
break
|
|
fi
|
|
if [ "$i" -eq 30 ]; then
|
|
echo "ERROR: Postgres did not become ready in time."
|
|
docker compose -f docker-compose.test.yml logs db | tail -10
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
# Verify connectivity from host
|
|
echo "Verifying host connectivity..."
|
|
cd "$PROJECT_DIR/backend"
|
|
if ! cargo sqlx database exists "$TEST_DATABASE_URL" 2>/dev/null; then
|
|
# sqlx-cli not installed, try a simple Rust connection test
|
|
echo "(sqlx-cli not available, will rely on cargo test to verify connectivity)"
|
|
fi
|
|
|
|
# ── Run tests ──────────────────────────────────────────────────────
|
|
echo ""
|
|
echo "=== Running integration tests ==="
|
|
echo "TEST_DATABASE_URL=$TEST_DATABASE_URL"
|
|
echo ""
|
|
|
|
if [ $# -gt 0 ]; then
|
|
echo "Running: cargo test $*"
|
|
cargo test "$@"
|
|
else
|
|
echo "Running: cargo test (all integration + unit tests)"
|
|
cargo test
|
|
fi
|
|
|
|
echo ""
|
|
echo "=== Tests complete ==="
|
|
echo ""
|
|
echo "Note: DB container is still running. To stop it:"
|
|
echo " cd $E2E_DIR && docker compose -f docker-compose.test.yml down"
|