From 083c3ee659c6c5542687f3bafae68cbc24dbc90f Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sat, 25 Jun 2022 18:07:39 +0800 Subject: db: refactor "action" table to use GORM (#7054) Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> --- internal/db/two_factors_test.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'internal/db/two_factors_test.go') diff --git a/internal/db/two_factors_test.go b/internal/db/two_factors_test.go index 935844d4..386e96ca 100644 --- a/internal/db/two_factors_test.go +++ b/internal/db/two_factors_test.go @@ -11,16 +11,40 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gorm.io/gorm" "gogs.io/gogs/internal/dbtest" "gogs.io/gogs/internal/errutil" ) +func TestTwoFactor_BeforeCreate(t *testing.T) { + now := time.Now() + db := &gorm.DB{ + Config: &gorm.Config{ + SkipDefaultTransaction: true, + NowFunc: func() time.Time { + return now + }, + }, + } + + t.Run("CreatedUnix has been set", func(t *testing.T) { + tf := &TwoFactor{CreatedUnix: 1} + _ = tf.BeforeCreate(db) + assert.Equal(t, int64(1), tf.CreatedUnix) + }) + + t.Run("CreatedUnix has not been set", func(t *testing.T) { + tf := &TwoFactor{} + _ = tf.BeforeCreate(db) + assert.Equal(t, db.NowFunc().Unix(), tf.CreatedUnix) + }) +} + func TestTwoFactors(t *testing.T) { if testing.Short() { t.Skip() } - t.Parallel() tables := []interface{}{new(TwoFactor), new(TwoFactorRecoveryCode)} -- cgit v1.2.3