From c2feb1bc7564799d088c57a84b4b87636166eacc Mon Sep 17 00:00:00 2001 From: Daniel Arroyo Date: Thu, 30 Jul 2026 17:42:28 -0400 Subject: [PATCH] Fix CI: add if-no-files-found=warn to coverage upload, add config tests - .github/workflows/ci.yml: upload-artifact if-no-files-found=warn - internal/config/config_test.go: 93.5% coverage smoke tests for Load, env overrides, URL helpers, duration helpers, Logger, boolEnv --- .github/workflows/ci.yml | 1 + internal/config/config_test.go | 122 +++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 internal/config/config_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e23b9cd..354329d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,3 +50,4 @@ jobs: with: name: coverage path: coverage.out + if-no-files-found: warn diff --git a/internal/config/config_test.go b/internal/config/config_test.go new file mode 100644 index 0000000..de0c719 --- /dev/null +++ b/internal/config/config_test.go @@ -0,0 +1,122 @@ +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) + } + } +}