Files
relspecgo/tests/integration/run_integration_tests.sh
Hein a427aa5537
Some checks are pending
CI / Test (1.23) (push) Waiting to run
CI / Test (1.24) (push) Waiting to run
CI / Test (1.25) (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Build (push) Waiting to run
More Roundtrip tests
2025-12-17 22:52:24 +02:00

101 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
set -e
# RelSpec Integration Tests Runner
# This script starts a PostgreSQL Podman container and runs integration tests
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
POSTGRES_INIT_DIR="$(cd "$SCRIPT_DIR/../postgres" && pwd)"
echo "=== RelSpec Integration Tests ==="
echo ""
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Container configuration
CONTAINER_NAME="relspec-integration-test-postgres"
POSTGRES_USER="relspec"
POSTGRES_PASSWORD="relspec_test_password"
POSTGRES_DB="relspec_test"
POSTGRES_PORT="5434"
# Check if podman is available
if ! command -v podman &> /dev/null; then
echo -e "${RED}Error: podman is not installed${NC}"
exit 1
fi
# Change to project root
cd "$PROJECT_ROOT"
# Function to cleanup
cleanup() {
echo -e "\n${YELLOW}Cleaning up...${NC}"
podman stop "$CONTAINER_NAME" 2>/dev/null || true
podman rm "$CONTAINER_NAME" 2>/dev/null || true
}
# Trap exit to cleanup
trap cleanup EXIT
# Stop and remove existing container if it exists
echo -e "${YELLOW}Cleaning up any existing containers...${NC}"
podman stop "$CONTAINER_NAME" 2>/dev/null || true
podman rm "$CONTAINER_NAME" 2>/dev/null || true
# Start PostgreSQL container
echo -e "${YELLOW}Starting PostgreSQL container...${NC}"
podman run -d \
--name "$CONTAINER_NAME" \
-e POSTGRES_USER="$POSTGRES_USER" \
-e POSTGRES_PASSWORD="$POSTGRES_PASSWORD" \
-e POSTGRES_DB="$POSTGRES_DB" \
-p "$POSTGRES_PORT:5432" \
docker.io/library/postgres:16-alpine
# Wait for PostgreSQL to be ready
echo -e "${YELLOW}Waiting for PostgreSQL to be ready..${NC}"
max_attempts=30
attempt=0
while [ $attempt -lt $max_attempts ]; do
if podman exec "$CONTAINER_NAME" pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB" &> /dev/null; then
echo -e "${GREEN}PostgreSQL is ready!${NC}"
break
fi
attempt=$((attempt + 1))
echo -n "."
sleep 1
done
if [ $attempt -eq $max_attempts ]; then
echo -e "\n${RED}Error: PostgreSQL failed to start${NC}"
podman logs "$CONTAINER_NAME"
exit 1
fi
# Give it one more second to fully initialize
sleep 2
# Set environment variable for tests
export RELSPEC_TEST_PG_CONN="postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:$POSTGRES_PORT/$POSTGRES_DB"
echo -e "\n${YELLOW}Running integration tests...${NC}"
echo "Connection string: $RELSPEC_TEST_PG_CONN"
echo ""
# Run the integration tests
cd "$PROJECT_ROOT"
if go test -v ./tests/integration/ -count=1; then
echo -e "\n${GREEN}✓ All integration tests passed!${NC}"
exit 0
else
echo -e "\n${RED}✗ Integration tests failed${NC}"
exit 1
fi