Skip to content

Commit 31c717f

Browse files
authored
Merge pull request #777 from ethantkoenig/tests/wiki
Unit tests for models/wiki
2 parents abf3fbf + bb76285 commit 31c717f

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

models/setup_for_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"os"
1010
"testing"
1111

12+
"code.gitea.io/gitea/modules/setting"
13+
1214
"github.com/go-xorm/core"
1315
"github.com/go-xorm/xorm"
1416
_ "github.com/mattn/go-sqlite3" // for the test engine
@@ -23,6 +25,14 @@ func TestMain(m *testing.M) {
2325
fmt.Printf("Error creating test engine: %v\n", err)
2426
os.Exit(1)
2527
}
28+
29+
setting.AppURL = "https://try.gitea.io/"
30+
setting.RunUser = "runuser"
31+
setting.SSH.Port = 3000
32+
setting.SSH.Domain = "try.gitea.io"
33+
setting.RepoRootPath = "/repos"
34+
setting.AppDataPath = "/appdata"
35+
2636
os.Exit(m.Run())
2737
}
2838

models/wiki.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func ToWikiPageName(urlString string) string {
4141
}
4242

4343
// WikiCloneLink returns clone URLs of repository wiki.
44-
func (repo *Repository) WikiCloneLink() (cl *CloneLink) {
44+
func (repo *Repository) WikiCloneLink() *CloneLink {
4545
return repo.cloneLink(true)
4646
}
4747

models/wiki_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package models
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestToWikiPageURL(t *testing.T) {
14+
assert.Equal(t, "wiki-name", ToWikiPageURL("wiki-name"))
15+
assert.Equal(t, "wiki-name-with-many-spaces", ToWikiPageURL("wiki name with many spaces"))
16+
}
17+
18+
func TestToWikiPageName(t *testing.T) {
19+
assert.Equal(t, "wiki name", ToWikiPageName("wiki name"))
20+
assert.Equal(t, "wiki name", ToWikiPageName("wiki-name"))
21+
assert.Equal(t, "wiki name", ToWikiPageName("wiki\tname"))
22+
assert.Equal(t, "wiki name", ToWikiPageName("./.././wiki/name"))
23+
}
24+
25+
func TestRepository_WikiCloneLink(t *testing.T) {
26+
assert.NoError(t, PrepareTestDatabase())
27+
28+
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
29+
cloneLink := repo.WikiCloneLink()
30+
assert.Equal(t, "ssh://[email protected]:3000/user2/repo1.wiki.git", cloneLink.SSH)
31+
assert.Equal(t, "https://try.gitea.io/user2/repo1.wiki.git", cloneLink.HTTPS)
32+
}
33+
34+
func TestWikiPath(t *testing.T) {
35+
assert.NoError(t, PrepareTestDatabase())
36+
assert.Equal(t, "/repos/user2/repo1.wiki.git", WikiPath("user2", "repo1"))
37+
}
38+
39+
func TestRepository_WikiPath(t *testing.T) {
40+
assert.NoError(t, PrepareTestDatabase())
41+
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
42+
assert.Equal(t, "/repos/user2/repo1.wiki.git", repo.WikiPath())
43+
}
44+
45+
// TODO TestRepository_HasWiki
46+
47+
// TODO TestRepository_InitWiki
48+
49+
func TestRepository_LocalWikiPath(t *testing.T) {
50+
assert.NoError(t, PrepareTestDatabase())
51+
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
52+
assert.Equal(t, "/appdata/tmp/local-wiki/1", repo.LocalWikiPath())
53+
}
54+
55+
// TODO TestRepository_UpdateLocalWiki
56+
57+
// TODO ... (all remaining untested functions)

0 commit comments

Comments
 (0)