generated from xmidt-org/.go-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tracingFactory_test.go
82 lines (73 loc) · 1.81 KB
/
tracingFactory_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
// SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package candlelight
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/propagation"
)
func TestNew(t *testing.T) {
tcs := []struct {
Description string
ShouldFail bool
ExpectIsNoop bool
Config Config
}{
{
Description: "Default means disabled tracing",
ShouldFail: false,
ExpectIsNoop: true,
Config: Config{},
},
{
Description: "Provider not found",
ShouldFail: true,
Config: Config{
Provider: "somethingElse",
},
},
{
Description: "Stdout provider",
ShouldFail: false,
ExpectIsNoop: false,
Config: Config{
Provider: "stdout",
},
},
}
for _, tc := range tcs {
t.Run(tc.Description, func(t *testing.T) {
assert := assert.New(t)
tracing, err := New(tc.Config)
if tc.ShouldFail {
assert.NotNil(err)
} else {
assert.Nil(err)
assert.Equal(tc.ExpectIsNoop, tracing.IsNoop())
}
})
}
}
func TestTracing(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
tracerProvider, err := ConfigureTracerProvider(Config{Provider: "stdout"})
require.Nil(err)
propagator := propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{})
tracing := Tracing{
tracerProvider: tracerProvider,
propagator: propagator,
}
assert.False(tracing.IsNoop())
assert.NotNil(tracing.TracerProvider())
assert.Equal(tracerProvider, tracing.TracerProvider())
assert.Equal(propagator, tracing.Propagator())
}
func TestTracingDefault(t *testing.T) {
assert := assert.New(t)
var tracing Tracing
assert.True(tracing.IsNoop())
assert.NotNil(tracing.TracerProvider())
assert.NotNil(tracing.Propagator())
}