MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestRecover

Function TestRecover

pkg/webmiddleware/recover_test.go:28–44  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func 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}

Callers

nothing calls this directly

Calls 4

RecoverFunction · 0.85
NewMethod · 0.65
ResultMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected