From 076bc120e050876e79d2fe9627adf4d254d80353 Mon Sep 17 00:00:00 2001 From: Gabriel Radureau Date: Wed, 8 Apr 2026 00:26:27 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20make=20BDD=20test=20serve?= =?UTF-8?q?r=20use=20actual=20config=20with=20environment=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modify createTestConfig to load real config - Respect DLC_DATABASE_HOST and other environment variables - Fallback to defaults if config loading fails - Enable proper database connection configuration - Fix BDD tests in Docker containers Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- pkg/bdd/testserver/server.go | 87 ++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/pkg/bdd/testserver/server.go b/pkg/bdd/testserver/server.go index b0ff480..5792a4c 100644 --- a/pkg/bdd/testserver/server.go +++ b/pkg/bdd/testserver/server.go @@ -5,7 +5,6 @@ import ( "database/sql" "fmt" "net/http" - "os" "strings" "time" @@ -240,38 +239,58 @@ func (s *Server) GetBaseURL() string { } func createTestConfig(port int) *config.Config { - return &config.Config{ - Server: config.ServerConfig{ - Host: "localhost", - Port: port, - }, - Shutdown: config.ShutdownConfig{ - Timeout: 5 * time.Second, - }, - Logging: config.LoggingConfig{ - JSON: false, - Level: "trace", - }, - Telemetry: config.TelemetryConfig{ - Enabled: false, - }, - API: config.APIConfig{ - V2Enabled: true, // Enable v2 for testing - }, - Auth: config.AuthConfig{ - JWTSecret: "default-secret-key-please-change-in-production", - AdminMasterPassword: "admin123", - }, - Database: config.DatabaseConfig{ - Host: "localhost", // Use localhost (PostgreSQL port is mapped) - Port: 5432, - User: "postgres", - Password: "postgres", - Name: "dance_lessons_coach_bdd_test", // Separate BDD test database - SSLMode: "disable", - MaxOpenConns: 10, - MaxIdleConns: 5, - ConnMaxLifetime: time.Hour, - }, + // Load actual config to respect environment variables + cfg, err := config.LoadConfig("") + if err != nil { + log.Warn().Err(err).Msg("Failed to load config, using defaults") + // Fallback to defaults if config loading fails + return &config.Config{ + Server: config.ServerConfig{ + Host: "localhost", + Port: port, + }, + Shutdown: config.ShutdownConfig{ + Timeout: 5 * time.Second, + }, + Logging: config.LoggingConfig{ + JSON: false, + Level: "trace", + }, + Telemetry: config.TelemetryConfig{ + Enabled: false, + }, + API: config.APIConfig{ + V2Enabled: true, // Enable v2 for testing + }, + Auth: config.AuthConfig{ + JWTSecret: "default-secret-key-please-change-in-production", + AdminMasterPassword: "admin123", + }, + Database: config.DatabaseConfig{ + Host: "localhost", // Fallback if env vars not set + Port: 5432, + User: "postgres", + Password: "postgres", + Name: "dance_lessons_coach_bdd_test", // Separate BDD test database + SSLMode: "disable", + MaxOpenConns: 10, + MaxIdleConns: 5, + ConnMaxLifetime: time.Hour, + }, + } } + + // Override server port for testing + cfg.Server.Port = port + cfg.API.V2Enabled = true // Ensure v2 is enabled for testing + + // Set default auth values if not configured + if cfg.Auth.JWTSecret == "" { + cfg.Auth.JWTSecret = "default-secret-key-please-change-in-production" + } + if cfg.Auth.AdminMasterPassword == "" { + cfg.Auth.AdminMasterPassword = "admin123" + } + + return cfg }