forked from hellofresh/health-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test.go
56 lines (46 loc) · 1.2 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
package health
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/trace"
)
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
}
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)
}