setupAPIWithLimits returns a live test server plus the underlying pool/store/enforcer so callers can write directly to the DB the API is reading from. testutil.TestDB(t) creates a fresh pool AND truncates the schema on every call — so callers must NOT call it again from inside the test or they'll wi
(t *testing.T, internalSecret string)
| 29 | // truncates the schema on every call — so callers must NOT call it |
| 30 | // again from inside the test or they'll wipe their own setup. |
| 31 | func setupAPIWithLimits(t *testing.T, internalSecret string) (*httptest.Server, *identity.Store, *pgxpool.Pool, limits.Enforcer) { |
| 32 | t.Helper() |
| 33 | pool := testutil.TestDB(t) |
| 34 | store := identity.NewStore(pool) |
| 35 | smtpRelay := outbound.NewSMTPRelay(&config.OutboundSMTPConfig{}) |
| 36 | sender := outbound.NewSender(smtpRelay, "test.e2a.dev") |
| 37 | userAuth := auth.NewUserAuth(&config.OAuthConfig{}, store, false) |
| 38 | usageStore := usage.NewStore(pool) |
| 39 | |
| 40 | defaults := limits.Defaults{ |
| 41 | PlanCode: "default", MaxAgents: 100, MaxDomains: 10, |
| 42 | MaxMessagesMonth: 1_000_000, MaxStorageBytes: 1 << 40, |
| 43 | } |
| 44 | enf := limits.NewEnforcer(limits.NewStore(pool), usageStore, defaults, 0) |
| 45 | |
| 46 | api := agent.NewAPI(store, sender, smtpRelay, userAuth, usage.NewNoopUsageTracker(), "e2a.dev", "test.e2a.dev", "agents.e2a.dev", "", false) |
| 47 | api.SetEnforcer(enf) |
| 48 | api.SetUsageStore(usageStore) |
| 49 | api.SetInternalAPISecret(internalSecret) |
| 50 | |
| 51 | router := mux.NewRouter() |
| 52 | api.RegisterRoutes(router) |
| 53 | server := httptest.NewServer(router) |
| 54 | t.Cleanup(server.Close) |
| 55 | return server, store, pool, enf |
| 56 | } |
| 57 | |
| 58 | func TestInvalidateLimits_RejectsMissingSignature(t *testing.T) { |
| 59 | server, _, _, _ := setupAPIWithLimits(t, "test-secret-1") |
no test coverage detected