-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathspan_event_test.go
122 lines (113 loc) · 2.9 KB
/
span_event_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
package pinpoint
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func Test_newSpanEvent(t *testing.T) {
type args struct {
span *span
operationName string
}
tests := []struct {
name string
args args
}{
{"1", args{defaultTestSpan(), "t1"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
se := newSpanEvent(tt.args.span, tt.args.operationName)
assert.Equal(t, se.operationName, tt.args.operationName, "operationName")
assert.Equal(t, se.serviceType, int32(ServiceTypeGoFunction), "serviceType")
assert.NotNil(t, se.startTime, "startTime")
})
}
}
func Test_spanEvent_end(t *testing.T) {
type args struct {
span *span
operationName string
}
tests := []struct {
name string
args args
}{
{"1", args{defaultTestSpan(), "t1"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
se := newSpanEvent(tt.args.span, tt.args.operationName)
tt.args.span.appendSpanEvent(se)
assert.Equal(t, se.parentSpan.eventDepth, int32(2), "eventDepth")
time.Sleep(100 * time.Millisecond)
se.end()
assert.Equal(t, se.operationName, tt.args.operationName, "operationName")
assert.Equal(t, se.parentSpan.eventDepth, int32(1), "eventDepth")
assert.Greater(t, se.endElapsed, int64(99), "endElapsed")
})
}
}
func Test_spanEvent_generateNextSpanId(t *testing.T) {
type args struct {
span *span
operationName string
}
tests := []struct {
name string
args args
}{
{"1", args{defaultTestSpan(), "t1"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
se := newSpanEvent(tt.args.span, tt.args.operationName)
id := se.generateNextSpanId()
assert.Equal(t, se.operationName, tt.args.operationName, "operationName")
assert.Equal(t, se.nextSpanId, id, "nextSpanId")
assert.NotEqual(t, se.nextSpanId, int64(0), "nextSpanId")
})
}
}
func Test_spanEvent_SetError(t *testing.T) {
type args struct {
span *span
operationName string
}
tests := []struct {
name string
args args
}{
{"1", args{defaultTestSpan(), "t1"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.args.span.agent = newTestAgent(defaultConfig())
se := newSpanEvent(tt.args.span, tt.args.operationName)
se.SetError(errors.New("TEST_ERROR"))
assert.Equal(t, int32(1), se.errorFuncId, "errorFuncId")
assert.Equal(t, "TEST_ERROR", se.errorString, "errorString")
})
}
}
func Test_spanEvent_SetSQL(t *testing.T) {
type args struct {
span *span
operationName string
}
tests := []struct {
name string
args args
}{
{"1", args{defaultTestSpan(), "t1"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.args.span.agent = newTestAgent(defaultConfig())
se := newSpanEvent(tt.args.span, tt.args.operationName)
se.SetSQL("SELECT 1", "")
assert.Equal(t, len(se.annotations.list), int(1), "annotations.len")
})
}
}