-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
132 lines (107 loc) · 2.62 KB
/
error_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package log_test
import (
"context"
"fmt"
"strings"
"testing"
"time"
log "github.com/subiz/log"
)
func A() error {
err := B()
return err
}
func B() error {
err := CCCCCC()
return err
}
func CCCCCC() error {
err := DDDDDD()
return err
}
func DDDDDD() error {
err := E()
return err
}
func E() error {
err := log.EServer(nil, log.M{"number3": "thanh"})
return err
}
func TestError(t *testing.T) {
// err := log.EInvalidZaloToken("thanh", "3290323", "Dayladau") // A()
err := A()
fmt.Println("EEEEEE", err.Error())
}
func TestLogErr(t *testing.T) {
err := log.EInvalidGoogleToken("thanh", "3290323", "Dayladau") // A()
log.Err("subiz", err, "param")
}
func TestWrap(t *testing.T) {
var err error = log.EAccountLocked("thanh") // A()
log.WrapStack(err, 0)
time.Sleep(20 * time.Second)
}
func TestToJson(t *testing.T) {
err := log.EAccountLocked("thanh") // A()
str := err.ToJSON()
fmt.Println("JSON:", str)
}
func TestMarshalJson(t *testing.T) {
err := log.EAccountLocked("thanh") // A()
str := log.NewError(err, nil).ToJSON()
fmt.Println("JSON--------:", str)
}
func TestDontModify(t *testing.T) {
err := log.EAccountLocked("thanh") // A()
log.EServer(err, log.M{"secret": "2340asdffEIFJ42"})
str := log.NewError(err, nil).ToJSON()
if strings.Contains(str, "2340asdffEIFJ42") {
t.Error("should not contain")
}
}
func A2(ctx context.Context) error {
err := B2(ctx)
return err
}
func B2(ctx context.Context) error {
err := CCCCCC2(ctx)
return err
}
func CCCCCC2(ctx context.Context) error {
err := DDDDDD2(ctx)
return err
}
func DDDDDD2(ctx context.Context) error {
err := E2(ctx)
return err
}
func E2(ctx context.Context) error {
err := log.Error(ctx, nil, "internal", "number3", "thanh")
return err
}
func TestNoSpanError(t *testing.T) {
defer log.Shutdown()
// no trace must work
// err := log.EInvalidZaloToken("thanh", "3290323", "Dayladau") // A()
ctx := context.Background()
ctx = context.WithValue(ctx, "account_id", "abcsble")
err := A2(ctx)
fmt.Println("EEEEEE", err.Error())
}
func TestSpanError(t *testing.T) {
defer log.Shutdown()
ctx, span := log.Start(context.Background(), "terrorst")
defer span.End()
// err := log.EInvalidZaloToken("thanh", "3290323", "Dayladau") // A()
ctx = context.WithValue(ctx, "account_id", "abcsble")
err := A2(ctx)
fmt.Println("EEEEEE", err.Error())
}
func TestSpanInfo(t *testing.T) {
defer log.Shutdown()
ctx, span := log.Start(context.Background(), "terinfo")
defer span.End()
// err := log.EInvalidZaloToken("thanh", "3290323", "Dayladau") // A()
log.SetAttributesContext(ctx, "account_id", "abcsble")
log.InfoContext(ctx, "xin chao the gioi")
}