From 1a3d7f9a8a181df48f0e911cbe17a3fad3ab9ac9 Mon Sep 17 00:00:00 2001 From: Chia Date: Wed, 5 Aug 2026 00:26:25 +1200 Subject: add some scripts --- internal/controlplane/manager_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'internal/controlplane/manager_test.go') diff --git a/internal/controlplane/manager_test.go b/internal/controlplane/manager_test.go index 8dd4012..ee78a00 100644 --- a/internal/controlplane/manager_test.go +++ b/internal/controlplane/manager_test.go @@ -13,6 +13,7 @@ import ( "aigw/internal/auth" "aigw/internal/catalog" + "aigw/internal/domain" ) type fakeManagerStore struct { @@ -26,6 +27,12 @@ type fakeManagerStore struct { subscribe func(context.Context, int64) (<-chan ChangeMessage, func() error, error) } +type capturePolicies struct{ values []domain.LimitPolicy } + +func (c *capturePolicies) ReplacePolicies(values []domain.LimitPolicy) { + c.values = append([]domain.LimitPolicy(nil), values...) +} + type safeLogBuffer struct { mu sync.Mutex buf bytes.Buffer @@ -199,6 +206,19 @@ func TestRedisCanBeDisabled(t *testing.T) { } } +func TestReloadReplacesLimitPolicySnapshot(t *testing.T) { + store := newFakeManagerStore(4) + store.snapshot.Store(Snapshot{Generation: 4, Limits: []domain.LimitPolicy{{ProjectID: "project-1", Concurrent: 3}}}) + target := &capturePolicies{} + manager := NewManager(store, catalog.NewModels(nil), auth.NewDynamic(nil, false), slog.Default(), time.Second, target) + if _, err := manager.Reload(context.Background()); err != nil { + t.Fatal(err) + } + if len(target.values) != 1 || target.values[0].Concurrent != 3 { + t.Fatalf("unexpected policies: %+v", target.values) + } +} + func waitUntil(t *testing.T, timeout time.Duration, condition func() bool) { t.Helper() deadline := time.Now().Add(timeout) -- cgit v1.2.3