🐛 fix: use environment variables for database host in BDD tests
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 13s
CI/CD Pipeline / CI Pipeline (push) Failing after 6m47s

This commit is contained in:
2026-04-10 16:52:58 +02:00
parent 21f21a2fdd
commit 908e41ba7d

View File

@@ -20,6 +20,26 @@ import (
"github.com/spf13/viper"
)
// getDatabaseHost returns the database host from environment variable or defaults to localhost
func getDatabaseHost() string {
host := os.Getenv("DLC_DATABASE_HOST")
if host == "" {
return "localhost"
}
return host
}
// getDatabasePort returns the database port from environment variable or defaults to 5432
func getDatabasePort() int {
port := 5432
if portEnv := os.Getenv("DLC_DATABASE_PORT"); portEnv != "" {
if parsedPort, err := strconv.Atoi(portEnv); err == nil {
port = parsedPort
}
}
return port
}
type Server struct {
httpServer *http.Server
port int
@@ -523,8 +543,8 @@ func createTestConfig(port int) *config.Config {
AdminMasterPassword: "admin123",
},
Database: config.DatabaseConfig{
Host: "localhost", // Fallback if env vars not set
Port: 5432,
Host: getDatabaseHost(), // Use env var if set, otherwise localhost
Port: getDatabasePort(), // Use env var if set, otherwise 5432
User: "postgres",
Password: "postgres",
Name: "dance_lessons_coach_bdd_test", // Separate BDD test database