Home / Function/ TestContextBindRequestTooLarge() — gin Function Reference

TestContextBindRequestTooLarge() — gin Function Reference

Architecture documentation for the TestContextBindRequestTooLarge() function in context_test.go from the gin codebase.

Entity Profile

Dependency Diagram

graph TD
  061e77fe_ae5f_8342_408f_3c3146600d93["TestContextBindRequestTooLarge()"]
  ebe0ae48_a62b_a38f_5bac_5bbbd96fc508["context_test.go"]
  061e77fe_ae5f_8342_408f_3c3146600d93 -->|defined in| ebe0ae48_a62b_a38f_5bac_5bbbd96fc508
  style 061e77fe_ae5f_8342_408f_3c3146600d93 fill:#6366f1,stroke:#818cf8,color:#fff

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

Defined In

Frequently Asked Questions

What does TestContextBindRequestTooLarge() do?
TestContextBindRequestTooLarge() is a function in the gin codebase, defined in context_test.go.
Where is TestContextBindRequestTooLarge() defined?
TestContextBindRequestTooLarge() is defined in context_test.go at line 2107.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free