Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TestPrepareWikiFileName #16487

Merged
merged 8 commits into from
Jul 20, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions services/wiki/wiki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,53 @@ 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())
assert.NoError(t, err)

tests := []struct {
name string
arg string
hasWiki bool
wikiPath string
wantErr bool
}{{
name: "add suffix",
arg: "home",
hasWiki: true,
wikiPath: "home.md",
wantErr: false,
}, {
name: "test special chars",
arg: "home of and & or wiki page!",
hasWiki: true,
wikiPath: "home-of-and-%26-or-wiki-page%21.md",
wantErr: false,
}, {
name: "strange cases",
arg: "...",
hasWiki: true,
wikiPath: "....md",
wantErr: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
isWikiExist, newWikiPath, err := prepareWikiFileName(gitRepo, tt.arg)
if (err != nil) != tt.wantErr {
assert.NoError(t, err)
return
}
if isWikiExist != tt.hasWiki {
if isWikiExist {
t.Errorf("expect to have no wiki but we detect one")
} else {
t.Errorf("expect to have wiki but we could not detect one")
}
}
assert.Equal(t, tt.wikiPath, newWikiPath)
})
}
}