TestPanicWithAbortHandler asserts that recovery handles http.ErrAbortHandler as broken pipe
(t *testing.T)
| 130 | |
| 131 | // TestPanicWithAbortHandler asserts that recovery handles http.ErrAbortHandler as broken pipe |
| 132 | func 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 | |
| 155 | func TestCustomRecoveryWithWriter(t *testing.T) { |
| 156 | errBuffer := new(strings.Builder) |
nothing calls this directly
no test coverage detected