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

Function TestContextRenderAPIJSON

context_test.go:1114–1124  ·  context_test.go::TestContextRenderAPIJSON

Tests that the response is serialized as JSON we change the content-type before

(t *testing.T)

Source from the content-addressed store, hash-verified

1112// Tests that the response is serialized as JSON
1113// we change the content-type before
1114func TestContextRenderAPIJSON(t *testing.T) {
1115 w := httptest.NewRecorder()
1116 c, _ := CreateTestContext(w)
1117
1118 c.Header("Content-Type", "application/vnd.api+json")
1119 c.JSON(http.StatusCreated, H{"foo": "bar"})
1120
1121 assert.Equal(t, http.StatusCreated, w.Code)
1122 assert.JSONEq(t, `{"foo":"bar"}`, w.Body.String())
1123 assert.Equal(t, "application/vnd.api+json", w.Header().Get("Content-Type"))
1124}
1125
1126// Tests that no Custom JSON is rendered if code is 204
1127func TestContextRenderNoContentAPIJSON(t *testing.T) {

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