Files
golang/internal/config/config_test.go
Gemini CLI 4807edd23a
All checks were successful
CI / Lint (pull_request) Successful in 5s
CI / Test (pull_request) Successful in 7s
CI / Build (pull_request) Successful in 7s
CI / Docker Build (pull_request) Successful in 21s
refactor(logging): move logging setup to internal/logging
Moves logging configuration and setup to a dedicated package. Updates Config struct to use nested LoggingConfig. Updates main.go to use the new logging package.
2026-01-15 18:57:01 +00:00

66 lines
1.6 KiB
Go

package config
import (
"os"
"path/filepath"
"testing"
)
func TestLoad(t *testing.T) {
// Create a temporary config file
tmpDir := t.TempDir()
configFile := filepath.Join(tmpDir, "config.yaml")
yamlContent := []byte(`
logging:
level: "info"
server:
host: "localhost"
port: 8080
`)
if err := os.WriteFile(configFile, yamlContent, 0644); err != nil {
t.Fatalf("failed to write temp config file: %v", err)
}
t.Run("Load from YAML", func(t *testing.T) {
cfg, err := Load(configFile, "TEST")
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if cfg.Logging.Level != "info" {
t.Errorf("expected Logging.Level 'info', got '%s'", cfg.Logging.Level)
}
if cfg.Server.Host != "localhost" {
t.Errorf("expected Server.Host 'localhost', got '%s'", cfg.Server.Host)
}
if cfg.Server.Port != 8080 {
t.Errorf("expected Server.Port 8080, got %d", cfg.Server.Port)
}
})
t.Run("Override from Env", func(t *testing.T) {
os.Setenv("TEST_LOGGING_LEVEL", "debug")
os.Setenv("TEST_SERVER_PORT", "9090")
os.Setenv("TEST_SERVER_HOST", "0.0.0.0")
defer func() {
os.Unsetenv("TEST_LOGGING_LEVEL")
os.Unsetenv("TEST_SERVER_PORT")
os.Unsetenv("TEST_SERVER_HOST")
}()
cfg, err := Load(configFile, "TEST")
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if cfg.Logging.Level != "debug" {
t.Errorf("expected Logging.Level 'debug', got '%s'", cfg.Logging.Level)
}
if cfg.Server.Port != 9090 {
t.Errorf("expected Server.Port 9090, got %d", cfg.Server.Port)
}
if cfg.Server.Host != "0.0.0.0" {
t.Errorf("expected Server.Host '0.0.0.0', got '%s'", cfg.Server.Host)
}
})
}