diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-11-30 07:52:15 -0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-11-30 17:52:15 +0200 |
commit | 91f3d77ceb66bedc7bb4d792306beb547f104dce (patch) | |
tree | b081210cb7b6b26415e0e28ceb3a51477407a97e /models/wiki_test.go | |
parent | 82e8486f13253e5a2b1a06c286b1e2b2b6049473 (diff) | |
download | gitea-91f3d77ceb66bedc7bb4d792306beb547f104dce.tar.gz gitea-91f3d77ceb66bedc7bb4d792306beb547f104dce.zip |
Unit tests for wiki routers (#3022)
Diffstat (limited to 'models/wiki_test.go')
-rw-r--r-- | models/wiki_test.go | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/models/wiki_test.go b/models/wiki_test.go index e80c6cbb8d..c816a17558 100644 --- a/models/wiki_test.go +++ b/models/wiki_test.go @@ -74,6 +74,14 @@ func TestWikiFilenameToName(t *testing.T) { assert.NoError(t, err) assert.Equal(t, test.Expected, name) } + for _, badFilename := range []string{ + "nofileextension", + "wrongfileextension.txt", + "badescaping%%.md", + } { + _, err := WikiFilenameToName(badFilename) + assert.Error(t, err) + } } func TestWikiNameToFilenameToName(t *testing.T) { @@ -115,7 +123,7 @@ func TestRepository_WikiPath(t *testing.T) { } func TestRepository_HasWiki(t *testing.T) { - prepareTestEnv(t) + PrepareTestEnv(t) repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) assert.True(t, repo1.HasWiki()) repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository) @@ -123,7 +131,7 @@ func TestRepository_HasWiki(t *testing.T) { } func TestRepository_InitWiki(t *testing.T) { - prepareTestEnv(t) + PrepareTestEnv(t) // repo1 already has a wiki repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) assert.NoError(t, repo1.InitWiki()) @@ -135,7 +143,7 @@ func TestRepository_InitWiki(t *testing.T) { } func TestRepository_LocalWikiPath(t *testing.T) { - prepareTestEnv(t) + PrepareTestEnv(t) repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) expected := filepath.Join(setting.AppDataPath, "tmp/local-wiki/1") assert.Equal(t, expected, repo.LocalWikiPath()) @@ -150,11 +158,23 @@ func TestRepository_AddWikiPage(t *testing.T) { "Another page", "Here's a <tag> and a/slash", } { - prepareTestEnv(t) + PrepareTestEnv(t) assert.NoError(t, repo.AddWikiPage(doer, wikiName, wikiContent, commitMsg)) expectedPath := path.Join(repo.LocalWikiPath(), WikiNameToFilename(wikiName)) assert.True(t, com.IsExist(expectedPath)) } + + // test for already-existing wiki name + PrepareTestEnv(t) + err := repo.AddWikiPage(doer, "Home", wikiContent, commitMsg) + assert.Error(t, err) + assert.True(t, IsErrWikiAlreadyExist(err)) + + // test for reserved wiki name + PrepareTestEnv(t) + err = repo.AddWikiPage(doer, "_edit", wikiContent, commitMsg) + assert.Error(t, err) + assert.True(t, IsErrWikiReservedName(err)) } func TestRepository_EditWikiPage(t *testing.T) { @@ -163,20 +183,23 @@ func TestRepository_EditWikiPage(t *testing.T) { repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) for _, newWikiName := range []string{ + "Home", // same name as before "New home", "New/name/with/slashes", } { - prepareTestEnv(t) + PrepareTestEnv(t) assert.NoError(t, repo.EditWikiPage(doer, "Home", newWikiName, newWikiContent, commitMsg)) newPath := path.Join(repo.LocalWikiPath(), WikiNameToFilename(newWikiName)) assert.True(t, com.IsExist(newPath)) - oldPath := path.Join(repo.LocalWikiPath(), "Home.md") - assert.False(t, com.IsExist(oldPath)) + if newWikiName != "Home" { + oldPath := path.Join(repo.LocalWikiPath(), "Home.md") + assert.False(t, com.IsExist(oldPath)) + } } } func TestRepository_DeleteWikiPage(t *testing.T) { - prepareTestEnv(t) + PrepareTestEnv(t) repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) assert.NoError(t, repo.DeleteWikiPage(doer, "Home")) |