Debian Codegraph @

api/v0/detector/zoo/mock/mock.go

raw symbols SCIP
1 package mock
2
3 import (
4 "sync"
5
6 log "github.com/golang/glog"
7 "github.com/mesos/mesos-go/api/v0/detector/zoo"
8 mesos "github.com/mesos/mesos-go/api/v0/mesosproto"
9 "github.com/stretchr/testify/mock"
10 )
11
12 type Client struct {
13 mock.Mock
14 }
15
16 func (m *Client) Stopped() (a <-chan struct{}) {
17 args := m.Called()
18 if x := args.Get(0); x != nil {
19 a = x.(<-chan struct{})
20 }
21 return
22 }
23
24 func (m *Client) Stop() {
25 m.Called()
26 }
27
28 func (m *Client) Data(path string) (a []byte, b error) {
29 args := m.Called(path)
30 if x := args.Get(0); x != nil {
31 a = x.([]byte)
32 }
33 b = args.Error(1)
34 return
35 }
36
37 func (m *Client) WatchChildren(path string) (a string, b <-chan []string, c <-chan error) {
38 args := m.Called(path)
39 a = args.String(0)
40 if x := args.Get(1); x != nil {
41 b = x.(<-chan []string)
42 }
43 if x := args.Get(2); x != nil {
44 c = x.(<-chan error)
45 }
46 return
47 }
48
49 // newMockZkClient returns a mocked implementation of ZKInterface that implements expectations
50 // for Stop() and Stopped(); multiple calls to Stop() are safe.
51 func NewClient(testZkPath string, initialChildren ...string) (mocked *Client, snaps chan []string, errs chan error) {
52 var doneOnce sync.Once
53 done := make(chan struct{})
54
55 mocked = &Client{}
56 mocked.On("Stop").Return().Run(func(_ mock.Arguments) { doneOnce.Do(func() { close(done) }) })
57 mocked.On("Stopped").Return((<-chan struct{})(done))
58
59 if initialChildren != nil {
60 errs = make(chan error) // this is purposefully unbuffered (some tests depend on this)
61 snaps = make(chan []string, 1)
62 snaps <- initialChildren[:]
63 mocked.On("WatchChildren", zoo.CurrentPath).Return(
64 testZkPath, (<-chan []string)(snaps), (<-chan error)(errs)).Run(
65 func(_ mock.Arguments) { log.V(1).Infoln("WatchChildren invoked") })
66 }
67 return
68 }
69
70 // implements MasterChanged and AllMasters extension
71 type AllMastersListener struct {
72 mock.Mock
73 }
74
75 func (a *AllMastersListener) OnMasterChanged(mi *mesos.MasterInfo) {
76 a.Called(mi)
77 }
78
79 func (a *AllMastersListener) UpdatedMasters(mi []*mesos.MasterInfo) {
80 a.Called(mi)
81 }