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") } }