Files
job-search/internal/middleware/ratelimit_test.go
T
bwilliams 465358609a Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names
Short and single-letter names in application code become full words (tests
keep theirs). Wrapped calls, signatures and composite literals put one item
per line, and one-line function bodies are expanded. Exported names and
groups of constants get doc comments, and comments refer to the renamed
identifiers.
2026-10-15 16:12:56 +01:00

26 lines
598 B
Go

package middleware
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestRateLimit(t *testing.T) {
l := NewKeyedLimiter(t.Context(), 1, 2, 0)
h := RateLimit(l, nil)(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
}))
var last int
for i := 0; i < 4; i++ {
rec := httptest.NewRecorder()
h.ServeHTTP(rec, httptest.NewRequest("GET", "/", nil))
last = rec.Code
if last == http.StatusTooManyRequests && rec.Header().Get("Retry-After") == "" {
t.Fatal("missing Retry-After")
}
}
if last != http.StatusTooManyRequests {
t.Fatalf("want 429, got %d", last)
}
}