You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_test.go 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package models_test
  2. import (
  3. "testing"
  4. . "code.gitea.io/gitea/models"
  5. "code.gitea.io/gitea/modules/markdown"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestRepo(t *testing.T) {
  9. Convey("The metas map", t, func() {
  10. var repo = new(Repository)
  11. repo.Name = "testrepo"
  12. repo.Owner = new(User)
  13. repo.Owner.Name = "testuser"
  14. externalTracker := RepoUnit{
  15. Type: UnitTypeExternalTracker,
  16. Config: &ExternalTrackerConfig{
  17. ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
  18. },
  19. }
  20. repo.Units = []*RepoUnit{
  21. &externalTracker,
  22. }
  23. Convey("When no external tracker is configured", func() {
  24. Convey("It should be nil", func() {
  25. repo.Units = nil
  26. So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
  27. })
  28. Convey("It should be nil even if other settings are present", func() {
  29. repo.Units = nil
  30. So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
  31. })
  32. })
  33. Convey("When an external issue tracker is configured", func() {
  34. repo.Units = []*RepoUnit{
  35. &externalTracker,
  36. }
  37. Convey("It should default to numeric issue style", func() {
  38. metas := repo.ComposeMetas()
  39. So(metas["style"], ShouldEqual, markdown.IssueNameStyleNumeric)
  40. })
  41. Convey("It should pass through numeric issue style setting", func() {
  42. externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markdown.IssueNameStyleNumeric
  43. metas := repo.ComposeMetas()
  44. So(metas["style"], ShouldEqual, markdown.IssueNameStyleNumeric)
  45. })
  46. Convey("It should pass through alphanumeric issue style setting", func() {
  47. externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markdown.IssueNameStyleAlphanumeric
  48. metas := repo.ComposeMetas()
  49. So(metas["style"], ShouldEqual, markdown.IssueNameStyleAlphanumeric)
  50. })
  51. Convey("It should contain the user name", func() {
  52. metas := repo.ComposeMetas()
  53. So(metas["user"], ShouldEqual, "testuser")
  54. })
  55. Convey("It should contain the repo name", func() {
  56. metas := repo.ComposeMetas()
  57. So(metas["repo"], ShouldEqual, "testrepo")
  58. })
  59. Convey("It should contain the URL format", func() {
  60. metas := repo.ComposeMetas()
  61. So(metas["format"], ShouldEqual, "https://someurl.com/{user}/{repo}/{issue}")
  62. })
  63. })
  64. })
  65. }