summaryrefslogtreecommitdiff
path: root/internal/controlplane/manager_test.go
diff options
context:
space:
mode:
authorChia <Chia@93.nz>2026-08-05 00:26:25 +1200
committerChia <Chia@93.nz>2026-08-05 00:33:31 +1200
commit1a3d7f9a8a181df48f0e911cbe17a3fad3ab9ac9 (patch)
tree8c92e1e7326fc67ed077a0a878697f1be14b43da /internal/controlplane/manager_test.go
parent5b651488b081b65fda8a323f228e139adb79a35d (diff)
add some scriptsmain
Diffstat (limited to '')
-rw-r--r--internal/controlplane/manager_test.go20
1 files changed, 20 insertions, 0 deletions
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)