🔧 refactor: simplify BDD database configuration
- Remove unnecessary getPostgresHost() function - Use direct localhost configuration - PostgreSQL port is mapped to host, so localhost works everywhere - Simplify code by removing unnecessary abstraction - Use existing config system properly Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -17,29 +17,6 @@ import (
|
||||
)
|
||||
|
||||
// getPostgresHost returns the appropriate PostgreSQL host based on environment
|
||||
// Uses DLC_DATABASE_HOST environment variable or detects execution context
|
||||
func getPostgresHost() string {
|
||||
host := os.Getenv("DLC_DATABASE_HOST")
|
||||
if host != "" {
|
||||
return host
|
||||
}
|
||||
|
||||
// Detect if we're running inside a Docker container
|
||||
// Check for Docker-specific environment variables or files
|
||||
if os.Getenv("DOCKER_CONTAINER") != "" ||
|
||||
os.Getenv("KUBERNETES_SERVICE_HOST") != "" ||
|
||||
os.Getenv("container") == "docker" {
|
||||
return "dance-lessons-coach-postgres" // Use container name in Docker
|
||||
}
|
||||
|
||||
// Check for .dockerenv file (Docker-specific)
|
||||
if _, err := os.Stat("/.dockerenv"); err == nil {
|
||||
return "dance-lessons-coach-postgres" // Use container name in Docker
|
||||
}
|
||||
|
||||
// Default to localhost for native execution (PostgreSQL port mapping)
|
||||
return "localhost"
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
httpServer *http.Server
|
||||
@@ -286,7 +263,7 @@ func createTestConfig(port int) *config.Config {
|
||||
AdminMasterPassword: "admin123",
|
||||
},
|
||||
Database: config.DatabaseConfig{
|
||||
Host: getPostgresHost(), // Use container name in Docker, localhost otherwise
|
||||
Host: "localhost", // Use localhost (PostgreSQL port is mapped)
|
||||
Port: 5432,
|
||||
User: "postgres",
|
||||
Password: "postgres",
|
||||
|
||||
Reference in New Issue
Block a user