-
Notifications
You must be signed in to change notification settings - Fork 100
/
mocks.go
59 lines (50 loc) · 1.23 KB
/
mocks.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
package fixtures
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
// MockNodePicker implements a mock nodes.NodePicker from github.com/atlassian/gostatsd/internal/cluster/nodes
type MockNodePicker struct {
TB testing.TB
FnAdd func(node string)
FnList func() []string
FnRemove func(node string)
FnRun func(ctx context.Context)
FnSelect func(key string) (string, bool, error)
}
func (m *MockNodePicker) Add(node string) {
if m.FnAdd != nil {
m.FnAdd(node)
} else {
assert.Fail(m.TB, "NodePicker.Add must not be called")
}
}
func (m *MockNodePicker) List() (p0 []string) {
if m.FnList != nil {
return m.FnList()
}
assert.Fail(m.TB, "NodePicker.List must not be called")
return
}
func (m *MockNodePicker) Remove(node string) {
if m.FnRemove != nil {
m.FnRemove(node)
} else {
assert.Fail(m.TB, "NodePicker.Remove must not be called")
}
}
func (m *MockNodePicker) Run(ctx context.Context) {
if m.FnRun != nil {
m.FnRun(ctx)
} else {
assert.Fail(m.TB, "NodePicker.Run must not be called")
}
}
func (m *MockNodePicker) Select(key string) (p0 string, p1 bool, p2 error) {
if m.FnSelect != nil {
return m.FnSelect(key)
}
assert.Fail(m.TB, "NodePicker.Select must not be called")
return
}