package config import ( "os" "testing" ) func TestLoad(t *testing.T) { cfg := Load() if cfg == nil { t.Fatal("Load() returned nil") } if cfg.LlamalinkPort != 8000 { t.Errorf("expected default port 8000, got %d", cfg.LlamalinkPort) } if cfg.DatabaseURL != "sqlite:///./llamalink.db" { t.Errorf("expected default DatabaseURL, got %s", cfg.DatabaseURL) } if cfg.ManageLlamaServer != true { t.Errorf("expected ManageLlamaServer default true, got %v", cfg.ManageLlamaServer) } if cfg.RateLimitPerMinute != 60 { t.Errorf("expected default RateLimitPerMinute 60, got %d", cfg.RateLimitPerMinute) } } func TestLoadEnvOverride(t *testing.T) { t.Setenv("LLAMALINK_PORT", "9000") t.Setenv("LLAMALINK_ENV", "production") t.Setenv("ADMIN_TOKEN", "secret-token") cfg := Load() if cfg.LlamalinkPort != 9000 { t.Errorf("expected port 9000 from env, got %d", cfg.LlamalinkPort) } if cfg.LlamalinkEnv != "production" { t.Errorf("expected env production, got %s", cfg.LlamalinkEnv) } if cfg.AdminToken != "secret-token" { t.Errorf("expected AdminToken secret-token, got %s", cfg.AdminToken) } } func TestLlamaServerURL(t *testing.T) { cfg := Load() url := cfg.LlamaServerURL() if url != "http://127.0.0.1:8080" { t.Errorf("expected http://127.0.0.1:8080, got %s", url) } } func TestDurationHelpers(t *testing.T) { cfg := Load() if cfg.LlamaServerStartupTimeoutDuration() != cfg.LlamaServerStartupTimeoutDuration() { t.Error("startup timeout duration mismatch") } if cfg.LlamaServerStopTimeoutDuration() != cfg.LlamaServerStopTimeoutDuration() { t.Error("stop timeout duration mismatch") } if cfg.ModelSwapCooldownDuration() != cfg.ModelSwapCooldownDuration() { t.Error("model swap cooldown duration mismatch") } } func TestLogger(t *testing.T) { cfg := Load() logger := cfg.Logger() if logger == nil { t.Fatal("Logger() returned nil") } cfg.LogLevel = "debug" cfg.LogFormat = "text" logger = cfg.Logger() if logger == nil { t.Fatal("Logger() with debug/text returned nil") } cfg.LogFormat = "json" logger = cfg.Logger() if logger == nil { t.Fatal("Logger() with json returned nil") } } func TestBoolEnv(t *testing.T) { tests := []struct { envVal string expected bool }{ {"true", true}, {"1", true}, {"yes", true}, {"false", false}, {"0", false}, {"no", false}, {"", false}, } for _, tc := range tests { if tc.envVal != "" { t.Setenv("TEST_BOOL_ENV", tc.envVal) } else { os.Unsetenv("TEST_BOOL_ENV") } result := boolEnv("TEST_BOOL_ENV", false) if result != tc.expected { t.Errorf("boolEnv(%q) = %v, want %v", tc.envVal, result, tc.expected) } } }