-
Notifications
You must be signed in to change notification settings - Fork 191
/
func_test.go
42 lines (35 loc) · 980 Bytes
/
func_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package goutil_test
import (
"errors"
"testing"
"github.com/gookit/goutil"
"github.com/gookit/goutil/testutil/assert"
)
func TestFuncName(t *testing.T) {
name := goutil.FuncName(goutil.PkgName)
assert.Eq(t, "github.com/gookit/goutil.PkgName", name)
name = goutil.FuncName(goutil.PanicIfErr)
assert.Eq(t, "github.com/gookit/goutil.PanicIfErr", name)
err := goutil.Go(func() error {
return nil
})
assert.NoErr(t, err)
}
func TestCallOn(t *testing.T) {
assert.NoErr(t, goutil.CallOn(false, func() error {
return errors.New("a error")
}))
assert.Err(t, goutil.CallOn(true, func() error {
return errors.New("a error")
}))
assert.ErrMsg(t, goutil.CallOrElse(true, func() error {
return errors.New("a error 001")
}, func() error {
return errors.New("a error 002")
}), "a error 001")
assert.ErrMsg(t, goutil.CallOrElse(false, func() error {
return errors.New("a error 001")
}, func() error {
return errors.New("a error 002")
}), "a error 002")
}