Chore: Use TimeNow instead of time.Now in user sql store to make it testable (#54983)

This commit is contained in:
Misi
2022-09-09 18:43:14 +02:00
committed by GitHub
parent d5e28426ee
commit c5be9605a2
3 changed files with 28 additions and 22 deletions
+3 -13
View File
@@ -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
}