From 2814f2fea1313992c588444ead3643e54ea57c4d Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 20 Sep 2023 08:51:36 +0800 Subject: [PATCH] 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. --- services/wiki/wiki_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go index 6f05dedab..81a688b04 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")