-
Notifications
You must be signed in to change notification settings - Fork 0
/
span_test.go
97 lines (71 loc) · 2.01 KB
/
span_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
package tracing_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/angelokurtis/go-tracing"
)
func TestSpan_Info(t *testing.T) {
t.Parallel()
t.Run("SHOULD show receiver and function name WHEN ask for operation name", func(t *testing.T) {
t.Parallel()
closer, err := tracing.Initialize()
if err != nil {
t.Fatal(err)
}
defer closer.Close()
_, ctx := tracing.StartSpanFromContext(context.TODO())
info := new(empty).f(ctx)
assert.Equal(t, "(*empty).f", info.OperationName)
})
t.Run("SHOULD have a trace id WHEN child context is started", func(t *testing.T) {
t.Parallel()
closer, err := tracing.Initialize()
if err != nil {
t.Fatal(err)
}
defer closer.Close()
_, ctx := tracing.StartSpanFromContext(context.TODO())
info := new(empty).f(ctx)
assert.Len(t, info.TraceID, 16)
})
t.Run("SHOULD have a span id WHEN child context is started", func(t *testing.T) {
t.Parallel()
closer, err := tracing.Initialize()
if err != nil {
t.Fatal(err)
}
defer closer.Close()
_, ctx := tracing.StartSpanFromContext(context.TODO())
info := new(empty).f(ctx)
assert.Len(t, info.SpanID, 16)
})
t.Run("SHOULD generate a new span id WHEN child context is started", func(t *testing.T) {
t.Parallel()
closer, err := tracing.Initialize()
if err != nil {
t.Fatal(err)
}
defer closer.Close()
_, ctx := tracing.StartSpanFromContext(context.TODO())
info := new(empty).f(ctx)
assert.NotEqual(t, info.SpanID, info.TraceID)
})
t.Run("SHOULD parent id must be equal the caller id WHEN child context is started", func(t *testing.T) {
t.Parallel()
closer, err := tracing.Initialize()
if err != nil {
t.Fatal(err)
}
defer closer.Close()
_, ctx := tracing.StartSpanFromContext(context.TODO())
info := new(empty).f(ctx)
assert.Equal(t, info.ParentID, info.TraceID)
})
}
type empty struct{}
func (e *empty) f(ctx context.Context) *tracing.Info {
span, _ := tracing.StartSpanFromContext(ctx)
info := span.Info()
return info
}