🐛 fix: BDD tests PostgreSQL connection for native execution

- Enhance getPostgresHost() to detect Docker vs native execution
- Use localhost for native execution (PostgreSQL port mapping)
- Use container name for Docker execution
- Fix local CI/CD script to set correct DLC_DATABASE_HOST
- Ensure BDD tests can connect in both Docker and native modes

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-04-07 23:40:08 +02:00
parent 9528b7d288
commit 18213f365d
2 changed files with 14 additions and 4 deletions

View File

@@ -17,14 +17,19 @@ import (
)
// getPostgresHost returns the appropriate PostgreSQL host based on environment
// Uses DLC_DATABASE_HOST environment variable or defaults to container name
// Uses DLC_DATABASE_HOST environment variable or defaults appropriately
func getPostgresHost() string {
host := os.Getenv("DLC_DATABASE_HOST")
if host != "" {
return host
}
// Default to container name for Docker environments
return "dance-lessons-coach-postgres"
// 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
if os.Getenv("DOCKER_CONTAINER") != "" || os.Getenv("KUBERNETES_SERVICE_HOST") != "" {
return "dance-lessons-coach-postgres"
}
// Native execution - use localhost with container port mapping
return "localhost"
}
type Server struct {

View File

@@ -75,7 +75,12 @@ if [ "$HAS_DOCKER" = true ]; then
done
# Set PostgreSQL environment variables for BDD tests
export DLC_DATABASE_HOST="dance-lessons-coach-postgres"
# Use container name for Docker, localhost for native (port mapping)
if [ "$HAS_DOCKER" = true ]; then
export DLC_DATABASE_HOST="dance-lessons-coach-postgres"
else
export DLC_DATABASE_HOST="localhost"
fi
export DLC_DATABASE_PORT=5432
export DLC_DATABASE_USER=postgres
export DLC_DATABASE_PASSWORD=postgres