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

62 lines
2.2 KiB

  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. 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 = markdown.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, markdown.ISSUE_NAME_STYLE_NUMERIC)
  32. })
  33. Convey("It should pass through numeric issue style setting", func() {
  34. repo.ExternalTrackerStyle = markdown.ISSUE_NAME_STYLE_NUMERIC
  35. metas := repo.ComposeMetas()
  36. So(metas["style"], ShouldEqual, markdown.ISSUE_NAME_STYLE_NUMERIC)
  37. })
  38. Convey("It should pass through alphanumeric issue style setting", func() {
  39. repo.ExternalTrackerStyle = markdown.ISSUE_NAME_STYLE_ALPHANUMERIC
  40. metas := repo.ComposeMetas()
  41. So(metas["style"], ShouldEqual, markdown.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. }