repo_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package models_test
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. . "github.com/gogs/gogs/models"
  6. "github.com/gogs/gogs/pkg/markup"
  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. repo.ExternalTrackerFormat = "https://someurl.com/{user}/{repo}/{issue}"
  15. Convey("When no external tracker is configured", func() {
  16. Convey("It should be nil", func() {
  17. repo.EnableExternalTracker = false
  18. So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
  19. })
  20. Convey("It should be nil even if other settings are present", func() {
  21. repo.EnableExternalTracker = false
  22. repo.ExternalTrackerFormat = "http://someurl.com/{user}/{repo}/{issue}"
  23. repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
  24. So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
  25. })
  26. })
  27. Convey("When an external issue tracker is configured", func() {
  28. repo.EnableExternalTracker = true
  29. Convey("It should default to numeric issue style", func() {
  30. metas := repo.ComposeMetas()
  31. So(metas["style"], ShouldEqual, markup.ISSUE_NAME_STYLE_NUMERIC)
  32. })
  33. Convey("It should pass through numeric issue style setting", func() {
  34. repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
  35. metas := repo.ComposeMetas()
  36. So(metas["style"], ShouldEqual, markup.ISSUE_NAME_STYLE_NUMERIC)
  37. })
  38. Convey("It should pass through alphanumeric issue style setting", func() {
  39. repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_ALPHANUMERIC
  40. metas := repo.ComposeMetas()
  41. So(metas["style"], ShouldEqual, markup.ISSUE_NAME_STYLE_ALPHANUMERIC)
  42. })
  43. Convey("It should contain the user name", func() {
  44. metas := repo.ComposeMetas()
  45. So(metas["user"], ShouldEqual, "testuser")
  46. })
  47. Convey("It should contain the repo name", func() {
  48. metas := repo.ComposeMetas()
  49. So(metas["repo"], ShouldEqual, "testrepo")
  50. })
  51. Convey("It should contain the URL format", func() {
  52. metas := repo.ComposeMetas()
  53. So(metas["format"], ShouldEqual, "https://someurl.com/{user}/{repo}/{issue}")
  54. })
  55. })
  56. })
  57. }