MCPcopy Index your code
hub / github.com/labstack/echo / TestContextJSONStatusAcrossReset

Function TestContextJSONStatusAcrossReset

dispatch_pool_test.go:31–41  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
31func 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).

Callers

nothing calls this directly

Calls 5

JSONMethod · 0.95
ResetMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…