Skip to content

Commit ec8e6f6

Browse files
committed
fix test
1 parent ca66b91 commit ec8e6f6

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

models/auth/source_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/stretchr/testify/assert"
1616
"github.com/stretchr/testify/require"
17-
"xorm.io/xorm"
1817
"xorm.io/xorm/schemas"
1918
)
2019

@@ -59,7 +58,7 @@ func TestDumpAuthSource(t *testing.T) {
5958
sb := new(strings.Builder)
6059

6160
// TODO: this test is quite hacky, it should use a low-level "select" (without model processors) but not a database dump
62-
engine := db.GetEngine(t.Context()).(*xorm.Engine)
61+
engine := unittest.GetXORMEngine()
6362
require.NoError(t, engine.DumpTables([]*schemas.Table{authSourceSchema}, sb))
6463
assert.Contains(t, sb.String(), `"Provider":"ConvertibleSourceName"`)
6564
}

models/db/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ func contextSafetyCheck(e Engine) {
9090
}
9191

9292
// GetEngine gets an existing db Engine/Statement or creates a new Session
93-
func GetEngine(ctx context.Context) Engine {
93+
func GetEngine(ctx context.Context) (e Engine) {
94+
defer func() { contextSafetyCheck(e) }()
9495
if e := getExistingEngine(ctx); e != nil {
9596
return e
9697
}
@@ -99,7 +100,6 @@ func GetEngine(ctx context.Context) Engine {
99100

100101
// getExistingEngine gets an existing db Engine/Statement from this context or returns nil
101102
func getExistingEngine(ctx context.Context) (e Engine) {
102-
defer func() { contextSafetyCheck(e) }()
103103
if engined, ok := ctx.(*Context); ok {
104104
return engined.engine
105105
}

tests/integration/db_collation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
"testing"
88

99
"code.gitea.io/gitea/models/db"
10+
"code.gitea.io/gitea/models/unittest"
1011
"code.gitea.io/gitea/modules/setting"
1112
"code.gitea.io/gitea/modules/test"
1213

1314
"github.com/stretchr/testify/assert"
14-
"xorm.io/xorm"
1515
)
1616

1717
type TestCollationTbl struct {
@@ -20,7 +20,7 @@ type TestCollationTbl struct {
2020
}
2121

2222
func TestDatabaseCollation(t *testing.T) {
23-
x := db.GetEngine(t.Context()).(*xorm.Engine)
23+
x := unittest.GetXORMEngine()
2424

2525
// all created tables should use case-sensitive collation by default
2626
_, _ = x.Exec("DROP TABLE IF EXISTS test_collation_tbl")

0 commit comments

Comments
 (0)