Use assert in legacy unit tests (#867)

This commit is contained in:
Ethan Koenig 2017-02-08 01:29:07 -05:00 committed by Lunny Xiao
parent 23a7527e04
commit d2329e1c26
69 changed files with 249 additions and 6983 deletions

View file

@ -9,69 +9,40 @@ import (
"code.gitea.io/gitea/modules/markdown"
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
)
func TestRepo(t *testing.T) {
Convey("The metas map", t, func() {
var repo = new(Repository)
repo.Name = "testrepo"
repo.Owner = new(User)
repo.Owner.Name = "testuser"
externalTracker := RepoUnit{
Type: UnitTypeExternalTracker,
Config: &ExternalTrackerConfig{
ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
},
}
repo.Units = []*RepoUnit{
&externalTracker,
}
repo := &Repository{Name: "testRepo"}
repo.Owner = &User{Name: "testOwner"}
Convey("When no external tracker is configured", func() {
Convey("It should be nil", func() {
repo.Units = nil
So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
})
Convey("It should be nil even if other settings are present", func() {
repo.Units = nil
So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
})
})
repo.Units = nil
assert.Nil(t, repo.ComposeMetas())
Convey("When an external issue tracker is configured", func() {
repo.Units = []*RepoUnit{
&externalTracker,
}
Convey("It should default to numeric issue style", func() {
metas := repo.ComposeMetas()
So(metas["style"], ShouldEqual, markdown.IssueNameStyleNumeric)
})
Convey("It should pass through numeric issue style setting", func() {
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markdown.IssueNameStyleNumeric
metas := repo.ComposeMetas()
So(metas["style"], ShouldEqual, markdown.IssueNameStyleNumeric)
})
Convey("It should pass through alphanumeric issue style setting", func() {
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markdown.IssueNameStyleAlphanumeric
metas := repo.ComposeMetas()
So(metas["style"], ShouldEqual, markdown.IssueNameStyleAlphanumeric)
})
Convey("It should contain the user name", func() {
metas := repo.ComposeMetas()
So(metas["user"], ShouldEqual, "testuser")
})
Convey("It should contain the repo name", func() {
metas := repo.ComposeMetas()
So(metas["repo"], ShouldEqual, "testrepo")
})
Convey("It should contain the URL format", func() {
metas := repo.ComposeMetas()
So(metas["format"], ShouldEqual, "https://someurl.com/{user}/{repo}/{issue}")
})
})
})
externalTracker := RepoUnit{
Type: UnitTypeExternalTracker,
Config: &ExternalTrackerConfig{
ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
},
}
testSuccess := func(expectedStyle string) {
repo.Units = []*RepoUnit{&externalTracker}
repo.ExternalMetas = nil
metas := repo.ComposeMetas()
assert.Equal(t, expectedStyle, metas["style"])
assert.Equal(t, "testRepo", metas["repo"])
assert.Equal(t, "testOwner", metas["user"])
assert.Equal(t, "https://someurl.com/{user}/{repo}/{issue}", metas["format"])
}
testSuccess(markdown.IssueNameStyleNumeric)
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markdown.IssueNameStyleAlphanumeric
testSuccess(markdown.IssueNameStyleAlphanumeric)
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markdown.IssueNameStyleNumeric
testSuccess(markdown.IssueNameStyleNumeric)
}
func TestGetRepositoryCount(t *testing.T) {