MCPcopy
hub / github.com/gin-gonic/gin / TestPanicWithAbortHandler

Function TestPanicWithAbortHandler

recovery_test.go:132–153  ·  view source on GitHub ↗

TestPanicWithAbortHandler asserts that recovery handles http.ErrAbortHandler as broken pipe

(t *testing.T)

Source from the content-addressed store, hash-verified

130
131// TestPanicWithAbortHandler asserts that recovery handles http.ErrAbortHandler as broken pipe
132func TestPanicWithAbortHandler(t *testing.T) {
133 const expectCode = 204
134
135 var buf strings.Builder
136 router := New()
137 router.Use(RecoveryWithWriter(&buf))
138 router.GET("/recovery", func(c *Context) {
139 // Start writing response
140 c.Header("X-Test", "Value")
141 c.Status(expectCode)
142
143 // Panic with ErrAbortHandler which should be treated as broken pipe
144 panic(http.ErrAbortHandler)
145 })
146 // RUN
147 w := PerformRequest(router, http.MethodGet, "/recovery")
148 // TEST
149 assert.Equal(t, expectCode, w.Code)
150 out := buf.String()
151 assert.Contains(t, out, "net/http: abort Handler")
152 assert.NotContains(t, out, "panic recovered")
153}
154
155func TestCustomRecoveryWithWriter(t *testing.T) {
156 errBuffer := new(strings.Builder)

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
RecoveryWithWriterFunction · 0.85
PerformRequestFunction · 0.85
UseMethod · 0.65
GETMethod · 0.65
StatusMethod · 0.65
StringMethod · 0.65
HeaderMethod · 0.45

Tested by

no test coverage detected