aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2021-11-12 22:36:47 +0800
committerGitHub <noreply@github.com>2021-11-12 22:36:47 +0800
commitdf64fa486555de6f403a795fd16c2e9e1d59e535 (patch)
treeb899e9b9e5d57409b1bf0e3afbd606b6a3900235 /integrations
parent7f802631c54d2e91301158380b273b872d62bd80 (diff)
downloadgitea-df64fa486555de6f403a795fd16c2e9e1d59e535.tar.gz
gitea-df64fa486555de6f403a795fd16c2e9e1d59e535.zip
Decouple unit test code from business code (#17623)
Diffstat (limited to 'integrations')
-rw-r--r--integrations/api_issue_label_test.go10
-rw-r--r--integrations/integration_test.go11
-rw-r--r--integrations/migrate_test.go4
-rw-r--r--integrations/repofiles_delete_test.go9
4 files changed, 20 insertions, 14 deletions
diff --git a/integrations/api_issue_label_test.go b/integrations/api_issue_label_test.go
index 4508069e17..f9c297a18e 100644
--- a/integrations/api_issue_label_test.go
+++ b/integrations/api_issue_label_test.go
@@ -10,6 +10,8 @@ import (
"strings"
"testing"
+ "code.gitea.io/gitea/models/unittest"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
@@ -18,7 +20,7 @@ import (
)
func TestAPIModifyLabels(t *testing.T) {
- assert.NoError(t, db.LoadFixtures())
+ assert.NoError(t, unittest.LoadFixtures())
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -88,7 +90,7 @@ func TestAPIModifyLabels(t *testing.T) {
}
func TestAPIAddIssueLabels(t *testing.T) {
- assert.NoError(t, db.LoadFixtures())
+ assert.NoError(t, unittest.LoadFixtures())
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
issue := db.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
@@ -111,7 +113,7 @@ func TestAPIAddIssueLabels(t *testing.T) {
}
func TestAPIReplaceIssueLabels(t *testing.T) {
- assert.NoError(t, db.LoadFixtures())
+ assert.NoError(t, unittest.LoadFixtures())
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
issue := db.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
@@ -137,7 +139,7 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
}
func TestAPIModifyOrgLabels(t *testing.T) {
- assert.NoError(t, db.LoadFixtures())
+ assert.NoError(t, unittest.LoadFixtures())
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
diff --git a/integrations/integration_test.go b/integrations/integration_test.go
index 1429893270..69c4ca4ae5 100644
--- a/integrations/integration_test.go
+++ b/integrations/integration_test.go
@@ -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))
}
diff --git a/integrations/migrate_test.go b/integrations/migrate_test.go
index c0d5d4fc75..b9fcfb2827 100644
--- a/integrations/migrate_test.go
+++ b/integrations/migrate_test.go
@@ -8,6 +8,8 @@ import (
"os"
"testing"
+ "code.gitea.io/gitea/models/unittest"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/migrations"
@@ -17,7 +19,7 @@ import (
)
func TestMigrateLocalPath(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
adminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
diff --git a/integrations/repofiles_delete_test.go b/integrations/repofiles_delete_test.go
index 22fef4b03e..8150673e2b 100644
--- a/integrations/repofiles_delete_test.go
+++ b/integrations/repofiles_delete_test.go
@@ -8,8 +8,9 @@ import (
"net/url"
"testing"
+ "code.gitea.io/gitea/models/unittest"
+
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/repofiles"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -67,7 +68,7 @@ func TestDeleteRepoFile(t *testing.T) {
func testDeleteRepoFile(t *testing.T, u *url.URL) {
// setup
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -106,7 +107,7 @@ func TestDeleteRepoFileWithoutBranchNames(t *testing.T) {
func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
// setup
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -136,7 +137,7 @@ func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
func TestDeleteRepoFileErrors(t *testing.T) {
// setup
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)