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)
| 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. |
| 16 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…