🐛 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"
"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
}