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

Function serverWithSendLimit

internal/httpapi/ratelimit_test.go:170–190  ·  view source on GitHub ↗

serverWithSendLimit builds a minimal server whose SendLimit always blocks, to assert the 429 path on the outbound chokepoint.

(t *testing.T)

Source from the content-addressed store, hash-verified

168// serverWithSendLimit builds a minimal server whose SendLimit always blocks,
169// to assert the 429 path on the outbound chokepoint.
170func serverWithSendLimit(t *testing.T) *httptest.Server {
171 t.Helper()
172 srv := httptest.NewServer(New(Deps{
173 Authenticator: func(r *http.Request) (*identity.User, error) {
174 if r.Header.Get("Authorization") == "Bearer good" {
175 return &identity.User{ID: "u_1"}, nil
176 }
177 return nil, errors.New("no")
178 },
179 GetAgent: func(ctx context.Context, address string) (*identity.AgentIdentity, error) {
180 return &identity.AgentIdentity{ID: "support@acme.com", Email: "support@acme.com", UserID: "u_1", DomainVerified: true}, nil
181 },
182 SendLimit: func(key string) (bool, time.Duration) { return false, 7 * time.Second },
183 DeliverOutbound: func(ctx context.Context, u *identity.User, ag *identity.AgentIdentity, req outbound.SendRequest, mt, rt string, ref *identity.Message) (*agent.OutboundResult, *agent.OutboundError) {
184 t.Error("DeliverOutbound must NOT be reached when rate-limited")
185 return &agent.OutboundResult{}, nil
186 },
187 }))
188 t.Cleanup(srv.Close)
189 return srv
190}
191
192func TestSendRateLimited(t *testing.T) {
193 srv := serverWithSendLimit(t)

Callers 1

TestSendRateLimitedFunction · 0.85

Calls 4

CleanupMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected