package handlers import ( "errors" "net/http/httptest" "strings" "testing" ) func TestDecodeJSONRejectsBodyAboveOneMiB(t *testing.T) { request := httptest.NewRequest( "POST", "/api/v1/users", strings.NewReader(strings.Repeat(" ", maxJSONBodyBytes+1)), ) request.Header.Set("Content-Type", "application/json") var destination map[string]any err := decodeJSON(request, &destination) if !errors.Is(err, errJSONBodyTooLarge) { t.Fatalf("expected errJSONBodyTooLarge, got %v", err) } }