-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
options_internal_test.go
86 lines (70 loc) · 1.73 KB
/
options_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
package otelsql
import (
"context"
"database/sql/driver"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/codes"
)
func TestTraceAll(t *testing.T) {
t.Parallel()
o := driverOptions{}
TraceAll().applyDriverOptions(&o)
assert.True(t, o.trace.AllowRoot)
assert.True(t, o.trace.Ping)
assert.True(t, o.trace.RowsNext)
assert.True(t, o.trace.RowsClose)
assert.True(t, o.trace.RowsAffected)
assert.True(t, o.trace.LastInsertID)
var (
ctx = context.Background()
query = "SELECT * FROM data WHERE country = $1"
values = []driver.NamedValue{{
Ordinal: 1,
Value: "US",
}}
)
expected := traceQueryWithArgs(ctx, query, values)
actual := o.trace.queryTracer(ctx, query, values)
assert.Equal(t, expected, actual)
}
func TestDisableErrSkip(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()
o := driverOptions{}
DisableErrSkip().applyDriverOptions(&o)
code, description := o.trace.errorToSpanStatus(tc.error)
assert.Equal(t, tc.expectedCode, code)
assert.Equal(t, tc.expectedDescription, description)
})
}
}