package fs import ( "time" ) var now time.Time func init() { now = time.Now() } type ticker interface { getC() <-chan time.Time } type clock interface { Now() time.Time Ticker() ticker } type realTicker time.Ticker func (rt realTicker) getC() <-chan time.Time { return rt.C } type realClock struct{} func (rc realClock) Now() time.Time { return time.Now() } func (rc realClock) Ticker() ticker { ticker := time.NewTicker(time.Second) return realTicker(*ticker) } type mockClock struct{} func (mc mockClock) Now() time.Time { return now } func (mc mockClock) Ticker() ticker { return newMockTicker() } type mockTicker struct { c <-chan time.Time } func (mc mockTicker) getC() <-chan time.Time { return mc.c } func newMockTicker() mockTicker { c := make(<-chan time.Time) return mockTicker{ c: c, } }