Documentation
¶
Overview ¶
Package clockmock provides moq-generated mock implementations of the clock package's interfaces. For most tests no double is needed at all — a testing/synctest bubble runs the production clock on fake time; reach for these mocks when a test needs to assert on the exact calls a unit makes.
Index ¶
- type ClockMock
- func (mock *ClockMock) NewTicker(d time.Duration) clock.Ticker
- func (mock *ClockMock) NewTickerCalls() []struct{ ... }
- func (mock *ClockMock) Now() time.Time
- func (mock *ClockMock) NowCalls() []struct{}
- func (mock *ClockMock) Since(t time.Time) time.Duration
- func (mock *ClockMock) SinceCalls() []struct{ ... }
- func (mock *ClockMock) Sleep(ctx context.Context, d time.Duration) error
- func (mock *ClockMock) SleepCalls() []struct{ ... }
- type TickerMock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClockMock ¶
type ClockMock struct {
// NewTickerFunc mocks the NewTicker method.
NewTickerFunc func(d time.Duration) clock.Ticker
// NowFunc mocks the Now method.
NowFunc func() time.Time
// SinceFunc mocks the Since method.
SinceFunc func(t time.Time) time.Duration
// SleepFunc mocks the Sleep method.
SleepFunc func(ctx context.Context, d time.Duration) error
// contains filtered or unexported fields
}
ClockMock is a mock implementation of clock.Clock.
func TestSomethingThatUsesClock(t *testing.T) {
// make and configure a mocked clock.Clock
mockedClock := &ClockMock{
NewTickerFunc: func(d time.Duration) clock.Ticker {
panic("mock out the NewTicker method")
},
NowFunc: func() time.Time {
panic("mock out the Now method")
},
SinceFunc: func(t time.Time) time.Duration {
panic("mock out the Since method")
},
SleepFunc: func(ctx context.Context, d time.Duration) error {
panic("mock out the Sleep method")
},
}
// use mockedClock in code that requires clock.Clock
// and then make assertions.
}
func (*ClockMock) NewTickerCalls ¶
NewTickerCalls gets all the calls that were made to NewTicker. Check the length with:
len(mockedClock.NewTickerCalls())
func (*ClockMock) NowCalls ¶
func (mock *ClockMock) NowCalls() []struct { }
NowCalls gets all the calls that were made to Now. Check the length with:
len(mockedClock.NowCalls())
func (*ClockMock) SinceCalls ¶
SinceCalls gets all the calls that were made to Since. Check the length with:
len(mockedClock.SinceCalls())
type TickerMock ¶
type TickerMock struct {
// ChanFunc mocks the Chan method.
ChanFunc func() <-chan time.Time
// StopFunc mocks the Stop method.
StopFunc func()
// contains filtered or unexported fields
}
TickerMock is a mock implementation of clock.Ticker.
func TestSomethingThatUsesTicker(t *testing.T) {
// make and configure a mocked clock.Ticker
mockedTicker := &TickerMock{
ChanFunc: func() <-chan time.Time {
panic("mock out the Chan method")
},
StopFunc: func() {
panic("mock out the Stop method")
},
}
// use mockedTicker in code that requires clock.Ticker
// and then make assertions.
}
func (*TickerMock) ChanCalls ¶
func (mock *TickerMock) ChanCalls() []struct { }
ChanCalls gets all the calls that were made to Chan. Check the length with:
len(mockedTicker.ChanCalls())
func (*TickerMock) StopCalls ¶
func (mock *TickerMock) StopCalls() []struct { }
StopCalls gets all the calls that were made to Stop. Check the length with:
len(mockedTicker.StopCalls())