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

Function TestDefaultJSONCodec_Encode

json_test.go:16–49  ·  view source on GitHub ↗

Note this test is deliberately simple as there's not a lot to test. Just need to ensure it writes JSONs. The heavy work is done by the context methods.

(t *testing.T)

Source from the content-addressed store, hash-verified

14// Note this test is deliberately simple as there's not a lot to test.
15// Just need to ensure it writes JSONs. The heavy work is done by the context methods.
16func TestDefaultJSONCodec_Encode(t *testing.T) {
17 e := New()
18 req := httptest.NewRequest(http.MethodPost, "/", nil)
19 rec := httptest.NewRecorder()
20 c := e.NewContext(req, rec)
21
22 // Echo
23 assert.Equal(t, e, c.Echo())
24
25 // Request
26 assert.NotNil(t, c.Request())
27
28 // Response
29 assert.NotNil(t, c.Response())
30
31 //--------
32 // Default JSON encoder
33 //--------
34
35 enc := new(DefaultJSONSerializer)
36
37 err := enc.Serialize(c, user{ID: 1, Name: "Jon Snow"}, "")
38 if assert.NoError(t, err) {
39 assert.Equal(t, userJSON+"\n", rec.Body.String())
40 }
41
42 req = httptest.NewRequest(http.MethodPost, "/", nil)
43 rec = httptest.NewRecorder()
44 c = e.NewContext(req, rec)
45 err = enc.Serialize(c, user{ID: 1, Name: "Jon Snow"}, " ")
46 if assert.NoError(t, err) {
47 assert.Equal(t, userJSONPretty+"\n", rec.Body.String())
48 }
49}
50
51// Note this test is deliberately simple as there's not a lot to test.
52// Just need to ensure it writes JSONs. The heavy work is done by the context methods.

Callers

nothing calls this directly

Calls 7

EchoMethod · 0.95
RequestMethod · 0.95
ResponseMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80
SerializeMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…