mirror of
https://github.com/go-gitea/gitea
synced 2025-07-07 11:07:20 +00:00
Decouple unit test code from business code (#17623)
This commit is contained in:
@ -25,7 +25,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"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/graceful"
|
||||
@ -84,6 +84,7 @@ func NewNilResponseHashSumRecorder() *NilResponseHashSumRecorder {
|
||||
func TestMain(m *testing.M) {
|
||||
defer log.Close()
|
||||
|
||||
unittest.InitUnitTestBridge()
|
||||
managerCtx, cancel := context.WithCancel(context.Background())
|
||||
graceful.InitManager(managerCtx)
|
||||
defer cancel()
|
||||
@ -112,8 +113,8 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
}
|
||||
|
||||
err := db.InitFixtures(
|
||||
db.FixturesOptions{
|
||||
err := unittest.InitFixtures(
|
||||
unittest.FixturesOptions{
|
||||
Dir: filepath.Join(filepath.Dir(setting.AppPath), "models/fixtures/"),
|
||||
},
|
||||
)
|
||||
@ -250,7 +251,7 @@ func prepareTestEnv(t testing.TB, skip ...int) func() {
|
||||
ourSkip += skip[0]
|
||||
}
|
||||
deferFn := PrintCurrentTest(t, ourSkip)
|
||||
assert.NoError(t, db.LoadFixtures())
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
|
||||
|
||||
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
|
||||
@ -527,7 +528,7 @@ func GetCSRF(t testing.TB, session *TestSession, urlStr string) string {
|
||||
// within a single test this is required
|
||||
func resetFixtures(t *testing.T) {
|
||||
assert.NoError(t, queue.GetManager().FlushAll(context.Background(), -1))
|
||||
assert.NoError(t, db.LoadFixtures())
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
|
||||
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
|
||||
}
|
||||
|
Reference in New Issue
Block a user