2020-04-19 04:24:08 +08:00
|
|
|
package db
|
2016-04-22 17:28:08 -05:00
|
|
|
|
|
|
|
|
import (
|
2016-07-09 07:22:28 +02:00
|
|
|
"testing"
|
2016-04-22 17:28:08 -05:00
|
|
|
|
2020-04-19 04:24:08 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2017-03-31 18:28:08 -04:00
|
|
|
|
2019-10-24 01:51:46 -07:00
|
|
|
"gogs.io/gogs/internal/markup"
|
2016-04-22 17:28:08 -05:00
|
|
|
)
|
|
|
|
|
|
2020-04-19 04:24:08 +08:00
|
|
|
func TestRepository_ComposeMetas(t *testing.T) {
|
|
|
|
|
repo := &Repository{
|
|
|
|
|
Name: "testrepo",
|
|
|
|
|
Owner: &User{
|
|
|
|
|
Name: "testuser",
|
|
|
|
|
},
|
|
|
|
|
ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.Run("no external tracker is configured", func(t *testing.T) {
|
|
|
|
|
repo.EnableExternalTracker = false
|
|
|
|
|
|
2020-09-29 23:07:16 +08:00
|
|
|
metas := repo.ComposeMetas()
|
|
|
|
|
assert.Equal(t, metas["repoLink"], repo.Link())
|
|
|
|
|
|
|
|
|
|
// Should no format and style if no external tracker is configured
|
|
|
|
|
_, ok := metas["format"]
|
|
|
|
|
assert.False(t, ok)
|
|
|
|
|
_, ok = metas["style"]
|
|
|
|
|
assert.False(t, ok)
|
2020-04-19 04:24:08 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("an external issue tracker is configured", func(t *testing.T) {
|
2020-09-29 23:07:16 +08:00
|
|
|
repo.ExternalMetas = nil
|
2020-04-19 04:24:08 +08:00
|
|
|
repo.EnableExternalTracker = true
|
|
|
|
|
|
|
|
|
|
// Default to numeric issue style
|
2022-01-13 11:27:16 +08:00
|
|
|
assert.Equal(t, markup.IssueNameStyleNumeric, repo.ComposeMetas()["style"])
|
2020-04-19 04:24:08 +08:00
|
|
|
repo.ExternalMetas = nil
|
|
|
|
|
|
2022-01-13 11:27:16 +08:00
|
|
|
repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
|
|
|
|
|
assert.Equal(t, markup.IssueNameStyleNumeric, repo.ComposeMetas()["style"])
|
2020-04-19 04:24:08 +08:00
|
|
|
repo.ExternalMetas = nil
|
|
|
|
|
|
2022-01-13 11:27:16 +08:00
|
|
|
repo.ExternalTrackerStyle = markup.IssueNameStyleAlphanumeric
|
|
|
|
|
assert.Equal(t, markup.IssueNameStyleAlphanumeric, repo.ComposeMetas()["style"])
|
2020-04-19 04:24:08 +08:00
|
|
|
repo.ExternalMetas = nil
|
|
|
|
|
|
|
|
|
|
metas := repo.ComposeMetas()
|
|
|
|
|
assert.Equal(t, "testuser", metas["user"])
|
|
|
|
|
assert.Equal(t, "testrepo", metas["repo"])
|
|
|
|
|
assert.Equal(t, "https://someurl.com/{user}/{repo}/{issue}", metas["format"])
|
2016-04-22 17:28:08 -05:00
|
|
|
})
|
|
|
|
|
}
|