MCPcopy
hub / github.com/gin-gonic/gin / TestContextRenderNoContentAPIJSON

Function TestContextRenderNoContentAPIJSON

context_test.go:1127–1137  ·  context_test.go::TestContextRenderNoContentAPIJSON

Tests that no Custom JSON is rendered if code is 204

(t *testing.T)

Source from the content-addressed store, hash-verified

1125
1126// Tests that no Custom JSON is rendered if code is 204
1127func TestContextRenderNoContentAPIJSON(t *testing.T) {
1128 w := httptest.NewRecorder()
1129 c, _ := CreateTestContext(w)
1130
1131 c.Header("Content-Type", "application/vnd.api+json")
1132 c.JSON(http.StatusNoContent, H{"foo": "bar"})
1133
1134 assert.Equal(t, http.StatusNoContent, w.Code)
1135 assert.Empty(t, w.Body.String())
1136 assert.Equal(t, "application/vnd.api+json", w.Header().Get("Content-Type"))
1137}
1138
1139// Tests that the response is serialized as JSON
1140// and Content-Type is set to application/json

Callers

nothing calls this directly

Calls 5

CreateTestContextFunction · 0.85
StringMethod · 0.65
HeaderMethod · 0.45
JSONMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected