Fixed Attempt to Fix Docker / Podman

Co-authored-by: IvanX006 <ivan@bitechsystems.co.za>
Co-authored-by: Warkanum <HEIN.PUTH@GMAIL.COM>
Co-authored-by: Hein <hein@bitechsystems.co.za>
This commit is contained in:
Hein 2025-12-19 16:42:01 +02:00
parent 84d673ce14
commit 45c463c117
5 changed files with 31 additions and 31 deletions

View File

@ -16,7 +16,7 @@ test: test-unit test-integration
# Start PostgreSQL for integration tests # Start PostgreSQL for integration tests
docker-up: docker-up:
@echo "Starting PostgreSQL container..." @echo "Starting PostgreSQL container..."
@docker-compose up -d postgres-test @podman compose up -d postgres-test
@echo "Waiting for PostgreSQL to be ready..." @echo "Waiting for PostgreSQL to be ready..."
@sleep 5 @sleep 5
@echo "PostgreSQL is ready!" @echo "PostgreSQL is ready!"
@ -24,12 +24,12 @@ docker-up:
# Stop PostgreSQL container # Stop PostgreSQL container
docker-down: docker-down:
@echo "Stopping PostgreSQL container..." @echo "Stopping PostgreSQL container..."
@docker-compose down @podman compose down
# Clean up Docker volumes and test data # Clean up Docker volumes and test data
clean: clean:
@echo "Cleaning up..." @echo "Cleaning up..."
@docker-compose down -v @podman compose down -v
@echo "Cleanup complete!" @echo "Cleanup complete!"
# Run integration tests with Docker (full workflow) # Run integration tests with Docker (full workflow)

View File

@ -465,7 +465,7 @@ func processRequest(ctx context.Context) {
1. **Check collector is running:** 1. **Check collector is running:**
```bash ```bash
docker-compose ps podman compose ps
``` ```
2. **Verify endpoint:** 2. **Verify endpoint:**
@ -476,7 +476,7 @@ func processRequest(ctx context.Context) {
3. **Check logs:** 3. **Check logs:**
```bash ```bash
docker-compose logs otel-collector podman compose logs otel-collector
``` ```
### Disable Tracing ### Disable Tracing

View File

@ -14,33 +14,33 @@ NC='\033[0m' # No Color
echo -e "${GREEN}=== ResolveSpec Integration Tests ===${NC}\n" echo -e "${GREEN}=== ResolveSpec Integration Tests ===${NC}\n"
# Check if docker-compose is available # Check if podman compose is available
if ! command -v docker-compose &> /dev/null; then if ! command -v podman &> /dev/null; then
echo -e "${RED}Error: docker-compose is not installed${NC}" echo -e "${RED}Error: podman is not installed${NC}"
echo "Please install docker-compose or run PostgreSQL manually" echo "Please install podman or run PostgreSQL manually"
echo "See INTEGRATION_TESTS.md for details" echo "See INTEGRATION_TESTS.md for details"
exit 1 exit 1
fi fi
# Clean up any existing containers and networks from previous runs # Clean up any existing containers and networks from previous runs
echo -e "${YELLOW}Cleaning up existing containers and networks...${NC}" echo -e "${YELLOW}Cleaning up existing containers and networks...${NC}"
docker-compose down -v 2>/dev/null || true podman compose down -v 2>/dev/null || true
# Start PostgreSQL # Start PostgreSQL
echo -e "${YELLOW}Starting PostgreSQL...${NC}" echo -e "${YELLOW}Starting PostgreSQL...${NC}"
docker-compose up -d postgres-test podman compose up -d postgres-test
# Wait for PostgreSQL to be ready # Wait for PostgreSQL to be ready
echo -e "${YELLOW}Waiting for PostgreSQL to be ready...${NC}" echo -e "${YELLOW}Waiting for PostgreSQL to be ready...${NC}"
max_attempts=30 max_attempts=30
attempt=0 attempt=0
while ! docker-compose exec -T postgres-test pg_isready -U postgres > /dev/null 2>&1; do while ! podman compose exec -T postgres-test pg_isready -U postgres > /dev/null 2>&1; do
attempt=$((attempt + 1)) attempt=$((attempt + 1))
if [ $attempt -ge $max_attempts ]; then if [ $attempt -ge $max_attempts ]; then
echo -e "${RED}Error: PostgreSQL failed to start after ${max_attempts} seconds${NC}" echo -e "${RED}Error: PostgreSQL failed to start after ${max_attempts} seconds${NC}"
docker-compose logs postgres-test podman compose logs postgres-test
docker-compose down podman compose down
exit 1 exit 1
fi fi
sleep 1 sleep 1
@ -51,8 +51,8 @@ echo -e "\n${GREEN}PostgreSQL is ready!${NC}\n"
# Create test databases # Create test databases
echo -e "${YELLOW}Creating test databases...${NC}" echo -e "${YELLOW}Creating test databases...${NC}"
docker-compose exec -T postgres-test psql -U postgres -c "CREATE DATABASE resolvespec_test;" 2>/dev/null || echo " resolvespec_test already exists" podman compose exec -T postgres-test psql -U postgres -c "CREATE DATABASE resolvespec_test;" 2>/dev/null || echo " resolvespec_test already exists"
docker-compose exec -T postgres-test psql -U postgres -c "CREATE DATABASE restheadspec_test;" 2>/dev/null || echo " restheadspec_test already exists" podman compose exec -T postgres-test psql -U postgres -c "CREATE DATABASE restheadspec_test;" 2>/dev/null || echo " restheadspec_test already exists"
echo -e "${GREEN}Test databases ready!${NC}\n" echo -e "${GREEN}Test databases ready!${NC}\n"
# Determine which tests to run # Determine which tests to run
@ -79,6 +79,6 @@ fi
# Cleanup # Cleanup
echo -e "\n${YELLOW}Stopping PostgreSQL...${NC}" echo -e "\n${YELLOW}Stopping PostgreSQL...${NC}"
docker-compose down podman compose down
exit $EXIT_CODE exit $EXIT_CODE

View File

@ -19,14 +19,14 @@ Integration tests validate the full functionality of both `pkg/resolvespec` and
- Go 1.19 or later - Go 1.19 or later
- PostgreSQL 12 or later - PostgreSQL 12 or later
- Docker and Docker Compose (optional, for easy setup) - Podman and Podman Compose (optional, for easy setup)
## Quick Start with Docker ## Quick Start with Podman
### 1. Start PostgreSQL with Docker Compose ### 1. Start PostgreSQL with Podman Compose
```bash ```bash
docker-compose up -d postgres-test podman compose up -d postgres-test
``` ```
This starts a PostgreSQL container with the following default settings: This starts a PostgreSQL container with the following default settings:
@ -52,7 +52,7 @@ go test -tags=integration ./pkg/restheadspec -v
### 3. Stop PostgreSQL ### 3. Stop PostgreSQL
```bash ```bash
docker-compose down podman compose down
``` ```
## Manual PostgreSQL Setup ## Manual PostgreSQL Setup
@ -161,7 +161,7 @@ If you see "connection refused" errors:
1. Check that PostgreSQL is running: 1. Check that PostgreSQL is running:
```bash ```bash
docker-compose ps podman compose ps
``` ```
2. Verify connection parameters: 2. Verify connection parameters:
@ -194,10 +194,10 @@ Each test automatically cleans up its data using `TRUNCATE`. If you need a fresh
```bash ```bash
# Stop and remove containers (removes data) # Stop and remove containers (removes data)
docker-compose down -v podman compose down -v
# Restart # Restart
docker-compose up -d postgres-test podman compose up -d postgres-test
``` ```
## CI/CD Integration ## CI/CD Integration

View File

@ -119,13 +119,13 @@ Integration tests require a PostgreSQL database and use the `// +build integrati
- PostgreSQL 12+ installed and running - PostgreSQL 12+ installed and running
- Create test databases manually (see below) - Create test databases manually (see below)
### Setup with Docker ### Setup with Podman
1. **Start PostgreSQL**: 1. **Start PostgreSQL**:
```bash ```bash
make docker-up make docker-up
# or # or
docker-compose up -d postgres-test podman compose up -d postgres-test
``` ```
2. **Run Tests**: 2. **Run Tests**:
@ -141,10 +141,10 @@ Integration tests require a PostgreSQL database and use the `// +build integrati
```bash ```bash
make docker-down make docker-down
# or # or
docker-compose down podman compose down
``` ```
### Setup without Docker ### Setup without Podman
1. **Create Databases**: 1. **Create Databases**:
```sql ```sql
@ -289,8 +289,8 @@ go test -tags=integration ./pkg/resolvespec -v
**Problem**: "connection refused" or "database does not exist" **Problem**: "connection refused" or "database does not exist"
**Solutions**: **Solutions**:
1. Check PostgreSQL is running: `docker-compose ps` 1. Check PostgreSQL is running: `podman compose ps`
2. Verify databases exist: `docker-compose exec postgres-test psql -U postgres -l` 2. Verify databases exist: `podman compose exec postgres-test psql -U postgres -l`
3. Check environment variable: `echo $TEST_DATABASE_URL` 3. Check environment variable: `echo $TEST_DATABASE_URL`
4. Recreate databases: `make clean && make docker-up` 4. Recreate databases: `make clean && make docker-up`