forked from armon/go-chord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ring_mock_test.go
70 lines (56 loc) · 1.24 KB
/
ring_mock_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
package buddystore
import (
"hash"
"github.com/stretchr/testify/mock"
"sync"
)
type MockRing struct {
mock.Mock
transport Transport
numSuccessors int
hashfunc func() hash.Hash
mockLock sync.Mutex
}
func (m MockRing) GetNumSuccessors() int {
return m.numSuccessors
}
func (m *MockRing) Leave() error {
m.mockLock.Lock()
defer m.mockLock.Unlock()
args := m.Mock.Called()
res, _ := args.Get(0).(error)
return res
}
func (m *MockRing) Lookup(n int, key []byte) ([]*Vnode, error) {
m.mockLock.Lock()
defer m.mockLock.Unlock()
args := m.Mock.Called(n, key)
res, ok := args.Get(0).([]*Vnode)
if !ok {
return nil, args.Error(1)
}
return res, args.Error(1)
}
func (m *MockRing) Shutdown() {
m.mockLock.Lock()
defer m.mockLock.Unlock()
m.Mock.Called()
}
func (m *MockRing) Transport() Transport {
m.mockLock.Lock()
defer m.mockLock.Unlock()
return m.transport
}
func (m *MockRing) GetLocalVnode() *Vnode {
panic("TODO: MockRing.GetLocalVnode")
}
func (m *MockRing) GetLocalLocalVnode() *localVnode {
panic("TODO: MockRing.GetLocalVnode")
}
func (m *MockRing) GetRingId() string {
panic("TODO: MockRing.GetRingId")
}
func (m *MockRing) GetHashFunc() func() hash.Hash {
return m.hashfunc
}
var _ RingIntf = new(MockRing)