24
"github.com/stretchr/testify/require"
27
func TestServerRecovery(t *testing.T) {
30
router.Router.PanicHandler = defaultRecovery
31
router.Use(func(c *Context) {
32
panic("in interceptor")
34
router.Handle(http.MethodGet, "/", func(c *Context) {
38
w := new(mockResponseWriter)
39
req, _ := http.NewRequest(http.MethodGet, "/", nil)
40
require.Panics(t, func() {
41
router.ServeHTTP(w, req)
46
router.Router.PanicHandler = defaultRecovery
47
router.Use(func(c *Context) {
50
router.Handle(http.MethodGet, "/", func(c *Context) {
54
w := new(mockResponseWriter)
55
req, _ := http.NewRequest(http.MethodGet, "/", nil)
56
require.Panics(t, func() {
57
router.ServeHTTP(w, req)
62
router.Router.PanicHandler = defaultRecovery
63
router.Use(func(c *Context) {
66
router.Handle(http.MethodGet, "/", func(c *Context) {
68
Err: &os.SyscallError{
70
Err: errors.New("broken pipe"),
75
w := new(mockResponseWriter)
76
req, _ := http.NewRequest(http.MethodGet, "/", nil)
77
require.NotPanics(t, func() {
78
router.ServeHTTP(w, req)
83
router.Router.PanicHandler = defaultRecovery
84
router.Use(func(c *Context) {
86
Err: &os.SyscallError{
87
Syscall: "Middleware",
88
Err: errors.New("connection reset by peer"),
92
router.Handle(http.MethodGet, "/", func(c *Context) {
96
w := new(mockResponseWriter)
97
req, _ := http.NewRequest(http.MethodGet, "/", nil)
98
require.NotPanics(t, func() {
99
router.ServeHTTP(w, req)