aboutsummaryrefslogtreecommitdiff
path: root/internal/db/access_tokens_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/access_tokens_test.go')
-rw-r--r--internal/db/access_tokens_test.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/internal/db/access_tokens_test.go b/internal/db/access_tokens_test.go
index 8a2f3805..ef629320 100644
--- a/internal/db/access_tokens_test.go
+++ b/internal/db/access_tokens_test.go
@@ -8,24 +8,33 @@ import (
"testing"
"time"
- "github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert"
+ "gorm.io/gorm"
"gogs.io/gogs/internal/errutil"
)
func TestAccessToken_BeforeCreate(t *testing.T) {
+ now := time.Now()
+ db := &gorm.DB{
+ Config: &gorm.Config{
+ NowFunc: func() time.Time {
+ return now
+ },
+ },
+ }
+
t.Run("CreatedUnix has been set", func(t *testing.T) {
token := &AccessToken{CreatedUnix: 1}
- token.BeforeCreate()
+ _ = token.BeforeCreate(db)
assert.Equal(t, int64(1), token.CreatedUnix)
assert.Equal(t, int64(0), token.UpdatedUnix)
})
t.Run("CreatedUnix has not been set", func(t *testing.T) {
token := &AccessToken{}
- token.BeforeCreate()
- assert.Equal(t, gorm.NowFunc().Unix(), token.CreatedUnix)
+ _ = token.BeforeCreate(db)
+ assert.Equal(t, db.NowFunc().Unix(), token.CreatedUnix)
assert.Equal(t, int64(0), token.UpdatedUnix)
})
}
@@ -80,7 +89,7 @@ func test_accessTokens_Create(t *testing.T, db *accessTokens) {
if err != nil {
t.Fatal(err)
}
- assert.Equal(t, gorm.NowFunc().Format(time.RFC3339), token.Created.UTC().Format(time.RFC3339))
+ assert.Equal(t, db.NowFunc().Format(time.RFC3339), token.Created.UTC().Format(time.RFC3339))
// Try create second access token with same name should fail
_, err = db.Create(token.UserID, token.Name)
@@ -193,5 +202,5 @@ func test_accessTokens_Save(t *testing.T, db *accessTokens) {
if err != nil {
t.Fatal(err)
}
- assert.Equal(t, gorm.NowFunc().Format(time.RFC3339), token.Updated.UTC().Format(time.RFC3339))
+ assert.Equal(t, db.NowFunc().Format(time.RFC3339), token.Updated.UTC().Format(time.RFC3339))
}