Files

47 lines
1.1 KiB
Go

package config
import (
"os"
"path/filepath"
"testing"
)
func TestConfigLoadEnvAndAppConfig(t *testing.T) {
tempDir := t.TempDir()
envPath := filepath.Join(tempDir, ".env")
configYAMLPath := filepath.Join(tempDir, "config.yaml")
_ = os.WriteFile(envPath, []byte("TEST_SECRET_KEY=12345\nDEEPSEEK_API_KEY=test-sk-key\n"), 0644)
_ = os.WriteFile(configYAMLPath, []byte(`
server:
port: "9090"
log_level: "debug"
ai_trigger:
analysis_threshold: 35.0
prompts:
system_prompt_path: "sys.txt"
`), 0644)
LoadEnvFile(envPath)
if os.Getenv("TEST_SECRET_KEY") != "12345" {
t.Errorf("expected TEST_SECRET_KEY to be 12345, got %q", os.Getenv("TEST_SECRET_KEY"))
}
cfg := &Config{
Port: "8080",
LogLevel: "info",
AppConfig: configYAMLPath,
}
cfg.Normalize()
if cfg.Port != "9090" {
t.Errorf("expected port 9090 from config.yaml, got %s", cfg.Port)
}
if cfg.AnalysisThreshold != 35.0 {
t.Errorf("expected analysis threshold 35.0, got %f", cfg.AnalysisThreshold)
}
if cfg.LLMProvider != "deepseek" {
t.Errorf("expected LLMProvider to be deepseek, got %s", cfg.LLMProvider)
}
}