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

Function setupCoreAPIWithBillingHook

internal/agent/billing_hook_test.go:41–65  ·  view source on GitHub ↗

setupCoreAPIWithBillingHook wires an *agent.API to a real test DB with the billing hook pointed at a recording httptest server that responds with hookStatus.

(t *testing.T, secret string, hookStatus int)

Source from the content-addressed store, hash-verified

39// billing hook pointed at a recording httptest server that responds with
40// hookStatus.
41func setupCoreAPIWithBillingHook(t *testing.T, secret string, hookStatus int) (*agent.API, *identity.Store, *recordedHookCall) {
42 t.Helper()
43 pool := testutil.TestDB(t)
44 store := identity.NewStore(pool)
45 smtpRelay := outbound.NewSMTPRelay(&config.OutboundSMTPConfig{})
46 sender := outbound.NewSender(smtpRelay, "test.e2a.dev")
47
48 rec := &recordedHookCall{}
49 hookSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
50 body, _ := io.ReadAll(r.Body)
51 rec.mu.Lock()
52 rec.body = body
53 rec.signature = r.Header.Get("X-E2A-Internal-Signature")
54 rec.called = true
55 rec.mu.Unlock()
56 w.WriteHeader(hookStatus)
57 }))
58 t.Cleanup(hookSrv.Close)
59
60 api := agent.NewAPI(store, sender, smtpRelay, nil, usage.NewNoopUsageTracker(),
61 "e2a.dev", "test.e2a.dev", "agents.e2a.dev", "", false)
62 api.SetInternalAPISecret(secret)
63 api.SetBillingHookURL(hookSrv.URL)
64 return api, store, rec
65}
66
67// expectedHMAC re-derives the X-E2A-Internal-Signature for the recorded body.
68// Independent computation, so a bug in either side shows up.

Calls 11

SetInternalAPISecretMethod · 0.95
SetBillingHookURLMethod · 0.95
TestDBFunction · 0.92
NewStoreFunction · 0.92
NewSMTPRelayFunction · 0.92
NewSenderFunction · 0.92
NewAPIFunction · 0.92
NewNoopUsageTrackerFunction · 0.92
CleanupMethod · 0.80
GetMethod · 0.65
WriteHeaderMethod · 0.45

Tested by

no test coverage detected