@@ -30,15 +30,29 @@ func TestRecoveryLoggerWithCustomLogger(t *testing.T) {
3030 var buf bytes.Buffer
3131 var logger = log .New (& buf , "" , log .LstdFlags )
3232
33- handler := RecoveryHandler (RecoveryLogger (logger ), PrintRecoveryStack (false ))
3433 handlerFunc := http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
3534 panic ("Unexpected error!" )
3635 })
3736
38- recovery := handler ( handlerFunc )
39- recovery . ServeHTTP ( httptest . NewRecorder ( ), newRequest ( "GET" , "/subdir/asdf" ))
37+ t . Run ( "Without print stack" , func ( t * testing. T ) {
38+ handler := RecoveryHandler ( RecoveryLogger ( logger ), PrintRecoveryStack ( false ))
4039
41- if ! strings .Contains (buf .String (), "Unexpected error!" ) {
42- t .Fatalf ("Got log %#v, wanted substring %#v" , buf .String (), "Unexpected error!" )
43- }
40+ recovery := handler (handlerFunc )
41+ recovery .ServeHTTP (httptest .NewRecorder (), newRequest ("GET" , "/subdir/asdf" ))
42+
43+ if ! strings .Contains (buf .String (), "Unexpected error!" ) {
44+ t .Fatalf ("Got log %#v, wanted substring %#v" , buf .String (), "Unexpected error!" )
45+ }
46+ })
47+
48+ t .Run ("With print stack enabled" , func (t * testing.T ) {
49+ handler := RecoveryHandler (RecoveryLogger (logger ), PrintRecoveryStack (true ))
50+
51+ recovery := handler (handlerFunc )
52+ recovery .ServeHTTP (httptest .NewRecorder (), newRequest ("GET" , "/subdir/asdf" ))
53+
54+ if ! strings .Contains (buf .String (), "runtime/debug.Stack" ) {
55+ t .Fatalf ("Got log %#v, wanted substring %#v" , buf .String (), "runtime/debug.Stack" )
56+ }
57+ })
4458}
0 commit comments