TestContextJSONStatusAcrossReset guards the reused delayedStatusWriter (c.dsw): a second JSON response on a pooled+Reset Context must use the new status, not inherit the previous one.
(t *testing.T)
| 29 | // TestContextJSONStatusAcrossReset guards the reused delayedStatusWriter (c.dsw): a second JSON |
| 30 | // response on a pooled+Reset Context must use the new status, not inherit the previous one. |
| 31 | func TestContextJSONStatusAcrossReset(t *testing.T) { |
| 32 | e := New() |
| 33 | c := e.NewContext(httptest.NewRequest(http.MethodGet, "/", nil), httptest.NewRecorder()) |
| 34 | assert.NoError(t, c.JSON(http.StatusTeapot, map[string]int{"a": 1})) |
| 35 | |
| 36 | rec2 := httptest.NewRecorder() |
| 37 | c.Reset(httptest.NewRequest(http.MethodGet, "/", nil), rec2) |
| 38 | assert.NoError(t, c.JSON(http.StatusCreated, map[string]int{"b": 2})) |
| 39 | assert.Equal(t, http.StatusCreated, rec2.Code) |
| 40 | assert.JSONEq(t, `{"b":2}`, rec2.Body.String()) |
| 41 | } |
| 42 | |
| 43 | // TestNestedJSONUsesFreshDelayedWriter guards the nested c.JSON case: a serializer that calls c.JSON |
| 44 | // re-entrantly must not corrupt the outer delayedStatusWriter (regression test for c.dsw self-reference). |
nothing calls this directly
no test coverage detected
searching dependent graphs…