Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839package api
import ( "net/http" "testing")
func TestRateLimit_DeniesAfterBurst(t *testing.T) { e, _ := newTestEnv(t) var sawDeny bool for i := 0; i < 60; i++ { w := do(t, e, "GET", "/api/get", nil, nil) if w.Code == http.StatusTooManyRequests { sawDeny = true break } } if !sawDeny { t.Errorf("expected a 429 within 60 requests; rate limiter did not deny") }}
func TestAddRateLimit_DeniesQuicklyOnAdd(t *testing.T) { e, _ := newTestEnv(t) // Burst is 3; the 4th-ish request from the same IP should get rate-limited. var sawDeny bool for i := 0; i < 10; i++ { body := map[string]string{"quote": "unique quote number " + string(rune('a'+i))} w := do(t, e, "POST", "/api/add", body, nil) if w.Code == http.StatusTooManyRequests { sawDeny = true break } } if !sawDeny { t.Errorf("expected /api/add to 429 within 10 requests; per-route limiter did not deny") }}