repo_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package models_test
  2. import (
  3. . "github.com/gogits/gogs/models"
  4. . "github.com/smartystreets/goconvey/convey"
  5. "testing"
  6. "github.com/gogits/gogs/modules/markdown"
  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. }