(t *testing.T)
| 26 | ) |
| 27 | |
| 28 | func TestRecover(t *testing.T) { |
| 29 | m := Recover() |
| 30 | |
| 31 | a := assertions.New(t) |
| 32 | r := httptest.NewRequest(http.MethodGet, "/", nil) |
| 33 | rec := httptest.NewRecorder() |
| 34 | m(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 35 | panic("this panic is expected") |
| 36 | })).ServeHTTP(rec, r) |
| 37 | |
| 38 | res := rec.Result() |
| 39 | |
| 40 | a.So(res.StatusCode, should.Equal, http.StatusInternalServerError) |
| 41 | |
| 42 | body, _ := io.ReadAll(res.Body) |
| 43 | a.So(string(body), should.ContainSubstring, "http_recovered") |
| 44 | } |