-
Notifications
You must be signed in to change notification settings - Fork 60
/
options_test.go
99 lines (81 loc) · 2.15 KB
/
options_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 health
import (
"fmt"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
)
func TestWithChecks(t *testing.T) {
h1, err := New()
require.NoError(t, err)
assert.Len(t, h1.checks, 0)
h2, err := New(WithChecks(Config{
Name: "foo",
}, Config{
Name: "bar",
}))
require.NoError(t, err)
assert.Len(t, h2.checks, 2)
_, err = New(WithChecks(Config{
Name: "foo",
}, Config{
Name: "foo",
}))
require.Error(t, err)
}
type mockTracerProvider struct {
mock.Mock
embedded.TracerProvider
}
func (m *mockTracerProvider) Tracer(instrumentationName string, opts ...trace.TracerOption) trace.Tracer {
args := m.Called(instrumentationName, opts)
return args.Get(0).(trace.Tracer)
}
func TestWithTracerProvider(t *testing.T) {
h1, err := New()
require.NoError(t, err)
assert.Equal(t, "trace.noopTracerProvider", fmt.Sprintf("%T", h1.tp))
assert.Equal(t, "", h1.instrumentationName)
tp := new(mockTracerProvider)
instrumentationName := "test.test"
h2, err := New(WithTracerProvider(tp, instrumentationName))
require.NoError(t, err)
assert.Same(t, tp, h2.tp)
assert.Equal(t, instrumentationName, h2.instrumentationName)
}
func TestWithComponent(t *testing.T) {
h1, err := New()
require.NoError(t, err)
assert.Empty(t, h1.component.Name)
assert.Empty(t, h1.component.Version)
c := Component{
Name: "test",
Version: "1.0",
}
h2, err := New(WithComponent(c))
require.NoError(t, err)
assert.Equal(t, "test", h2.component.Name)
assert.Equal(t, "1.0", h2.component.Version)
}
func TestWithMaxConcurrent(t *testing.T) {
numCPU := runtime.NumCPU()
t.Logf("Num CPUs: %d", numCPU)
h1, err := New()
require.NoError(t, err)
assert.Equal(t, numCPU, h1.maxConcurrent)
h2, err := New(WithMaxConcurrent(13))
require.NoError(t, err)
assert.Equal(t, 13, h2.maxConcurrent)
}
func TestWithSystemInfo(t *testing.T) {
h1, err := New()
require.NoError(t, err)
assert.False(t, h1.systemInfoEnabled)
h2, err := New(WithSystemInfo())
require.NoError(t, err)
assert.True(t, h2.systemInfoEnabled)
}