summaryrefslogtreecommitdiffstats
path: root/services/wiki
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 /services/wiki
parent7f802631c54d2e91301158380b273b872d62bd80 (diff)
downloadgitea-df64fa486555de6f403a795fd16c2e9e1d59e535.tar.gz
gitea-df64fa486555de6f403a795fd16c2e9e1d59e535.zip
Decouple unit test code from business code (#17623)
Diffstat (limited to 'services/wiki')
-rw-r--r--services/wiki/wiki_test.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go
index d6a65cc23a..7ecd3bb04e 100644
--- a/services/wiki/wiki_test.go
+++ b/services/wiki/wiki_test.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/util"
@@ -18,7 +19,7 @@ import (
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
func TestWikiNameToSubURL(t *testing.T) {
@@ -110,7 +111,7 @@ func TestWikiNameToFilenameToName(t *testing.T) {
}
func TestRepository_InitWiki(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
// repo1 already has a wiki
repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
assert.NoError(t, InitWiki(repo1))
@@ -122,7 +123,7 @@ func TestRepository_InitWiki(t *testing.T) {
}
func TestRepository_AddWikiPage(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
const wikiContent = "This is the wiki content"
const commitMsg = "Commit message"
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
@@ -166,7 +167,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
}
func TestRepository_EditWikiPage(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
const newWikiContent = "This is the new content"
const commitMsg = "Commit message"
@@ -177,7 +178,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
"New home",
"New/name/with/slashes",
} {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
assert.NoError(t, EditWikiPage(doer, repo, "Home", newWikiName, newWikiContent, commitMsg))
// Now need to show that the page has been added:
@@ -199,7 +200,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
}
func TestRepository_DeleteWikiPage(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
doer := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
assert.NoError(t, DeleteWikiPage(doer, repo, "Home"))
@@ -216,7 +217,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
}
func TestPrepareWikiFileName(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
gitRepo, err := git.OpenRepository(repo.WikiPath())
defer gitRepo.Close()
@@ -267,7 +268,7 @@ func TestPrepareWikiFileName(t *testing.T) {
}
func TestPrepareWikiFileName_FirstPage(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
// Now create a temporaryDirectory
tmpDir, err := os.MkdirTemp("", "empty-wiki")