MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / setupAPIWithLimits

Function setupAPIWithLimits

internal/agent/limits_api_test.go:31–56  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
31func 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
58func TestInvalidateLimits_RejectsMissingSignature(t *testing.T) {
59 server, _, _, _ := setupAPIWithLimits(t, "test-secret-1")

Calls 15

SetEnforcerMethod · 0.95
SetUsageStoreMethod · 0.95
SetInternalAPISecretMethod · 0.95
RegisterRoutesMethod · 0.95
TestDBFunction · 0.92
NewStoreFunction · 0.92
NewSMTPRelayFunction · 0.92
NewSenderFunction · 0.92
NewUserAuthFunction · 0.92
NewStoreFunction · 0.92
NewEnforcerFunction · 0.92
NewStoreFunction · 0.92

Tested by

no test coverage detected