forked from kostyay/gorm-opentelemetry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbacks_test.go
59 lines (53 loc) · 1.01 KB
/
callbacks_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
package otelgorm
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/trace"
)
func TestChunkBy(t *testing.T) {
tests := []struct {
input string
max int
output []string
}{
{
"1234",
1,
[]string{"1", "2", "3", "4"},
},
{
"1234",
2,
[]string{"12", "34"},
},
{
"1234",
4,
[]string{"1234"},
},
{
"1234",
5,
[]string{"1234"},
},
}
for idx, tc := range tests {
t.Run(fmt.Sprintf("test_%d", idx), func(tt *testing.T) {
result := []string{}
chunkBy(tc.input, tc.max, func(s string, option ...trace.EventOption) {
result = append(result, s)
})
require.Equal(tt, tc.output, result)
})
}
}
func TestWithOmitVariablesFromTrace(t *testing.T) {
ctx := context.Background()
shouldOmit, _ := ctx.Value(omitVarsKey).(bool)
require.NotEqual(t, shouldOmit, true)
ctx = WithOmitVariablesFromTrace(context.Background())
shouldOmit, _ = ctx.Value(omitVarsKey).(bool)
require.Equal(t, shouldOmit, true)
}