🐛 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"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -240,6 +239,11 @@ func (s *Server) GetBaseURL() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createTestConfig(port int) *config.Config {
|
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{
|
return &config.Config{
|
||||||
Server: config.ServerConfig{
|
Server: config.ServerConfig{
|
||||||
Host: "localhost",
|
Host: "localhost",
|
||||||
@@ -263,7 +267,7 @@ func createTestConfig(port int) *config.Config {
|
|||||||
AdminMasterPassword: "admin123",
|
AdminMasterPassword: "admin123",
|
||||||
},
|
},
|
||||||
Database: config.DatabaseConfig{
|
Database: config.DatabaseConfig{
|
||||||
Host: "localhost", // Use localhost (PostgreSQL port is mapped)
|
Host: "localhost", // Fallback if env vars not set
|
||||||
Port: 5432,
|
Port: 5432,
|
||||||
User: "postgres",
|
User: "postgres",
|
||||||
Password: "postgres",
|
Password: "postgres",
|
||||||
@@ -275,3 +279,18 @@ func createTestConfig(port int) *config.Config {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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