-
Notifications
You must be signed in to change notification settings - Fork 0
/
storerStub.go
137 lines (111 loc) · 2.95 KB
/
storerStub.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package mock
// StorerStub -
type StorerStub struct {
PutCalled func(key, data []byte) error
GetCalled func(key []byte) ([]byte, error)
GetFromEpochCalled func(key []byte, epoch uint32) ([]byte, error)
GetBulkFromEpochCalled func(keys [][]byte, epoch uint32) (map[string][]byte, error)
HasCalled func(key []byte) error
HasInEpochCalled func(key []byte, epoch uint32) error
SearchFirstCalled func(key []byte) ([]byte, error)
RemoveCalled func(key []byte) error
ClearCacheCalled func()
DestroyUnitCalled func() error
RangeKeysCalled func(handler func(key []byte, val []byte) bool)
PutInEpochCalled func(key, data []byte, epoch uint32) error
GetOldestEpochCalled func() (uint32, error)
CloseCalled func() error
}
// PutInEpoch -
func (ss *StorerStub) PutInEpoch(key, data []byte, epoch uint32) error {
if ss.PutInEpochCalled != nil {
return ss.PutInEpochCalled(key, data, epoch)
}
return nil
}
// GetFromEpoch -
func (ss *StorerStub) GetFromEpoch(key []byte, epoch uint32) ([]byte, error) {
if ss.GetFromEpochCalled != nil {
return ss.GetFromEpochCalled(key, epoch)
}
return nil, nil
}
// GetBulkFromEpoch -
func (ss *StorerStub) GetBulkFromEpoch(keys [][]byte, epoch uint32) (map[string][]byte, error) {
if ss.GetBulkFromEpochCalled != nil {
return ss.GetBulkFromEpochCalled(keys, epoch)
}
return nil, nil
}
// SearchFirst -
func (ss *StorerStub) SearchFirst(key []byte) ([]byte, error) {
if ss.SearchFirstCalled != nil {
return ss.SearchFirstCalled(key)
}
return nil, nil
}
// Close -
func (ss *StorerStub) Close() error {
if ss.CloseCalled != nil {
return ss.CloseCalled()
}
return nil
}
// Put -
func (ss *StorerStub) Put(key, data []byte) error {
if ss.PutCalled != nil {
return ss.PutCalled(key, data)
}
return nil
}
// Get -
func (ss *StorerStub) Get(key []byte) ([]byte, error) {
if ss.GetCalled != nil {
return ss.GetCalled(key)
}
return nil, nil
}
// Has -
func (ss *StorerStub) Has(key []byte) error {
if ss.HasCalled != nil {
return ss.HasCalled(key)
}
return nil
}
// Remove -
func (ss *StorerStub) Remove(key []byte) error {
if ss.RemoveCalled != nil {
return ss.RemoveCalled(key)
}
return nil
}
// ClearCache -
func (ss *StorerStub) ClearCache() {
if ss.ClearCacheCalled != nil {
ss.ClearCacheCalled()
}
}
// DestroyUnit -
func (ss *StorerStub) DestroyUnit() error {
if ss.DestroyUnitCalled != nil {
return ss.DestroyUnitCalled()
}
return nil
}
// RangeKeys -
func (ss *StorerStub) RangeKeys(handler func(key []byte, val []byte) bool) {
if ss.RangeKeysCalled != nil {
ss.RangeKeysCalled(handler)
}
}
// GetOldestEpoch -
func (ss *StorerStub) GetOldestEpoch() (uint32, error) {
if ss.GetOldestEpochCalled != nil {
return ss.GetOldestEpochCalled()
}
return 0, nil
}
// IsInterfaceNil returns true if there is no value under the interface
func (ss *StorerStub) IsInterfaceNil() bool {
return ss == nil
}