From 1dd6ef9296f1eea351758381aa7acaaff6d24c13 Mon Sep 17 00:00:00 2001 From: Darren Jacques Date: Sat, 28 Jan 2023 13:41:18 -0800 Subject: [PATCH] Use current time for NewFakeClock's initial value This prevents callers from building tests that rely on implementation details. Typically by expecting a string containing a static, default value of NewFakeClock(). This philosophy of preventing users from relying on implementation internals is similar to Go's random map iteration behavior. For users who depend on the initial clock time, NewFakeClockAt provides the behavior they need, and makes their expectations clear in tests. --- clockwork.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clockwork.go b/clockwork.go index d80395c..3206b36 100644 --- a/clockwork.go +++ b/clockwork.go @@ -43,10 +43,11 @@ func NewRealClock() Clock { // NewFakeClock returns a FakeClock implementation which can be // manually advanced through time for testing. The initial time of the -// FakeClock will be an arbitrary non-zero time. +// FakeClock will be the current system time. +// +// Tests that require a deterministic time must use NewFakeClockAt. func NewFakeClock() FakeClock { - // Use the standard layout time to avoid fulfilling Time.IsZero(). - return NewFakeClockAt(time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)) + return NewFakeClockAt(time.Now()) } // NewFakeClockAt returns a FakeClock initialised at the given time.Time.