-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrace_test.go
99 lines (91 loc) · 2.18 KB
/
trace_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
package cmd_test
import (
"io"
"testing"
"github.com/hamba/cmd/v2"
"github.com/hamba/logger/v2"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
semconv "go.opentelemetry.io/otel/semconv/v1.18.0"
)
func TestNewTracer(t *testing.T) {
tests := []struct {
name string
exporter string
endpoint string
tags []string
headers []string
ratio float64
wantErr require.ErrorAssertionFunc
}{
{
name: "no tracer",
exporter: "",
endpoint: "",
ratio: 1.0,
wantErr: require.NoError,
},
{
name: "zipkin",
exporter: "zipkin",
endpoint: "http://localhost:1234/api/v2",
ratio: 1.0,
wantErr: require.NoError,
},
{
name: "with tags",
exporter: "otlphttp",
endpoint: "localhost:1234",
tags: []string{"cluster=test", "namespace=num"},
ratio: 1.0,
wantErr: require.NoError,
},
{
name: "with headers",
exporter: "otlphttp",
endpoint: "localhost:1234",
headers: []string{"cluster=test", "namespace=num"},
ratio: 1.0,
wantErr: require.NoError,
},
{
name: "unknown exporter",
exporter: "some-exporter",
endpoint: "localhost:1234",
ratio: 1.0,
wantErr: require.Error,
},
{
name: "ratio too low",
exporter: "otlpgrpc",
endpoint: "localhost:1234",
ratio: -1.0,
wantErr: require.NoError,
},
{
name: "ratio too high",
exporter: "otlpgrpc",
endpoint: "localhost:1234",
ratio: 2.0,
wantErr: require.NoError,
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
c, fs := newTestContext()
fs.String(cmd.FlagTracingExporter, test.exporter, "doc")
fs.String(cmd.FlagTracingEndpoint, test.endpoint, "doc")
fs.Var(cli.NewStringSlice(test.tags...), cmd.FlagTracingTags, "doc")
fs.Var(cli.NewStringSlice(test.headers...), cmd.FlagTracingHeaders, "doc")
fs.Float64(cmd.FlagTracingRatio, test.ratio, "doc")
log := logger.New(io.Discard, logger.LogfmtFormat(), logger.Error)
_, err := cmd.NewTracer(c, log,
semconv.ServiceNameKey.String("my-service"),
semconv.ServiceVersionKey.String("1.0.0"),
)
test.wantErr(t, err)
})
}
}