TestContextBindRequestTooLarge() — gin Function Reference
Architecture documentation for the TestContextBindRequestTooLarge() function in context_test.go from the gin codebase.
Entity Profile
Relationship Graph
Source Code
context_test.go lines 2107–2136
func TestContextBindRequestTooLarge(t *testing.T) {
// When using go-json as JSON encoder, they do not propagate the http.MaxBytesError error
// The response will fail with a generic 400 instead of 413
// https://github.com/goccy/go-json/issues/485
var expectedCode int
switch json.Package {
case "github.com/goccy/go-json":
expectedCode = http.StatusBadRequest
default:
expectedCode = http.StatusRequestEntityTooLarge
}
w := httptest.NewRecorder()
c, _ := CreateTestContext(w)
c.Request, _ = http.NewRequest(http.MethodPost, "/", strings.NewReader(`{"foo":"bar", "bar":"foo"}`))
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 10)
var obj struct {
Foo string `json:"foo"`
Bar string `json:"bar"`
}
require.Error(t, c.BindJSON(&obj))
c.Writer.WriteHeaderNow()
assert.Empty(t, obj.Bar)
assert.Empty(t, obj.Foo)
assert.Equal(t, expectedCode, w.Code)
assert.True(t, c.IsAborted())
}
Domain
Subdomains
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free