summaryrefslogtreecommitdiffstats
path: root/models/repo_test.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-02-08 01:29:07 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2017-02-08 14:29:07 +0800
commitd2329e1c261bb235bfa32692710434936b98533b (patch)
tree148096febc87256d680a697673e08accb6afa355 /models/repo_test.go
parent23a7527e040a2ea6612db040544cf204b7969d55 (diff)
downloadgitea-d2329e1c261bb235bfa32692710434936b98533b.tar.gz
gitea-d2329e1c261bb235bfa32692710434936b98533b.zip
Use assert in legacy unit tests (#867)
Diffstat (limited to 'models/repo_test.go')
-rw-r--r--models/repo_test.go89
1 files changed, 30 insertions, 59 deletions
diff --git a/models/repo_test.go b/models/repo_test.go
index 499c8c83eb..db8bd1024e 100644
--- a/models/repo_test.go
+++ b/models/repo_test.go
@@ -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,
- }
-
- 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))
- })
- })
-
- 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}")
- })
- })
- })
+ repo := &Repository{Name: "testRepo"}
+ repo.Owner = &User{Name: "testOwner"}
+
+ repo.Units = nil
+ assert.Nil(t, repo.ComposeMetas())
+
+ 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) {