🧪 test: fix ambiguous BDD step definitions and improve test output\n\n- Remove duplicate step registrations for authentication and user creation\n- Remove duplicate logging level update step patterns\n- Change test logging from info to trace level for better debugging\n- Change JWT test format from progress to pretty for better scenario visibility\n- Keep meaningful implementations, use ErrPending only for truly unimplemented steps\n\nGenerated by Mistral Vibe.\nCo-Authored-By: Mistral Vibe <vibe@mistral.ai>

This commit is contained in:
2026-04-10 08:42:46 +02:00
parent de2e03519e
commit 0011bed168
13 changed files with 237 additions and 89 deletions

View File

@@ -18,8 +18,6 @@ import (
"github.com/spf13/viper"
)
// getPostgresHost returns the appropriate PostgreSQL host based on environment
type Server struct {
httpServer *http.Server
port int
@@ -233,6 +231,15 @@ func (s *Server) initDBConnection() error {
cfg.Database.SSLMode,
)
// Log the database configuration being used
log.Debug().
Str("host", cfg.Database.Host).
Int("port", cfg.Database.Port).
Str("user", cfg.Database.User).
Str("dbname", cfg.Database.Name).
Str("sslmode", cfg.Database.SSLMode).
Msg("Database connection initialized with test configuration")
var dbErr error
s.db, dbErr = sql.Open("postgres", dsn)
if dbErr != nil {
@@ -439,64 +446,62 @@ func createTestConfig(port int) *config.Config {
cfg.Auth.AdminMasterPassword = "admin123"
}
log.Debug().Str("config", configPath).Msg("Using test config file")
log.Debug().
Str("config", configPath).
Str("db_host", cfg.Database.Host).
Int("db_port", cfg.Database.Port).
Str("db_user", cfg.Database.User).
Str("db_name", cfg.Database.Name).
Bool("v2flag", cfg.API.V2Enabled).
Msg("Using test config file")
return &cfg
}
}
}
}
// No test config file, use default config
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 by default for most tests
},
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,
},
}
}
// No test config file found, use hardcoded test defaults
// This ensures test suite has complete control and isn't affected by
// environment variables or main config file settings
log.Debug().
Str("db_host", "localhost").
Int("db_port", 5432).
Str("db_user", "postgres").
Str("db_name", "dance_lessons_coach_bdd_test").
Msg("No test config file found, using hardcoded test defaults")
// Override server port for testing
cfg.Server.Port = port
// Set default auth values if not configured
if cfg.Auth.JWTSecret == "" {
cfg.Auth.JWTSecret = "default-secret-key-please-change-in-production"
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 by default for most tests
},
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,
},
}
if cfg.Auth.AdminMasterPassword == "" {
cfg.Auth.AdminMasterPassword = "admin123"
}
return cfg
}