🐛 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:
@@ -17,14 +17,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// getPostgresHost returns the appropriate PostgreSQL host based on environment
|
// 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 {
|
func getPostgresHost() string {
|
||||||
host := os.Getenv("DLC_DATABASE_HOST")
|
host := os.Getenv("DLC_DATABASE_HOST")
|
||||||
if host != "" {
|
if host != "" {
|
||||||
return host
|
return host
|
||||||
}
|
}
|
||||||
// Default to container name for Docker environments
|
// Default to localhost for native execution, container name for Docker
|
||||||
return "dance-lessons-coach-postgres"
|
// 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 {
|
type Server struct {
|
||||||
|
|||||||
@@ -75,7 +75,12 @@ if [ "$HAS_DOCKER" = true ]; then
|
|||||||
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 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_PORT=5432
|
||||||
export DLC_DATABASE_USER=postgres
|
export DLC_DATABASE_USER=postgres
|
||||||
export DLC_DATABASE_PASSWORD=postgres
|
export DLC_DATABASE_PASSWORD=postgres
|
||||||
|
|||||||
Reference in New Issue
Block a user