Fix CI: add if-no-files-found=warn to coverage upload, add config tests
CI / test (push) Failing after 12m39s

- .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
This commit is contained in:
2026-07-30 17:42:28 -04:00
parent f775c2f67e
commit c2feb1bc75
2 changed files with 123 additions and 0 deletions
+1
View File
@@ -50,3 +50,4 @@ jobs:
with: with:
name: coverage name: coverage
path: coverage.out path: coverage.out
if-no-files-found: warn
+122
View File
@@ -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)
}
}
}