Refactor integration tests infrastructure (#37462)

Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-04-29 18:37:38 +02:00
committed by GitHub
parent 9262803621
commit d57d06335d
26 changed files with 331 additions and 544 deletions

View File

@@ -17,11 +17,11 @@ func TestMain(m *testing.M) {
func Test_DropTableColumns(t *testing.T) {
x, deferable := PrepareTestEnv(t, 0)
if x == nil || t.Failed() {
defer deferable()
return
}
defer deferable()
// FIXME: this logic seems wrong. Need to add an assertion here in the future, but it seems causing failure.
if x == nil || t.Failed() {
t.Skip("PrepareTestEnv did not yield a usable engine")
}
type DropTest struct {
ID int64 `xorm:"pk autoincr"`

View File

@@ -15,7 +15,6 @@ import (
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/tempdir"
"code.gitea.io/gitea/modules/testlogger"
"code.gitea.io/gitea/modules/util"
@@ -120,6 +119,8 @@ func deleteDB() error {
if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE [%s]", setting.Database.Name)); err != nil {
return err
}
default:
return fmt.Errorf("unsupported database type: %s", setting.Database.Type)
}
return nil
@@ -203,14 +204,10 @@ func LoadTableSchemasMap(t *testing.T, x *xorm.Engine) map[string]*schemas.Table
func mainTest(m *testing.M) int {
testlogger.Init()
tempWorkPath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("migration-test-data-")
err := setting.PrepareIntegrationTestConfig()
if err != nil {
return testlogger.MainErrorf("Unable to create temporary dir for migration test: %v", err)
return testlogger.MainErrorf("Unable to prepare integration test config: %v", err)
}
defer cleanup()
setting.MockBuiltinPaths(tempWorkPath, "", "")
setting.SetupGiteaTestEnv()
if err = git.InitFull(); err != nil {