mirror of
https://github.com/go-gitea/gitea.git
synced 2025-10-31 21:28:11 +09:00
Add test for ExtendCommentTreePathLength migration and fix bugs (#35791)
Co-authored-by: Mithilesh Gupta <guptamithilesh@protonmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FIXME: this file shouldn't be in a normal package, it should only be compiled for tests
|
// 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
|
|||||||
return x, deferFn
|
return x, deferFn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LoadTableSchemasMap(t *testing.T, x *xorm.Engine) map[string]*schemas.Table {
|
||||||
|
tables, err := x.DBMetas()
|
||||||
|
require.NoError(t, err)
|
||||||
|
tableMap := make(map[string]*schemas.Table)
|
||||||
|
for _, table := range tables {
|
||||||
|
tableMap[table.Name] = table
|
||||||
|
}
|
||||||
|
return tableMap
|
||||||
|
}
|
||||||
|
|
||||||
func MainTest(m *testing.M) {
|
func MainTest(m *testing.M) {
|
||||||
testlogger.Init()
|
testlogger.Init()
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import (
|
|||||||
"code.gitea.io/gitea/models/migrations/v1_23"
|
"code.gitea.io/gitea/models/migrations/v1_23"
|
||||||
"code.gitea.io/gitea/models/migrations/v1_24"
|
"code.gitea.io/gitea/models/migrations/v1_24"
|
||||||
"code.gitea.io/gitea/models/migrations/v1_25"
|
"code.gitea.io/gitea/models/migrations/v1_25"
|
||||||
|
"code.gitea.io/gitea/models/migrations/v1_26"
|
||||||
"code.gitea.io/gitea/models/migrations/v1_6"
|
"code.gitea.io/gitea/models/migrations/v1_6"
|
||||||
"code.gitea.io/gitea/models/migrations/v1_7"
|
"code.gitea.io/gitea/models/migrations/v1_7"
|
||||||
"code.gitea.io/gitea/models/migrations/v1_8"
|
"code.gitea.io/gitea/models/migrations/v1_8"
|
||||||
@@ -379,8 +380,8 @@ func prepareMigrationTasks() []*migration {
|
|||||||
newMigration(309, "Improve Notification table indices", v1_23.ImproveNotificationTableIndices),
|
newMigration(309, "Improve Notification table indices", v1_23.ImproveNotificationTableIndices),
|
||||||
newMigration(310, "Add Priority to ProtectedBranch", v1_23.AddPriorityToProtectedBranch),
|
newMigration(310, "Add Priority to ProtectedBranch", v1_23.AddPriorityToProtectedBranch),
|
||||||
newMigration(311, "Add TimeEstimate to Issue table", v1_23.AddTimeEstimateColumnToIssueTable),
|
newMigration(311, "Add TimeEstimate to Issue table", v1_23.AddTimeEstimateColumnToIssueTable),
|
||||||
|
|
||||||
// Gitea 1.23.0-rc0 ends at migration ID number 311 (database version 312)
|
// Gitea 1.23.0-rc0 ends at migration ID number 311 (database version 312)
|
||||||
|
|
||||||
newMigration(312, "Add DeleteBranchAfterMerge to AutoMerge", v1_24.AddDeleteBranchAfterMergeForAutoMerge),
|
newMigration(312, "Add DeleteBranchAfterMerge to AutoMerge", v1_24.AddDeleteBranchAfterMergeForAutoMerge),
|
||||||
newMigration(313, "Move PinOrder from issue table to a new table issue_pin", v1_24.MovePinOrderToTableIssuePin),
|
newMigration(313, "Move PinOrder from issue table to a new table issue_pin", v1_24.MovePinOrderToTableIssuePin),
|
||||||
newMigration(314, "Update OwnerID as zero for repository level action tables", v1_24.UpdateOwnerIDOfRepoLevelActionsTables),
|
newMigration(314, "Update OwnerID as zero for repository level action tables", v1_24.UpdateOwnerIDOfRepoLevelActionsTables),
|
||||||
@@ -390,11 +391,13 @@ func prepareMigrationTasks() []*migration {
|
|||||||
newMigration(318, "Add anonymous_access_mode for repo_unit", v1_24.AddRepoUnitAnonymousAccessMode),
|
newMigration(318, "Add anonymous_access_mode for repo_unit", v1_24.AddRepoUnitAnonymousAccessMode),
|
||||||
newMigration(319, "Add ExclusiveOrder to Label table", v1_24.AddExclusiveOrderColumnToLabelTable),
|
newMigration(319, "Add ExclusiveOrder to Label table", v1_24.AddExclusiveOrderColumnToLabelTable),
|
||||||
newMigration(320, "Migrate two_factor_policy to login_source table", v1_24.MigrateSkipTwoFactor),
|
newMigration(320, "Migrate two_factor_policy to login_source table", v1_24.MigrateSkipTwoFactor),
|
||||||
|
// Gitea 1.24.0 ends at migration ID number 320 (database version 321)
|
||||||
|
|
||||||
// Gitea 1.24.0 ends at database version 321
|
|
||||||
newMigration(321, "Use LONGTEXT for some columns and fix review_state.updated_files column", v1_25.UseLongTextInSomeColumnsAndFixBugs),
|
newMigration(321, "Use LONGTEXT for some columns and fix review_state.updated_files column", v1_25.UseLongTextInSomeColumnsAndFixBugs),
|
||||||
newMigration(322, "Extend comment tree_path length limit", v1_25.ExtendCommentTreePathLength),
|
newMigration(322, "Extend comment tree_path length limit", v1_25.ExtendCommentTreePathLength),
|
||||||
newMigration(323, "Add support for actions concurrency", v1_25.AddActionsConcurrency),
|
// Gitea 1.25.0 ends at migration ID number 322 (database version 323)
|
||||||
|
|
||||||
|
newMigration(323, "Add support for actions concurrency", v1_26.AddActionsConcurrency),
|
||||||
}
|
}
|
||||||
return preparedMigrations
|
return preparedMigrations
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
|
func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
|
||||||
@@ -38,33 +39,26 @@ func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
|
|||||||
type Notice struct {
|
type Notice struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
Type int
|
Type int
|
||||||
Description string `xorm:"LONGTEXT"`
|
Description string `xorm:"TEXT"`
|
||||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare and load the testing database
|
// Prepare and load the testing database
|
||||||
x, deferable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
|
x, deferrable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
|
||||||
defer deferable()
|
defer deferrable()
|
||||||
|
|
||||||
assert.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
|
require.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
|
||||||
|
|
||||||
tables, err := x.DBMetas()
|
tables := base.LoadTableSchemasMap(t, x)
|
||||||
assert.NoError(t, err)
|
table := tables["review_state"]
|
||||||
|
column := table.GetColumn("updated_files")
|
||||||
|
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
|
||||||
|
|
||||||
for _, table := range tables {
|
table = tables["package_property"]
|
||||||
switch table.Name {
|
column = table.GetColumn("value")
|
||||||
case "review_state":
|
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
|
||||||
column := table.GetColumn("updated_files")
|
|
||||||
assert.NotNil(t, column)
|
table = tables["notice"]
|
||||||
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
|
column = table.GetColumn("description")
|
||||||
case "package_property":
|
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
|
||||||
column := table.GetColumn("value")
|
|
||||||
assert.NotNil(t, column)
|
|
||||||
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
|
|
||||||
case "notice":
|
|
||||||
column := table.GetColumn("description")
|
|
||||||
assert.NotNil(t, column)
|
|
||||||
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
34
models/migrations/v1_25/v322_test.go
Normal file
34
models/migrations/v1_25/v322_test.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package v1_25
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/migrations/base"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_ExtendCommentTreePathLength(t *testing.T) {
|
||||||
|
if setting.Database.Type.IsSQLite3() {
|
||||||
|
t.Skip("For SQLITE, varchar or char will always be represented as TEXT")
|
||||||
|
}
|
||||||
|
|
||||||
|
type Comment struct {
|
||||||
|
ID int64 `xorm:"pk autoincr"`
|
||||||
|
TreePath string `xorm:"VARCHAR(255)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
x, deferrable := base.PrepareTestEnv(t, 0, new(Comment))
|
||||||
|
defer deferrable()
|
||||||
|
|
||||||
|
require.NoError(t, ExtendCommentTreePathLength(x))
|
||||||
|
table := base.LoadTableSchemasMap(t, x)["comment"]
|
||||||
|
column := table.GetColumn("tree_path")
|
||||||
|
assert.Contains(t, []string{"NVARCHAR", "VARCHAR"}, column.SQLType.Name)
|
||||||
|
assert.EqualValues(t, 4000, column.Length)
|
||||||
|
}
|
||||||
14
models/migrations/v1_26/main_test.go
Normal file
14
models/migrations/v1_26/main_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package v1_26
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/migrations/base"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
base.MainTest(m)
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright 2025 The Gitea Authors. All rights reserved.
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
package v1_25
|
package v1_26
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
Reference in New Issue
Block a user