Files
mtusi2026lab7/internal/transport/http/handlers/handler_test.go
T
2026-11-22 23:33:11 +03:00

24 lines
503 B
Go

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)
}
}