Home / Function/ TestContextAbortWithStatusJSON() — gin Function Reference

TestContextAbortWithStatusJSON() — gin Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

context_test.go lines 1834–1858

func TestContextAbortWithStatusJSON(t *testing.T) {
	w := httptest.NewRecorder()
	c, _ := CreateTestContext(w)
	c.index = 4

	in := new(testJSONAbortMsg)
	in.Bar = "barValue"
	in.Foo = "fooValue"

	c.AbortWithStatusJSON(http.StatusUnsupportedMediaType, in)

	assert.Equal(t, abortIndex, c.index)
	assert.Equal(t, http.StatusUnsupportedMediaType, c.Writer.Status())
	assert.Equal(t, http.StatusUnsupportedMediaType, w.Code)
	assert.True(t, c.IsAborted())

	contentType := w.Header().Get("Content-Type")
	assert.Equal(t, "application/json; charset=utf-8", contentType)

	buf := new(bytes.Buffer)
	_, err := buf.ReadFrom(w.Body)
	require.NoError(t, err)
	jsonStringBody := buf.String()
	assert.JSONEq(t, "{\"foo\":\"fooValue\",\"bar\":\"barValue\"}", jsonStringBody)
}

Domain

Subdomains

Defined In

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free