Skip to content

Commit aa7fc49

Browse files
authored
Merge pull request #1333 from Azure/let-unit-tests-panic
frontend: Do not handle panics when running "go test"
2 parents 6c4a5e1 + 0cab644 commit aa7fc49

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

frontend/pkg/frontend/middleware_panic.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@ import (
77
"fmt"
88
"net/http"
99
"runtime/debug"
10+
"testing"
1011

1112
"github.com/Azure/ARO-HCP/internal/api/arm"
1213
)
1314

1415
func MiddlewarePanic(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
15-
defer func() {
16-
if e := recover(); e != nil {
17-
logger := LoggerFromContext(r.Context())
18-
logger.Error(fmt.Sprintf("panic: %#v\n%s\n", e, string(debug.Stack())))
19-
arm.WriteInternalServerError(w)
20-
}
21-
}()
16+
// Do not catch panics when running "go test".
17+
if !testing.Testing() {
18+
defer func() {
19+
if e := recover(); e != nil {
20+
logger := LoggerFromContext(r.Context())
21+
logger.Error(fmt.Sprintf("panic: %#v\n%s\n", e, string(debug.Stack())))
22+
arm.WriteInternalServerError(w)
23+
}
24+
}()
25+
}
2226

2327
next(w, r)
2428
}

0 commit comments

Comments
 (0)