mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-28 20:56:11 +01:00
[CHORE] Move test related function to own package
- Go's deadcode eliminator is quite simple, if you put a public function in a package `aa/bb` that is used only by tests, it would still be built if package `aa/bb` was imported. This means that if such functions use libraries relevant only to tests that those libraries would still be be built and increase the binary size of a Go binary. - This is also the case with Forgejo, `models/migrations/base/tests.go` contained functions exclusively used by tests which (skipping some steps here) imports https://github.com/ClickHouse/clickhouse-go, which is 2MiB. The `code.gitea.io/gitea/models/migrations/base` package is imported by `cmd/doctor` and thus the code of the clickhouse library is also built and included in the Forgejo binary, although entirely unused and not reachable. - This patch moves the test-related functions to their own package, so Go's deadcode eliminator knows not to build the test-related functions and thus reduces the size of the Forgejo binary. - It is not possible to move this to a `_test.go` file because Go does not allow importing functions from such files, so any test helper function must be in a non-test package and file. - Reduction of size (built with `TAGS="sqlite sqlite_unlock_notify" make build`): - Before: 95912040 bytes (92M) - After: 92306888 bytes (89M)
This commit is contained in:
parent
6e83c39f13
commit
138942c09e
|
@ -60,13 +60,6 @@ code.gitea.io/gitea/models/issues
|
|||
IsErrIssueWasClosed
|
||||
ChangeMilestoneStatus
|
||||
|
||||
code.gitea.io/gitea/models/migrations/base
|
||||
removeAllWithRetry
|
||||
newXORMEngine
|
||||
deleteDB
|
||||
PrepareTestEnv
|
||||
MainTest
|
||||
|
||||
code.gitea.io/gitea/models/organization
|
||||
GetTeamNamesByID
|
||||
UpdateTeamUnits
|
||||
|
@ -93,36 +86,6 @@ code.gitea.io/gitea/models/repo
|
|||
GetTopicByName
|
||||
WatchRepoMode
|
||||
|
||||
code.gitea.io/gitea/models/unittest
|
||||
CheckConsistencyFor
|
||||
checkForConsistency
|
||||
GetXORMEngine
|
||||
OverrideFixtures
|
||||
InitFixtures
|
||||
LoadFixtures
|
||||
Copy
|
||||
CopyDir
|
||||
NewMockWebServer
|
||||
NormalizedFullPath
|
||||
FixturesDir
|
||||
fatalTestError
|
||||
InitSettings
|
||||
MainTest
|
||||
CreateTestEngine
|
||||
PrepareTestDatabase
|
||||
PrepareTestEnv
|
||||
Cond
|
||||
OrderBy
|
||||
LoadBeanIfExists
|
||||
BeanExists
|
||||
AssertExistsAndLoadBean
|
||||
GetCount
|
||||
AssertNotExistsBean
|
||||
AssertExistsIf
|
||||
AssertSuccessfulInsert
|
||||
AssertCount
|
||||
AssertInt64InRange
|
||||
|
||||
code.gitea.io/gitea/models/user
|
||||
IsErrPrimaryEmailCannotDelete
|
||||
ErrUserInactive.Error
|
||||
|
@ -273,22 +236,6 @@ code.gitea.io/gitea/modules/sync
|
|||
StatusTable.Start
|
||||
StatusTable.IsRunning
|
||||
|
||||
code.gitea.io/gitea/modules/testlogger
|
||||
testLoggerWriterCloser.pushT
|
||||
testLoggerWriterCloser.Log
|
||||
testLoggerWriterCloser.recordError
|
||||
testLoggerWriterCloser.printMsg
|
||||
testLoggerWriterCloser.popT
|
||||
testLoggerWriterCloser.Reset
|
||||
PrintCurrentTest
|
||||
Printf
|
||||
NewTestLoggerWriter
|
||||
TestLogEventWriter.Base
|
||||
TestLogEventWriter.GetLevel
|
||||
TestLogEventWriter.GetWriterName
|
||||
TestLogEventWriter.GetWriterType
|
||||
TestLogEventWriter.Run
|
||||
|
||||
code.gitea.io/gitea/modules/timeutil
|
||||
GetExecutableModTime
|
||||
MockSet
|
||||
|
|
50
assets/go-licenses.json
generated
50
assets/go-licenses.json
generated
File diff suppressed because one or more lines are too long
|
@ -6,9 +6,9 @@ package forgejo_migrations //nolint:revive
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -6,14 +6,14 @@ package forgejo_migrations //nolint:revive
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// TestEnsureUpToDate tests the behavior of EnsureUpToDate.
|
||||
func TestEnsureUpToDate(t *testing.T) {
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(ForgejoVersion))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(ForgejoVersion))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
|
|
|
@ -6,9 +6,9 @@ package v1_22 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_22 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ func Test_RemoveSSHSignaturesFromReleaseNotes(t *testing.T) {
|
|||
Note string `xorm:"TEXT"`
|
||||
}
|
||||
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(Release))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(Release))
|
||||
defer deferable()
|
||||
|
||||
assert.NoError(t, RemoveSSHSignaturesFromReleaseNotes(x))
|
||||
|
|
|
@ -4,22 +4,14 @@
|
|||
package base
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
@ -442,99 +434,3 @@ func ModifyColumn(x *xorm.Engine, tableName string, col *schemas.Column) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeAllWithRetry(dir string) error {
|
||||
var err error
|
||||
for i := 0; i < 20; i++ {
|
||||
err = os.RemoveAll(dir)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func newXORMEngine() (*xorm.Engine, error) {
|
||||
if err := db.InitEngine(context.Background()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := unittest.GetXORMEngine()
|
||||
return x, nil
|
||||
}
|
||||
|
||||
func deleteDB() error {
|
||||
switch {
|
||||
case setting.Database.Type.IsSQLite3():
|
||||
if err := util.Remove(setting.Database.Path); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.MkdirAll(path.Dir(setting.Database.Path), os.ModePerm)
|
||||
|
||||
case setting.Database.Type.IsMySQL():
|
||||
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/",
|
||||
setting.Database.User, setting.Database.Passwd, setting.Database.Host))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
if _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", setting.Database.Name)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", setting.Database.Name)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
case setting.Database.Type.IsPostgreSQL():
|
||||
db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s",
|
||||
setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.SSLMode))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
if _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", setting.Database.Name)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s", setting.Database.Name)); err != nil {
|
||||
return err
|
||||
}
|
||||
db.Close()
|
||||
|
||||
// Check if we need to setup a specific schema
|
||||
if len(setting.Database.Schema) != 0 {
|
||||
db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s",
|
||||
setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
schrows, err := db.Query(fmt.Sprintf("SELECT 1 FROM information_schema.schemata WHERE schema_name = '%s'", setting.Database.Schema))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer schrows.Close()
|
||||
|
||||
if !schrows.Next() {
|
||||
// Create and setup a DB schema
|
||||
_, err = db.Exec(fmt.Sprintf("CREATE SCHEMA %s", setting.Database.Schema))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Make the user's default search path the created schema; this will affect new connections
|
||||
_, err = db.Exec(fmt.Sprintf(`ALTER USER "%s" SET search_path = %s`, setting.Database.User, setting.Database.Schema))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -6,13 +6,14 @@ package base
|
|||
import (
|
||||
"testing"
|
||||
|
||||
migrations_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm/names"
|
||||
)
|
||||
|
||||
func Test_DropTableColumns(t *testing.T) {
|
||||
x, deferable := PrepareTestEnv(t, 0)
|
||||
x, deferable := migrations_tests.PrepareTestEnv(t, 0)
|
||||
if x == nil || t.Failed() {
|
||||
defer deferable()
|
||||
return
|
||||
|
|
|
@ -5,8 +5,10 @@ package base
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
migrations_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
MainTest(m)
|
||||
migrations_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -2,30 +2,32 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//nolint:forbidigo
|
||||
package base
|
||||
package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/testlogger"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
// FIXME: this file shouldn't be in a normal package, it should only be compiled for tests
|
||||
|
||||
// PrepareTestEnv prepares the test environment and reset the database. The skip parameter should usually be 0.
|
||||
// Provide models to be sync'd with the database - in particular any models you expect fixtures to be loaded from.
|
||||
//
|
||||
|
@ -171,3 +173,99 @@ func MainTest(m *testing.M) {
|
|||
}
|
||||
os.Exit(exitStatus)
|
||||
}
|
||||
|
||||
func newXORMEngine() (*xorm.Engine, error) {
|
||||
if err := db.InitEngine(context.Background()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := unittest.GetXORMEngine()
|
||||
return x, nil
|
||||
}
|
||||
|
||||
func deleteDB() error {
|
||||
switch {
|
||||
case setting.Database.Type.IsSQLite3():
|
||||
if err := util.Remove(setting.Database.Path); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.MkdirAll(path.Dir(setting.Database.Path), os.ModePerm)
|
||||
|
||||
case setting.Database.Type.IsMySQL():
|
||||
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/",
|
||||
setting.Database.User, setting.Database.Passwd, setting.Database.Host))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
if _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", setting.Database.Name)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", setting.Database.Name)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
case setting.Database.Type.IsPostgreSQL():
|
||||
db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s",
|
||||
setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.SSLMode))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
if _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", setting.Database.Name)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s", setting.Database.Name)); err != nil {
|
||||
return err
|
||||
}
|
||||
db.Close()
|
||||
|
||||
// Check if we need to setup a specific schema
|
||||
if len(setting.Database.Schema) != 0 {
|
||||
db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s",
|
||||
setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
schrows, err := db.Query(fmt.Sprintf("SELECT 1 FROM information_schema.schemata WHERE schema_name = '%s'", setting.Database.Schema))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer schrows.Close()
|
||||
|
||||
if !schrows.Next() {
|
||||
// Create and setup a DB schema
|
||||
_, err = db.Exec(fmt.Sprintf("CREATE SCHEMA %s", setting.Database.Schema))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Make the user's default search path the created schema; this will affect new connections
|
||||
_, err = db.Exec(fmt.Sprintf(`ALTER USER "%s" SET search_path = %s`, setting.Database.User, setting.Database.Schema))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeAllWithRetry(dir string) error {
|
||||
var err error
|
||||
for i := 0; i < 20; i++ {
|
||||
err = os.RemoveAll(dir)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
return err
|
||||
}
|
|
@ -6,9 +6,9 @@ package v1_14 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_14 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -47,7 +47,7 @@ func Test_RemoveInvalidLabels(t *testing.T) {
|
|||
}
|
||||
|
||||
// load and prepare the test database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(Comment), new(Issue), new(Repository), new(IssueLabel), new(Label))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(Comment), new(Issue), new(Repository), new(IssueLabel), new(Label))
|
||||
if x == nil || t.Failed() {
|
||||
defer deferable()
|
||||
return
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_14 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -34,7 +34,7 @@ func Test_DeleteOrphanedIssueLabels(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(IssueLabel), new(Label))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(IssueLabel), new(Label))
|
||||
if x == nil || t.Failed() {
|
||||
defer deferable()
|
||||
return
|
||||
|
|
|
@ -6,9 +6,9 @@ package v1_15 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -20,7 +20,7 @@ func Test_AddPrimaryEmail2EmailAddress(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(User))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(User))
|
||||
if x == nil || t.Failed() {
|
||||
defer deferable()
|
||||
return
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_15 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -20,7 +20,7 @@ func Test_AddIssueResourceIndexTable(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(Issue))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(Issue))
|
||||
if x == nil || t.Failed() {
|
||||
defer deferable()
|
||||
return
|
||||
|
|
|
@ -6,9 +6,9 @@ package v1_16 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_16 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -27,7 +27,7 @@ func (ls *LoginSourceOriginalV189) TableName() string {
|
|||
|
||||
func Test_UnwrapLDAPSourceCfg(t *testing.T) {
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(LoginSourceOriginalV189))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(LoginSourceOriginalV189))
|
||||
if x == nil || t.Failed() {
|
||||
defer deferable()
|
||||
return
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_16 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -31,7 +31,7 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferrable := base.PrepareTestEnv(t, 0, new(Attachment), new(Issue), new(Release))
|
||||
x, deferrable := migration_tests.PrepareTestEnv(t, 0, new(Attachment), new(Issue), new(Release))
|
||||
defer deferrable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_16 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -21,7 +21,7 @@ func Test_AddTableCommitStatusIndex(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(CommitStatus))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(CommitStatus))
|
||||
if x == nil || t.Failed() {
|
||||
defer deferable()
|
||||
return
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -58,7 +58,7 @@ func Test_RemigrateU2FCredentials(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(WebauthnCredential), new(U2fRegistration), new(ExpectedWebauthnCredential))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(WebauthnCredential), new(U2fRegistration), new(ExpectedWebauthnCredential))
|
||||
if x == nil || t.Failed() {
|
||||
defer deferable()
|
||||
return
|
||||
|
|
|
@ -6,9 +6,9 @@ package v1_17 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"encoding/base32"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -38,7 +38,7 @@ func Test_StoreWebauthnCredentialIDAsBytes(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(WebauthnCredential), new(ExpectedWebauthnCredential))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(WebauthnCredential), new(ExpectedWebauthnCredential))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
|
|
|
@ -6,9 +6,9 @@ package v1_18 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -16,7 +16,7 @@ func Test_UpdateOpenMilestoneCounts(t *testing.T) {
|
|||
type ExpectedMilestone issues.Milestone
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(issues.Milestone), new(ExpectedMilestone), new(issues.Issue))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(issues.Milestone), new(ExpectedMilestone), new(issues.Issue))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_18 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ func Test_AddConfidentialClientColumnToOAuth2ApplicationTable(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(oauth2Application))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(oauth2Application))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
|
|
|
@ -6,9 +6,9 @@ package v1_19 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_19 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/secret"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -39,7 +39,7 @@ func Test_AddHeaderAuthorizationEncryptedColWebhook(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(Webhook), new(ExpectedWebhook), new(HookTask))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(Webhook), new(ExpectedWebhook), new(HookTask))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
|
|
|
@ -6,9 +6,9 @@ package v1_20 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -66,7 +66,7 @@ func Test_ConvertScopedAccessTokens(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(AccessToken))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(AccessToken))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
t.Skip()
|
||||
|
|
|
@ -6,9 +6,9 @@ package v1_21 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ package v1_22 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_22 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -21,7 +21,7 @@ func Test_AddCombinedIndexToIssueUser(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(IssueUser))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(IssueUser))
|
||||
defer deferable()
|
||||
|
||||
assert.NoError(t, AddCombinedIndexToIssueUser(x))
|
||||
|
|
|
@ -6,7 +6,7 @@ package v1_22 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/xorm"
|
||||
|
@ -64,7 +64,7 @@ func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
return base.PrepareTestEnv(t, 0,
|
||||
return migration_tests.PrepareTestEnv(t, 0,
|
||||
new(Repository),
|
||||
new(CommitStatus),
|
||||
new(RepoArchiver),
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strconv"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
|
||||
|
@ -34,7 +34,7 @@ func Test_AddPayloadVersionToHookTaskTable(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(HookTask), new(HookTaskMigrated))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(HookTask), new(HookTaskMigrated))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
"code.gitea.io/gitea/models/project"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
func Test_CheckProjectColumnsConsistency(t *testing.T) {
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(project.Project), new(project.Column))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(project.Project), new(project.Column))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"slices"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
@ -21,7 +21,7 @@ func Test_AddUniqueIndexForProjectIssue(t *testing.T) {
|
|||
}
|
||||
|
||||
// Prepare and load the testing database
|
||||
x, deferable := base.PrepareTestEnv(t, 0, new(ProjectIssue))
|
||||
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(ProjectIssue))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
|
|
|
@ -6,9 +6,9 @@ package v1_23 //nolint
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
base.MainTest(m)
|
||||
migration_tests.MainTest(m)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue