Better settings for unit tests (#795)

This commit is contained in:
Ethan Koenig 2017-01-30 00:17:43 -05:00 committed by Lunny Xiao
parent 78535fb08e
commit 7765593018
2 changed files with 11 additions and 5 deletions

View file

@ -30,8 +30,8 @@ func TestMain(m *testing.M) {
setting.RunUser = "runuser" setting.RunUser = "runuser"
setting.SSH.Port = 3000 setting.SSH.Port = 3000
setting.SSH.Domain = "try.gitea.io" setting.SSH.Domain = "try.gitea.io"
setting.RepoRootPath = "/repos" setting.RepoRootPath = "/tmp/repos"
setting.AppDataPath = "/appdata" setting.AppDataPath = "/tmp/appdata"
os.Exit(m.Run()) os.Exit(m.Run())
} }

View file

@ -5,8 +5,11 @@
package models package models
import ( import (
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -33,13 +36,15 @@ func TestRepository_WikiCloneLink(t *testing.T) {
func TestWikiPath(t *testing.T) { func TestWikiPath(t *testing.T) {
assert.NoError(t, PrepareTestDatabase()) assert.NoError(t, PrepareTestDatabase())
assert.Equal(t, "/repos/user2/repo1.wiki.git", WikiPath("user2", "repo1")) expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
assert.Equal(t, expected, WikiPath("user2", "repo1"))
} }
func TestRepository_WikiPath(t *testing.T) { func TestRepository_WikiPath(t *testing.T) {
assert.NoError(t, PrepareTestDatabase()) assert.NoError(t, PrepareTestDatabase())
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
assert.Equal(t, "/repos/user2/repo1.wiki.git", repo.WikiPath()) expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
assert.Equal(t, expected, repo.WikiPath())
} }
// TODO TestRepository_HasWiki // TODO TestRepository_HasWiki
@ -49,7 +54,8 @@ func TestRepository_WikiPath(t *testing.T) {
func TestRepository_LocalWikiPath(t *testing.T) { func TestRepository_LocalWikiPath(t *testing.T) {
assert.NoError(t, PrepareTestDatabase()) assert.NoError(t, PrepareTestDatabase())
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
assert.Equal(t, "/appdata/tmp/local-wiki/1", repo.LocalWikiPath()) expected := filepath.Join(setting.AppDataPath, "tmp/local-wiki/1")
assert.Equal(t, expected, repo.LocalWikiPath())
} }
// TODO TestRepository_UpdateLocalWiki // TODO TestRepository_UpdateLocalWiki