-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_test.go
More file actions
61 lines (50 loc) · 1.35 KB
/
Copy pathfunc_test.go
File metadata and controls
61 lines (50 loc) · 1.35 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package xerror_test
import (
"testing"
"github.com/save95/xerror"
"github.com/save95/xerror/ecode"
"github.com/save95/xerror/xcode"
)
func TestNew(t *testing.T) {
t.Log(xcode.New(500))
t.Log(xerror.New("this is new error"))
err := xerror.WithXCode(xcode.InternalServerError)
t.Log(err, " / ", err.ToMessage(&ecode.Config{}))
}
func TestNewWithCode(t *testing.T) {
err := xerror.WithCode(100001, "木有登陆")
t.Log(err)
t.Log(err.ToMessage(nil))
}
func TestNewWithXCode(t *testing.T) {
err := xerror.WithXCode(xcode.InternalServerError)
t.Log(err)
t.Log(err.ToMessage(nil))
}
func TestWithXCodeMessage(t *testing.T) {
err := xerror.WithXCodeMessage(xcode.InternalServerError, "变更消息")
t.Log(err)
t.Log(err.ToMessage(nil))
}
func TestParsePayload(t *testing.T) {
err := xerror.WithXCodeMessage(xcode.InternalServerError, "变更消息")
t.Log(xerror.ParsePayload(err))
err2 := xerror.Wrap(err, "错误2").
WithFields("abc").
WithFields(map[string]interface{}{
"k": "v",
"a": 1,
})
t.Log(xerror.ParsePayload(err2))
}
func TestStackTraceString(t *testing.T) {
err := xerror.WithXCodeMessage(xcode.InternalServerError, "变更消息")
t.Log(xerror.FormatStackTrace(err))
err2 := xerror.Wrap(err, "错误2").
WithFields("abc").
WithFields(map[string]interface{}{
"k": "v",
"a": 1,
})
t.Log(xerror.FormatStackTrace(err2))
}