camfish/util_test.go
2025-01-30 19:59:25 -05:00

54 lines
1.4 KiB
Go

package camfish
import "errors"
import "testing"
import "context"
func TestDefaul(test *testing.T) {
value := defaul("", "askjd")
test.Log(value)
if value != "askjd" { test.Fatal("not equal") }
value1 := defaul("zzzz", "askjd")
test.Log(value1)
if value1 != "zzzz" { test.Fatal("not equal") }
value2 := defaul(0, 3)
test.Log(value2)
if value2 != 3 { test.Fatal("not equal") }
}
func TestPanicWrap(test *testing.T) {
err := panicWrap(func () error {
return errors.New("test case 0")
})
test.Log(err)
if err.Error() != "test case 0" { test.Fatal("not equal") }
err = panicWrap(func () error {
panic(errors.New("test case 1"))
})
test.Log(err)
if err.Error() != "test case 1" { test.Fatal("not equal") }
err = panicWrap( func () error {
return nil
})
test.Log(err)
if err != nil { test.Fatal("not equal") }
}
func TestPanicWrapCtx(test *testing.T) {
err := panicWrapCtx(context.Background(), func (ctx context.Context) error {
return errors.New("test case 0")
})
test.Log(err)
if err.Error() != "test case 0" { test.Fatal("not equal") }
err = panicWrapCtx(context.Background(), func (ctx context.Context) error {
panic(errors.New("test case 1"))
})
test.Log(err)
if err.Error() != "test case 1" { test.Fatal("not equal") }
err = panicWrapCtx(context.Background(), func (ctx context.Context) error {
return nil
})
test.Log(err)
if err != nil { test.Fatal("not equal") }
}