Files
Story Crater Bot b6767e247c
Build / Build and push image (push) Failing after 12s
CI / Test, vet, build (push) Successful in 2m18s
fix(deps,ci): update module path to forgejo.riotpiao.com/rock/homelab-frontend, switch to GITHUB_TOKEN
2026-08-21 20:46:45 -07:00

76 lines
2.0 KiB
Go

package config_test
import (
"os"
"testing"
"time"
"forgejo.riotpiao.com/rock/homelab-frontend/internal/config"
)
// TestLoadIntegration tests the full Load function with CONFIG_PATH env var
func TestLoadIntegration(t *testing.T) {
// Set the environment variable
originalConfigPath := os.Getenv("CONFIG_PATH")
os.Setenv("CONFIG_PATH", "../../testdata/config/valid.yaml")
defer func() {
if originalConfigPath != "" {
os.Setenv("CONFIG_PATH", originalConfigPath)
} else {
os.Unsetenv("CONFIG_PATH")
}
}()
cfg, err := config.Load()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if cfg == nil {
t.Fatal("expected non-nil config")
}
if len(cfg.Routes) != 3 {
t.Errorf("expected 3 routes, got %d", len(cfg.Routes))
}
// Verify reasoning-chat is present
reasoningRoute, ok := cfg.Routes["reasoning-chat"]
if !ok {
t.Fatal("reasoning-chat route not found")
}
if reasoningRoute.Upstream.Address != "reasoning-predictor.llm-serving:80" {
t.Errorf("unexpected address: %s", reasoningRoute.Upstream.Address)
}
if reasoningRoute.Upstream.ConnectTimeout != 10*time.Second {
t.Errorf("unexpected connect timeout: %v", reasoningRoute.Upstream.ConnectTimeout)
}
if reasoningRoute.Upstream.ReadTimeout != time.Hour {
t.Errorf("unexpected read timeout: %v", reasoningRoute.Upstream.ReadTimeout)
}
if reasoningRoute.Upstream.WriteTimeout != time.Hour {
t.Errorf("unexpected write timeout: %v", reasoningRoute.Upstream.WriteTimeout)
}
}
// TestLoadIntegrationWithInvalidConfig tests that Load fails with invalid config
func TestLoadIntegrationWithInvalidConfig(t *testing.T) {
originalConfigPath := os.Getenv("CONFIG_PATH")
os.Setenv("CONFIG_PATH", "../../testdata/config/missing-address.yaml")
defer func() {
if originalConfigPath != "" {
os.Setenv("CONFIG_PATH", originalConfigPath)
} else {
os.Unsetenv("CONFIG_PATH")
}
}()
cfg, err := config.Load()
if err == nil {
t.Fatal("expected error but got nil")
}
if cfg != nil {
t.Error("expected nil config on error")
}
}