aboutsummaryrefslogtreecommitdiffstats
path: root/services/wiki/wiki_test.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-09-20 08:51:36 +0800
committerGitHub <noreply@github.com>2023-09-20 08:51:36 +0800
commit2814f2fea1313992c588444ead3643e54ea57c4d (patch)
tree5542c3aa9962a31025b3ece934149c05652499df /services/wiki/wiki_test.go
parent1b1c55f73f85f647209df0ab1ebdd60040231b0a (diff)
downloadgitea-2814f2fea1313992c588444ead3643e54ea57c4d.tar.gz
gitea-2814f2fea1313992c588444ead3643e54ea57c4d.zip
Fix incorrect test code for error handling (#27139)
If `assert.NoError` fails, it should return. Otherwise the code could still execute even if the error occurs.
Diffstat (limited to 'services/wiki/wiki_test.go')
-rw-r--r--services/wiki/wiki_test.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go
index 6f05dedab6..81a688b046 100644
--- a/services/wiki/wiki_test.go
+++ b/services/wiki/wiki_test.go
@@ -168,7 +168,9 @@ func TestRepository_AddWikiPage(t *testing.T) {
assert.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, webPath, wikiContent, commitMsg))
// Now need to show that the page has been added:
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
- assert.NoError(t, err)
+ if !assert.NoError(t, err) {
+ return
+ }
defer gitRepo.Close()
masterTree, err := gitRepo.GetTree(DefaultBranch)
assert.NoError(t, err)
@@ -238,7 +240,9 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
// Now need to show that the page has been added:
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
- assert.NoError(t, err)
+ if !assert.NoError(t, err) {
+ return
+ }
defer gitRepo.Close()
masterTree, err := gitRepo.GetTree(DefaultBranch)
assert.NoError(t, err)
@@ -251,7 +255,9 @@ func TestPrepareWikiFileName(t *testing.T) {
unittest.PrepareTestEnv(t)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
- assert.NoError(t, err)
+ if !assert.NoError(t, err) {
+ return
+ }
defer gitRepo.Close()
tests := []struct {
@@ -303,7 +309,9 @@ func TestPrepareWikiFileName_FirstPage(t *testing.T) {
assert.NoError(t, err)
gitRepo, err := git.OpenRepository(git.DefaultContext, tmpDir)
- assert.NoError(t, err)
+ if !assert.NoError(t, err) {
+ return
+ }
defer gitRepo.Close()
existence, newWikiPath, err := prepareGitPath(gitRepo, "Home")