forked from mtusi2026/mtusi2026lab7
24 lines
503 B
Go
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)
|
|
}
|
|
}
|