//go:build test package webhooks import ( "os" "testing" "crussell/db" "crussell/testutils/testdb" ) // resetSquareWebhookEventsSeen clears the process-global in-memory webhook // dedup cache (squareWebhookEventsSeen in square.go). square.go exposes no // reset — the cache is a deliberate process-lifetime fast-path for handler // dedup — so the test suite provides its own test-only accessor: the test files // compile into the same package and can reach the unexported cache. Without a // reset the suite is order-dependent: tests reuse event_ids (e.g. "evt_1") and // a delivery from an earlier test would fast-path-drop a later test's delivery // BEFORE dispatch, silently skipping the state mutation the later test asserts. func resetSquareWebhookEventsSeen() { squareWebhookEventsSeen.mu.Lock() squareWebhookEventsSeen.seen = make(map[string]struct{}) squareWebhookEventsSeen.order = make([]string, 0, squareWebhookEventsSeen.max) squareWebhookEventsSeen.mu.Unlock() } func TestMain(m *testing.M) { pool := testdb.CreateTestDatabase("crussell_test_handlers_webhooks") db.Conn = db.NewPoolProxy(pool) testdb.SeedBaseline(pool) // Start from a clean in-memory dedup cache: the handler's fast-path cache // is a package global that would otherwise leak event_ids across tests // (they share ids like "evt_1"), making the suite order-dependent. resetSquareWebhookEventsSeen() code := m.Run() testdb.DestroyTestDatabase(pool, "crussell_test_handlers_webhooks") os.Exit(code) }