aboutsummaryrefslogtreecommitdiffstats
path: root/services/wiki/wiki_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'services/wiki/wiki_test.go')
-rw-r--r--services/wiki/wiki_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go
index b35b86d655..a1614b509c 100644
--- a/services/wiki/wiki_test.go
+++ b/services/wiki/wiki_test.go
@@ -210,3 +210,54 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
_, err = masterTree.GetTreeEntryByPath(wikiPath)
assert.Error(t, err)
}
+
+func TestPrepareWikiFileName(t *testing.T) {
+ models.PrepareTestEnv(t)
+ repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ gitRepo, err := git.OpenRepository(repo.WikiPath())
+ defer gitRepo.Close()
+ assert.NoError(t, err)
+
+ tests := []struct {
+ name string
+ arg string
+ existence bool
+ wikiPath string
+ wantErr bool
+ }{{
+ name: "add suffix",
+ arg: "Home",
+ existence: true,
+ wikiPath: "Home.md",
+ wantErr: false,
+ }, {
+ name: "test special chars",
+ arg: "home of and & or wiki page!",
+ existence: false,
+ wikiPath: "home-of-and-%26-or-wiki-page%21.md",
+ wantErr: false,
+ }, {
+ name: "fount unescaped cases",
+ arg: "Unescaped File",
+ existence: true,
+ wikiPath: "Unescaped File.md",
+ wantErr: false,
+ }}
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ existence, newWikiPath, err := prepareWikiFileName(gitRepo, tt.arg)
+ if (err != nil) != tt.wantErr {
+ assert.NoError(t, err)
+ return
+ }
+ if existence != tt.existence {
+ if existence {
+ t.Errorf("expect to find no escaped file but we detect one")
+ } else {
+ t.Errorf("expect to find an escaped file but we could not detect one")
+ }
+ }
+ assert.Equal(t, tt.wikiPath, newWikiPath)
+ })
+ }
+}