MCPcopy
hub / github.com/labstack/echo / TestContextJSON

Function TestContextJSON

context_test.go:221–233  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

219}
220
221func TestContextJSON(t *testing.T) {
222 e := New()
223 rec := httptest.NewRecorder()
224 req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userJSON))
225 c := e.NewContext(req, rec)
226
227 err := c.JSON(http.StatusOK, user{ID: 1, Name: "Jon Snow"})
228 if assert.NoError(t, err) {
229 assert.Equal(t, http.StatusOK, rec.Code)
230 assert.Equal(t, MIMEApplicationJSON, rec.Header().Get(HeaderContentType))
231 assert.Equal(t, userJSON+"\n", rec.Body.String())
232 }
233}
234
235func TestContextJSONErrorsOut(t *testing.T) {
236 e := New()

Callers

nothing calls this directly

Calls 6

JSONMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80
GetMethod · 0.45
HeaderMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…