-
Notifications
You must be signed in to change notification settings - Fork 17
/
mock.go
48 lines (39 loc) · 1.02 KB
/
mock.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
package lock
import "errors"
// MockLocker implements the RuleLocker interface.
type MockLocker struct {
Channel chan bool
ErrorMsg *string
}
func (tlkr *MockLocker) Lock(key string, options ...Option) (RuleLock, error) {
if tlkr.ErrorMsg != nil {
return nil, errors.New(*tlkr.ErrorMsg)
}
tLock := mockLock{
channel: tlkr.Channel,
}
return &tLock, nil
}
type mockLock struct {
channel chan bool
}
func (tl *mockLock) Unlock() error {
tl.channel <- true
return nil
}
// FuncMockLocker instances are driven by functions that are provided.
type FuncMockLocker struct {
LockF func(string, ...Option) (RuleLock, error)
}
// Lock is a mock implementation of RuleLock.Lock
func (ml FuncMockLocker) Lock(key string, options ...Option) (RuleLock, error) {
return ml.LockF(key, options...)
}
// FuncMockLock instances are driven by functions that are provided.
type FuncMockLock struct {
UnlockF func() error
}
// Unlock is a mock implementation of RuleLock.Unlock
func (ml FuncMockLock) Unlock() error {
return ml.UnlockF()
}