fb5ae6ceb5
CI / test (push) Failing after 12m33s
Compare against expected values (300s, 20s, 5s) instead of self-comparison
126 lines
2.7 KiB
Go
126 lines
2.7 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
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) {
|
|
t.Setenv("LLAMA_SERVER_STARTUP_TIMEOUT", "300")
|
|
t.Setenv("LLAMA_SERVER_STOP_TIMEOUT", "20")
|
|
t.Setenv("MODEL_SWAP_COOLDOWN", "5")
|
|
|
|
cfg := Load()
|
|
|
|
if got := cfg.LlamaServerStartupTimeoutDuration(); got != 300*time.Second {
|
|
t.Errorf("startup: got %v, want 300s", got)
|
|
}
|
|
if got := cfg.LlamaServerStopTimeoutDuration(); got != 20*time.Second {
|
|
t.Errorf("stop: got %v, want 20s", got)
|
|
}
|
|
if got := cfg.ModelSwapCooldownDuration(); got != 5*time.Second {
|
|
t.Errorf("cooldown: got %v, want 5s", got)
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|