Overview
Fake Time for test. not best way.
Detail
var now = Time.Now
// if you want to use specify time, you call it. then replace time to argument valuen.
// then, you receive function is for revert original time module. for finish test, recommend call by defer
func switchFakeTime(t time.Time) (revertFakeTime func()) {
now = func() time.Time {
return t
}
return func() {
now = time.Now
}
}
fmt.Println(now())
revertFunc := switchFakeTime.(Time.Now())
fmt.Println(now())
time.Sleep(10 * time.Second)
fmt.Println(now())
revertFunc()
fmt.Println(now())