From 02b74317f2d8120a705599d6ae908634a1fa2b44 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 1 Jan 2024 16:15:15 +0100 Subject: [PATCH] [GITEA] Fix session generation for database (squash) timeutil.Mock because of e743570f65 * Refactor timeutil package (#28623) (cherry picked from commit acc6b51be2b6d676129f653a8949b2c06aa2ad94) --- models/auth/session_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/models/auth/session_test.go b/models/auth/session_test.go index 1731f40ccd..3475fdd2cd 100644 --- a/models/auth/session_test.go +++ b/models/auth/session_test.go @@ -17,7 +17,7 @@ import ( func TestAuthSession(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - defer timeutil.Unset() + defer timeutil.MockUnset() key := "I-Like-Free-Software" @@ -31,7 +31,7 @@ func TestAuthSession(t *testing.T) { assert.NoError(t, err) now := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC) - timeutil.Set(now) + timeutil.MockSet(now) // New session is created. sess, err := auth.ReadSession(db.DefaultContext, key) @@ -54,13 +54,13 @@ func TestAuthSession(t *testing.T) { t.Run("Update session", func(t *testing.T) { data := []byte{0xba, 0xdd, 0xc0, 0xde} now := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) - timeutil.Set(now) + timeutil.MockSet(now) // Update session. err := auth.UpdateSession(db.DefaultContext, key, data) assert.NoError(t, err) - timeutil.Set(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)) + timeutil.MockSet(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)) // Read updated session. // Ensure data is updated and expiry is set from the update session call. @@ -70,7 +70,7 @@ func TestAuthSession(t *testing.T) { assert.EqualValues(t, data, sess.Data) assert.EqualValues(t, now.Unix(), sess.Expiry) - timeutil.Set(now) + timeutil.MockSet(now) }) t.Run("Delete session", func(t *testing.T) { @@ -97,13 +97,13 @@ func TestAuthSession(t *testing.T) { }) t.Run("Cleanup sessions", func(t *testing.T) { - timeutil.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)) + timeutil.MockSet(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)) _, err := auth.ReadSession(db.DefaultContext, "sess-1") assert.NoError(t, err) // One minute later. - timeutil.Set(time.Date(2023, 1, 1, 0, 1, 0, 0, time.UTC)) + timeutil.MockSet(time.Date(2023, 1, 1, 0, 1, 0, 0, time.UTC)) _, err = auth.ReadSession(db.DefaultContext, "sess-2") assert.NoError(t, err)