mirror of https://github.com/go-gitea/gitea.git
Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
c5770195d9
commit
eb748ff79e
|
@ -7,6 +7,9 @@ package models
|
|||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -37,6 +40,10 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
|
|||
// Prepare
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
// Mock time
|
||||
timeutil.Set(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC))
|
||||
defer timeutil.Unset()
|
||||
|
||||
for i, tc := range testCases {
|
||||
user := AssertExistsAndLoadBean(t, &User{ID: tc.userID}).(*User)
|
||||
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue