Allow mocking timeutil (#17354)

Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
John Olheiser authored and GitHub committed 2021-10-18 21:12:26 +01:00
1 parent f0376b7e02
commit c59afa752d
2 files changed
+22

No files matched your search

+16
View File
@@ -13,8 +13,24 @@ import (
// TimeStamp defines a timestamp
type TimeStamp int64
// mock is NOT concurrency-safe!!
var mock time.Time
// Set sets the time to a mocked time.Time
func Set(now time.Time) {
mock = now
}
// Unset will unset the mocked time.Time
func Unset() {
mock = time.Time{}
}
// TimeStampNow returns now int64
func TimeStampNow() TimeStamp {
if !mock.IsZero() {
return TimeStamp(mock.Unix())
}
return TimeStamp(time.Now().Unix())
}