-
Notifications
You must be signed in to change notification settings - Fork 199
/
timerMock.go
52 lines (44 loc) · 896 Bytes
/
timerMock.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
package mock
import (
"sync"
"time"
)
// TimerMock -
type TimerMock struct {
secondsMutex *sync.RWMutex
seconds int64
NowCalled func() time.Time
}
// NewTimerMock -
func NewTimerMock() *TimerMock {
return &TimerMock{
seconds: 0,
secondsMutex: &sync.RWMutex{},
}
}
// Now -
func (tm *TimerMock) Now() time.Time {
if tm.NowCalled != nil {
return tm.NowCalled()
}
tm.secondsMutex.RLock()
currentSeconds := time.Unix(tm.seconds, 0)
tm.secondsMutex.RUnlock()
return currentSeconds
}
// IsInterfaceNil -
func (tm *TimerMock) IsInterfaceNil() bool {
return tm == nil
}
// IncrementSeconds -
func (tm *TimerMock) IncrementSeconds(value int) {
tm.secondsMutex.Lock()
tm.seconds += int64(value)
tm.secondsMutex.Unlock()
}
// SetSeconds -
func (tm *TimerMock) SetSeconds(value int) {
tm.secondsMutex.Lock()
tm.seconds = int64(value)
tm.secondsMutex.Unlock()
}