github.com/xmidt-org/webpa-common@v1.11.9/clock/clocktest/mocks.go (about) 1 package clocktest 2 3 import ( 4 "time" 5 6 "github.com/stretchr/testify/mock" 7 "github.com/xmidt-org/webpa-common/clock" 8 ) 9 10 // Mock is a stretchr mock for a clock. In addition to implementing clock.Interface and supplying 11 // mock behavior, other methods that make mocking a bit easier are supplied. 12 type Mock struct { 13 mock.Mock 14 } 15 16 var _ clock.Interface = (*Mock)(nil) 17 18 func (m *Mock) Now() time.Time { 19 return m.Called().Get(0).(time.Time) 20 } 21 22 func (m *Mock) OnNow(v time.Time) *mock.Call { 23 return m.On("Now").Return(v) 24 } 25 26 func (m *Mock) Sleep(d time.Duration) { 27 m.Called(d) 28 } 29 30 func (m *Mock) OnSleep(d time.Duration) *mock.Call { 31 return m.On("Sleep", d) 32 } 33 34 func (m *Mock) NewTimer(d time.Duration) clock.Timer { 35 return m.Called(d).Get(0).(clock.Timer) 36 } 37 38 func (m *Mock) OnNewTimer(d time.Duration, t clock.Timer) *mock.Call { 39 return m.On("NewTimer", d).Return(t) 40 } 41 42 func (m *Mock) NewTicker(d time.Duration) clock.Ticker { 43 return m.Called(d).Get(0).(clock.Ticker) 44 } 45 46 func (m *Mock) OnNewTicker(d time.Duration, t clock.Ticker) *mock.Call { 47 return m.On("NewTicker", d).Return(t) 48 } 49 50 // MockTimer is a stretchr mock for the clock.Timer interface 51 type MockTimer struct { 52 mock.Mock 53 } 54 55 var _ clock.Timer = (*MockTimer)(nil) 56 57 func (m *MockTimer) C() <-chan time.Time { 58 return m.Called().Get(0).(<-chan time.Time) 59 } 60 61 func (m *MockTimer) OnC(c <-chan time.Time) *mock.Call { 62 return m.On("C").Return(c) 63 } 64 65 func (m *MockTimer) Reset(d time.Duration) bool { 66 return m.Called(d).Bool(0) 67 } 68 69 func (m *MockTimer) OnReset(d time.Duration, r bool) *mock.Call { 70 return m.On("Reset", d).Return(r) 71 } 72 73 func (m *MockTimer) Stop() bool { 74 return m.Called().Bool(0) 75 } 76 77 func (m *MockTimer) OnStop(r bool) *mock.Call { 78 return m.On("Stop").Return(r) 79 } 80 81 type MockTicker struct { 82 mock.Mock 83 } 84 85 var _ clock.Ticker = (*MockTicker)(nil) 86 87 func (m *MockTicker) C() <-chan time.Time { 88 return m.Called().Get(0).(<-chan time.Time) 89 } 90 91 func (m *MockTicker) OnC(c <-chan time.Time) *mock.Call { 92 return m.On("C").Return(c) 93 } 94 95 func (m *MockTicker) Stop() { 96 m.Called() 97 } 98 99 func (m *MockTicker) OnStop() *mock.Call { 100 return m.On("Stop") 101 }