🐛 fix: BDD tests PostgreSQL connection for native execution

- Simplify getPostgresHost() to always use localhost by default
- Use DLC_DATABASE_HOST=localhost for all local execution
- Container name only needed when running INSIDE Docker containers
- Fix native execution PostgreSQL connection issues
- Ensure BDD tests connect to localhost:5432 (mapped port)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-04-07 23:52:57 +02:00
parent 6c2399bea6
commit f8474b69c1
2 changed files with 6 additions and 7 deletions

View File

@@ -24,11 +24,8 @@ func getPostgresHost() string {
return host return host
} }
// Default to localhost for native execution, container name for Docker // Default to localhost for native execution, container name for Docker
// Check if we're running in a container by looking for Docker-specific env vars // When running natively but PostgreSQL is in Docker, use localhost (port mapping)
if os.Getenv("DOCKER_CONTAINER") != "" || os.Getenv("KUBERNETES_SERVICE_HOST") != "" { // When running in Docker containers, use container name
return "dance-lessons-coach-postgres"
}
// Native execution - use localhost with container port mapping
return "localhost" return "localhost"
} }

View File

@@ -69,7 +69,9 @@ for i in {1..30}; do
done done
# Set PostgreSQL environment variables for BDD tests # Set PostgreSQL environment variables for BDD tests
export DLC_DATABASE_HOST="dance-lessons-coach-postgres" # Use localhost since PostgreSQL port is mapped to host
# Container name is only used when running INSIDE Docker containers
export DLC_DATABASE_HOST="localhost"
export DLC_DATABASE_PORT=5432 export DLC_DATABASE_PORT=5432
export DLC_DATABASE_USER=postgres export DLC_DATABASE_USER=postgres
export DLC_DATABASE_PASSWORD=postgres export DLC_DATABASE_PASSWORD=postgres
@@ -130,7 +132,7 @@ if [ "$USE_DOCKER_CACHE" = true ]; then
--network dance-lessons-coach-network \ --network dance-lessons-coach-network \
-v "$(pwd):/workspace" \ -v "$(pwd):/workspace" \
-w /workspace \ -w /workspace \
-e DLC_DATABASE_HOST=dance-lessons-coach-postgres \ -e DLC_DATABASE_HOST=localhost \
-e DLC_DATABASE_PORT=5432 \ -e DLC_DATABASE_PORT=5432 \
-e DLC_DATABASE_USER=postgres \ -e DLC_DATABASE_USER=postgres \
-e DLC_DATABASE_PASSWORD=postgres \ -e DLC_DATABASE_PASSWORD=postgres \