summaryrefslogtreecommitdiff
path: root/internal/catalog/catalog_test.go
diff options
context:
space:
mode:
authorChia <Chia@93.nz>2026-08-04 19:58:52 +1200
committerChia <Chia@93.nz>2026-08-04 20:43:23 +1200
commit5b651488b081b65fda8a323f228e139adb79a35d (patch)
tree08baf40efb8fe103b32721cd991ff712323e3173 /internal/catalog/catalog_test.go
Build AI gateway control plane and admin UI
Diffstat (limited to '')
-rw-r--r--internal/catalog/catalog_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/catalog/catalog_test.go b/internal/catalog/catalog_test.go
new file mode 100644
index 0000000..07fb71f
--- /dev/null
+++ b/internal/catalog/catalog_test.go
@@ -0,0 +1,43 @@
+package catalog
+
+import (
+ "testing"
+
+ "aigw/internal/domain"
+)
+
+func TestCatalogReplaceSwapsModelSnapshot(t *testing.T) {
+ openAI := domain.Provider{ID: "openai", Protocol: domain.ProtocolOpenAI}
+ anthropic := domain.Provider{ID: "anthropic", Protocol: domain.ProtocolAnthropic}
+ catalog := NewModels([]domain.Model{{
+ ID: "old", Routes: []domain.Route{{Provider: openAI, UpstreamModel: "old-upstream"}},
+ }})
+
+ catalog.Replace([]domain.Model{{
+ ID: "new", Routes: []domain.Route{{Provider: anthropic, UpstreamModel: "new-upstream"}},
+ }})
+ if _, err := catalog.Model("old"); err == nil {
+ t.Fatal("old model remained after snapshot replacement")
+ }
+ model, err := catalog.Model("new")
+ if err != nil || len(model.Routes) != 1 || model.Routes[0].Provider.ID != "anthropic" {
+ t.Fatalf("new model was not loaded: model=%+v err=%v", model, err)
+ }
+ if got := catalog.Models(domain.ProtocolOpenAI); len(got) != 0 {
+ t.Fatalf("unexpected OpenAI models after replacement: %+v", got)
+ }
+}
+
+func TestCatalogReplaceCopiesRouteSlices(t *testing.T) {
+ models := []domain.Model{{ID: "model", Routes: []domain.Route{{UpstreamModel: "before"}}}}
+ catalog := NewModels(models)
+ models[0].Routes[0].UpstreamModel = "after"
+
+ model, err := catalog.Model("model")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if model.Routes[0].UpstreamModel != "before" {
+ t.Fatal("catalog snapshot aliases the caller's route slice")
+ }
+}