🐛 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:
@@ -5,7 +5,6 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -240,6 +239,11 @@ func (s *Server) GetBaseURL() string {
|
||||
}
|
||||
|
||||
func createTestConfig(port int) *config.Config {
|
||||
// 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",
|
||||
@@ -263,7 +267,7 @@ func createTestConfig(port int) *config.Config {
|
||||
AdminMasterPassword: "admin123",
|
||||
},
|
||||
Database: config.DatabaseConfig{
|
||||
Host: "localhost", // Use localhost (PostgreSQL port is mapped)
|
||||
Host: "localhost", // Fallback if env vars not set
|
||||
Port: 5432,
|
||||
User: "postgres",
|
||||
Password: "postgres",
|
||||
@@ -274,4 +278,19 @@ func createTestConfig(port int) *config.Config {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user