Chore: Use TimeNow instead of time.Now in user sql store to make it testable (#54983)
This commit is contained in:
@@ -86,8 +86,9 @@ func TestSQLStore_GetOrgUsers(t *testing.T) {
|
||||
|
||||
func TestSQLStore_GetOrgUsers_PopulatesCorrectly(t *testing.T) {
|
||||
// The millisecond part is not stored in the DB
|
||||
constNow := time.Now().UTC().Truncate(time.Second)
|
||||
defer mockTimeNow(constNow)()
|
||||
constNow := time.Date(2022, 8, 17, 20, 34, 58, 0, time.UTC)
|
||||
MockTimeNow(constNow)
|
||||
defer ResetTimeNow()
|
||||
|
||||
store := InitTestDB(t, InitTestDBOpt{})
|
||||
_, err := store.CreateUser(context.Background(), user.CreateUserCommand{
|
||||
@@ -334,14 +335,3 @@ func hasWildcardScope(user *user.SignedInUser, action string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func mockTimeNow(constTime time.Time) func() {
|
||||
timeNow = func() time.Time {
|
||||
return constTime.Truncate(time.Second)
|
||||
}
|
||||
return resetTimeNow
|
||||
}
|
||||
|
||||
func resetTimeNow() {
|
||||
timeNow = time.Now
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user