🐛 fix: make BDD test server use actual config with environment variables

- 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 <vibe@mistral.ai>
This commit is contained in:
2026-04-08 00:26:27 +02:00
parent 0026515237
commit 076bc120e0

View File

@@ -5,7 +5,6 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"net/http" "net/http"
"os"
"strings" "strings"
"time" "time"
@@ -240,38 +239,58 @@ func (s *Server) GetBaseURL() string {
} }
func createTestConfig(port int) *config.Config { func createTestConfig(port int) *config.Config {
return &config.Config{ // Load actual config to respect environment variables
Server: config.ServerConfig{ cfg, err := config.LoadConfig("")
Host: "localhost", if err != nil {
Port: port, log.Warn().Err(err).Msg("Failed to load config, using defaults")
}, // Fallback to defaults if config loading fails
Shutdown: config.ShutdownConfig{ return &config.Config{
Timeout: 5 * time.Second, Server: config.ServerConfig{
}, Host: "localhost",
Logging: config.LoggingConfig{ Port: port,
JSON: false, },
Level: "trace", Shutdown: config.ShutdownConfig{
}, Timeout: 5 * time.Second,
Telemetry: config.TelemetryConfig{ },
Enabled: false, Logging: config.LoggingConfig{
}, JSON: false,
API: config.APIConfig{ Level: "trace",
V2Enabled: true, // Enable v2 for testing },
}, Telemetry: config.TelemetryConfig{
Auth: config.AuthConfig{ Enabled: false,
JWTSecret: "default-secret-key-please-change-in-production", },
AdminMasterPassword: "admin123", API: config.APIConfig{
}, V2Enabled: true, // Enable v2 for testing
Database: config.DatabaseConfig{ },
Host: "localhost", // Use localhost (PostgreSQL port is mapped) Auth: config.AuthConfig{
Port: 5432, JWTSecret: "default-secret-key-please-change-in-production",
User: "postgres", AdminMasterPassword: "admin123",
Password: "postgres", },
Name: "dance_lessons_coach_bdd_test", // Separate BDD test database Database: config.DatabaseConfig{
SSLMode: "disable", Host: "localhost", // Fallback if env vars not set
MaxOpenConns: 10, Port: 5432,
MaxIdleConns: 5, User: "postgres",
ConnMaxLifetime: time.Hour, 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
} }