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.
69 lines
1.8 KiB
Bash
69 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# Run backend integration tests (Rust).
|
|
# Starts a Postgres container, runs tests, then cleans up.
|
|
#
|
|
# Usage:
|
|
# ./scripts/run-integration-tests.sh # run all integration tests
|
|
# ./scripts/run-integration-tests.sh pipeline # run only pipeline_test
|
|
#
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
|
|
|
CONTAINER_NAME="ai-synth-integration-db"
|
|
PG_PORT=5434
|
|
PG_USER="test_user"
|
|
PG_PASS="test_password"
|
|
PG_DB="postgres"
|
|
|
|
cleanup() {
|
|
echo "Cleaning up..."
|
|
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
echo "=== Starting Postgres for integration tests ==="
|
|
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
|
docker run -d \
|
|
--name "$CONTAINER_NAME" \
|
|
-e POSTGRES_USER="$PG_USER" \
|
|
-e POSTGRES_PASSWORD="$PG_PASS" \
|
|
-e POSTGRES_DB="$PG_DB" \
|
|
-p "127.0.0.1:${PG_PORT}:5432" \
|
|
--health-cmd "pg_isready -U $PG_USER -d $PG_DB" \
|
|
--health-interval 5s \
|
|
--health-timeout 3s \
|
|
--health-retries 10 \
|
|
postgres:17-alpine
|
|
|
|
echo "Waiting for Postgres to be ready..."
|
|
for i in $(seq 1 30); do
|
|
if docker exec "$CONTAINER_NAME" pg_isready -U "$PG_USER" -d "$PG_DB" >/dev/null 2>&1; then
|
|
echo "Postgres is ready."
|
|
break
|
|
fi
|
|
if [ "$i" -eq 30 ]; then
|
|
echo "ERROR: Postgres did not become ready in time."
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
export TEST_DATABASE_URL="postgres://${PG_USER}:${PG_PASS}@127.0.0.1:${PG_PORT}/${PG_DB}"
|
|
|
|
echo "=== Running integration tests ==="
|
|
cd "$PROJECT_DIR/backend"
|
|
|
|
if [ $# -gt 0 ]; then
|
|
echo "Running: cargo test --test $1 -- --nocapture"
|
|
cargo test --test "$1" -- --nocapture
|
|
else
|
|
echo "Running: cargo test (all integration + unit tests)"
|
|
cargo test -- --nocapture
|
|
fi
|
|
|
|
echo "=== All tests passed ==="
|