forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresolver_test.go
57 lines (46 loc) · 1.15 KB
/
resolver_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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package loadbalancingexporter
import "context"
type mockResolver struct {
onStart func(context.Context) error
onShutdown func(context.Context) error
onResolve func(ctx context.Context) ([]string, error)
onChangeCallbacks []func([]string)
triggerCallbacks bool
}
func (m *mockResolver) start(ctx context.Context) error {
if m.onStart != nil {
if err := m.onStart(ctx); err != nil {
return err
}
}
_, err := m.resolve(ctx)
if err != nil {
return err
}
return nil
}
func (m *mockResolver) shutdown(ctx context.Context) error {
if m.onShutdown != nil {
return m.onShutdown(ctx)
}
return nil
}
func (m *mockResolver) resolve(ctx context.Context) ([]string, error) {
var resolved []string
var err error
if m.onResolve != nil {
resolved, err = m.onResolve(ctx)
}
if m.triggerCallbacks {
for _, callback := range m.onChangeCallbacks {
callback(resolved)
}
}
return resolved, err
}
func (m *mockResolver) onChange(f func([]string)) {
m.onChangeCallbacks = append(m.onChangeCallbacks, f)
}
var _ resolver = (*mockResolver)(nil)