github.com/sandwich-go/boost@v1.3.29/xpanic/panic_when_test.go (about) 1 package xpanic 2 3 import ( 4 "errors" 5 . "github.com/smartystreets/goconvey/convey" 6 "testing" 7 ) 8 9 func TestPanicWhen(t *testing.T) { 10 Convey("panic when", t, func() { 11 var err = errors.New("error") 12 So(func() { 13 WhenErrorAsFmtFirst(err, "%w, %d", 1) 14 }, ShouldPanic) 15 So(func() { 16 WhenErrorAsFmtFirst(nil, "%w, %d", 1) 17 }, ShouldNotPanic) 18 19 Try(func() { 20 WhenErrorAsFmtFirst(err, "%w, %d", 1) 21 }).Catch(func(err E) { 22 So(err.(error).Error(), ShouldEqual, "error, 1") 23 }) 24 25 So(func() { WhenError(err) }, ShouldPanic) 26 So(func() { WhenError(nil) }, ShouldNotPanic) 27 So(func() { WhenTrue(true, "%d", 1) }, ShouldPanic) 28 So(func() { WhenTrue(false, "%d", 1) }, ShouldNotPanic) 29 }) 30 }