summaryrefslogtreecommitdiffstats
path: root/services/wiki/wiki_test.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-08-01 18:04:32 +0100
committerGitHub <noreply@github.com>2021-08-01 19:04:32 +0200
commite51c73ae5c03c83256d48cdcd0ca9cbdbf7a5222 (patch)
tree1e6f6cfc023da95a1c7fb28cae8ebf785ec7f352 /services/wiki/wiki_test.go
parentd686d7b05231ee43d6901317208c1dd851dacfa9 (diff)
downloadgitea-e51c73ae5c03c83256d48cdcd0ca9cbdbf7a5222.tar.gz
gitea-e51c73ae5c03c83256d48cdcd0ca9cbdbf7a5222.zip
Fix 500 on first wiki page (#16586)
* Fix 500 on first wiki page There is a mistake in #16319 and #16487 which means that the first time a wiki page is created a 500 is reported because the `master` branch is not in existence in that wiki yet. This PR simply checks for this error and returns not found. Fix #16584 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/wiki/wiki_test.go')
-rw-r--r--services/wiki/wiki_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go
index a1614b509c..6c861d556a 100644
--- a/services/wiki/wiki_test.go
+++ b/services/wiki/wiki_test.go
@@ -5,11 +5,15 @@
package wiki
import (
+ "io/ioutil"
+ "os"
"path/filepath"
"testing"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/util"
+
"github.com/stretchr/testify/assert"
)
@@ -261,3 +265,28 @@ func TestPrepareWikiFileName(t *testing.T) {
})
}
}
+
+func TestPrepareWikiFileName_FirstPage(t *testing.T) {
+ models.PrepareTestEnv(t)
+
+ // Now create a temporaryDirectory
+ tmpDir, err := ioutil.TempDir("", "empty-wiki")
+ assert.NoError(t, err)
+ defer func() {
+ if _, err := os.Stat(tmpDir); !os.IsNotExist(err) {
+ _ = util.RemoveAll(tmpDir)
+ }
+ }()
+
+ err = git.InitRepository(tmpDir, true)
+ assert.NoError(t, err)
+
+ gitRepo, err := git.OpenRepository(tmpDir)
+ defer gitRepo.Close()
+ assert.NoError(t, err)
+
+ existence, newWikiPath, err := prepareWikiFileName(gitRepo, "Home")
+ assert.False(t, existence)
+ assert.NoError(t, err)
+ assert.Equal(t, "Home.md", newWikiPath)
+}