blob: 8809109de37144df767fe7abc8eebf718282348d (
plain)
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
|
// Package clock abstracts time for testability.
package clock
import "time"
// Clock provides the current time.
type Clock interface {
Now() time.Time
}
// RealClock uses the system clock.
type RealClock struct{}
// Now returns the current time.
func (RealClock) Now() time.Time { return time.Now() }
// MockClock is a fake clock for testing.
type MockClock struct {
T time.Time
}
// Now returns the mock time.
func (m *MockClock) Now() time.Time { return m.T }
var (
_ Clock = (*RealClock)(nil)
_ Clock = (*MockClock)(nil)
)
|