46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package config_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"chat-agent-system/internal/config"
|
|
)
|
|
|
|
func TestConfigLoadDefaultsAndFile(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
envPath := filepath.Join(tmpDir, ".env")
|
|
envContent := `ENV=dev
|
|
DATA_DIR=./data/test_data
|
|
AGENT_BACKEND=pi-agent
|
|
AGENT_TIMEOUT=15m
|
|
KB_DB_PORT=55432
|
|
`
|
|
if err := os.WriteFile(envPath, []byte(envContent), 0o644); err != nil {
|
|
t.Fatalf("failed to write test env: %v", err)
|
|
}
|
|
|
|
cfg, err := config.Load(envPath)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error loading config: %v", err)
|
|
}
|
|
|
|
if cfg.Env != "dev" {
|
|
t.Errorf("expected Env 'dev', got %q", cfg.Env)
|
|
}
|
|
if cfg.DataDir != "./data/test_data" {
|
|
t.Errorf("expected DataDir './data/test_data', got %q", cfg.DataDir)
|
|
}
|
|
if cfg.AgentBackend != "pi-agent" {
|
|
t.Errorf("expected AgentBackend 'pi-agent', got %q", cfg.AgentBackend)
|
|
}
|
|
if cfg.AgentTimeout != 15*time.Minute {
|
|
t.Errorf("expected AgentTimeout 15m, got %v", cfg.AgentTimeout)
|
|
}
|
|
if cfg.KbDbPort != 55432 {
|
|
t.Errorf("expected KbDbPort 55432, got %d", cfg.KbDbPort)
|
|
}
|
|
}
|