#!/bin/bash # Test Environment Setup Script # Starts isolated Docker containers for integration testing set -e echo "🚀 Starting ML Training Service Test Environment..." # Navigate to docker directory SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd "$SCRIPT_DIR" # Stop any existing containers echo "📦 Cleaning up existing test containers..." docker-compose -f docker-compose.test.yml down -v 2>/dev/null || true # Start fresh containers echo "🐳 Starting PostgreSQL and Redis test containers..." docker-compose -f docker-compose.test.yml up -d # Wait for PostgreSQL to be ready echo "⏳ Waiting for PostgreSQL to be ready..." until docker exec foxhunt-postgres-test pg_isready -U foxhunt_test > /dev/null 2>&1; do echo " Waiting for PostgreSQL..." sleep 1 done echo "✅ PostgreSQL is ready" # Wait for Redis to be ready echo "⏳ Waiting for Redis to be ready..." until docker exec foxhunt-redis-test redis-cli ping > /dev/null 2>&1; do echo " Waiting for Redis..." sleep 1 done echo "✅ Redis is ready" # Export test database URL export DATABASE_URL="postgresql://foxhunt_test:foxhunt_test_password@localhost:5433/foxhunt_test" export REDIS_URL="redis://localhost:6380" echo "" echo "✅ Test environment ready!" echo "" echo "Environment variables:" echo " DATABASE_URL=$DATABASE_URL" echo " REDIS_URL=$REDIS_URL" echo "" echo "Run integration tests with:" echo " cargo test --test integration --features minimal -- --test-threads=1" echo "" echo "Stop test environment with:" echo " ./test_teardown.sh"