mirror of
https://github.com/go-gitea/gitea.git
synced 2025-06-21 05:28:00 +02:00
Add TestPrepareWikiFileName (#16487)
* Add TestPrepareWikiFileName * use LsTree as LsFiles is index only * ajust other tests Co-authored-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
@ -88,7 +88,7 @@ func prepareWikiFileName(gitRepo *git.Repository, wikiName string) (bool, string
|
||||
escaped := NameToFilename(wikiName)
|
||||
|
||||
// Look for both files
|
||||
filesInIndex, err := gitRepo.LsFiles(unescaped, escaped)
|
||||
filesInIndex, err := gitRepo.LsTree("master", unescaped, escaped)
|
||||
if err != nil {
|
||||
log.Error("%v", err)
|
||||
return false, escaped, err
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user