forked from nhatthm/otelsql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracer_internal_test.go
98 lines (83 loc) · 2 KB
/
tracer_internal_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
package otelsql
import (
"context"
"database/sql/driver"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/codes"
)
func TestFormatSpanName(t *testing.T) {
t.Parallel()
actual := formatSpanName(context.Background(), "ping")
expected := "sql:ping"
assert.Equal(t, expected, actual)
}
func TestSpanStatusFromError(t *testing.T) {
t.Parallel()
testCases := []struct {
scenario string
error error
expectedCode codes.Code
expectedDescription string
}{
{
scenario: "no error",
error: nil,
expectedCode: codes.Ok,
expectedDescription: "",
},
{
scenario: "no error",
error: errors.New("error"),
expectedCode: codes.Error,
expectedDescription: "error",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()
code, description := spanStatusFromError(tc.error)
assert.Equal(t, tc.expectedCode, code)
assert.Equal(t, tc.expectedDescription, description)
})
}
}
func TestSpanStatusFromErrorIgnoreErrSkip(t *testing.T) {
t.Parallel()
testCases := []struct {
scenario string
error error
expectedCode codes.Code
expectedDescription string
}{
{
scenario: "no error",
error: nil,
expectedCode: codes.Ok,
expectedDescription: "",
},
{
scenario: "skip",
error: driver.ErrSkip,
expectedCode: codes.Ok,
expectedDescription: "",
},
{
scenario: "no error",
error: errors.New("error"),
expectedCode: codes.Error,
expectedDescription: "error",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()
code, description := spanStatusFromErrorIgnoreErrSkip(tc.error)
assert.Equal(t, tc.expectedCode, code)
assert.Equal(t, tc.expectedDescription, description)
})
}
}