gitee.com/gricks/utils@v1.0.8/recover_test.go (about) 1 package utils 2 3 import ( 4 "os" 5 "testing" 6 7 "gitee.com/gricks/logrus" 8 ) 9 10 func TestRecover(t *testing.T) { 11 logger := logrus.New(logrus.WithFile("recover")) 12 defer os.Remove("recover.log") 13 defer logger.Close() 14 15 entry := logger.GetEntry() 16 var wrong bool 17 defer func() { 18 if wrong { 19 entry.Error("yep, something wrong.") 20 } else { 21 entry.Error("wow.") 22 } 23 }() 24 defer Recover(entry, &wrong) 25 26 panic("deliberate error") 27 }