Baseline for the Kong replacement on api.riotpiao.com. Brings the working tree under version control for the first time: gateway source, the task board that drives the agent runs, test fixtures, and K8s manifests. Anchor the gateway ignore rule to the repo root. Unanchored, "gateway" also matched the cmd/gateway/ source directory, so the program entrypoint was excluded from every commit. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package config_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/Riotpiaole/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")
|
|
}
|
|
}
|