serverWithSendLimit builds a minimal server whose SendLimit always blocks, to assert the 429 path on the outbound chokepoint.
(t *testing.T)
| 168 | // serverWithSendLimit builds a minimal server whose SendLimit always blocks, |
| 169 | // to assert the 429 path on the outbound chokepoint. |
| 170 | func 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 | |
| 192 | func TestSendRateLimited(t *testing.T) { |
| 193 | srv := serverWithSendLimit(t) |
no test coverage detected