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.
74 lines
2.1 KiB
Bash
74 lines
2.1 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 # 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 --test api_admin_test -- --test-threads=1 # extra cargo args
|
|
# ./scripts/run-integration-tests.sh --lib # unit tests only
|
|
#
|
|
# All arguments are passed directly to `cargo 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 $*"
|
|
cargo test "$@"
|
|
else
|
|
echo "Running: cargo test (all integration + unit tests)"
|
|
cargo test
|
|
fi
|
|
|
|
echo "=== All tests passed ==="
|