package main import ( "testing" "git.k6n.net/mats/platform/catalog" ) // mustCache opens a per-pod projection cache backed by a temp dir (pod-local). func mustCache(t *testing.T) *catalogProjectionCache { t.Helper() c, err := newCatalogProjectionCache(t.TempDir()) if err != nil { t.Fatalf("newCatalogProjectionCache: %v", err) } t.Cleanup(func() { _ = c.store.Close() }) return c } // Apply is a TEST-ONLY convenience that routes a delta batch through the store at // the initial epoch (0), reproducing the pre-ProjectionStore cache API so the // existing cart tests keep exercising Get/IsDeleted/Len. Production code feeds the // store via HandleFrame with real bus framing (snapshot + epoch-stamped deltas). func (c *catalogProjectionCache) Apply(updates []catalog.ProjectionUpdate) (upserts, deletes int) { for _, u := range updates { if u.Deleted { deletes++ } else if u.SKU != "" { upserts++ } } payload, err := catalog.EncodeUpdates(updates) if err != nil { return 0, 0 } // No MetaSnapshotPhase ⇒ delta; epoch 0 matches a fresh store's base epoch. _ = c.store.HandleFrame(map[string]string{catalog.MetaEpoch: "0"}, payload) return upserts, deletes }