Re:Mocking time and testing event loops in Go
by physicles on Monday May 25, 2020 @09:46AM
(#23301037)
I've done this too, because passing a mockable time everywhere would just clutter the code, and this is an instance where a package-level global isn't going to bite you in the ass -- in prod anyway (in tests you might get your wires crossed, but seen another way, a global ensures all parts of your program think it's the same time).
Difference in mine is that dates.SetNowSource returns a reset function that you can defer, like with context.WithCancel().
Difference in mine is that dates.SetNowSource returns a reset function that you can defer, like with context.WithCancel().