repo_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2015 - Present, The Gogs Authors. All rights reserved.
  2. // Copyright 2018 - Present, Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package models_test
  7. import (
  8. . "gitote/gitote/models"
  9. "gitote/gitote/pkg/markup"
  10. "testing"
  11. . "github.com/smartystreets/goconvey/convey"
  12. )
  13. func TestRepo(t *testing.T) {
  14. Convey("The metas map", t, func() {
  15. var repo = new(Repository)
  16. repo.Name = "testrepo"
  17. repo.Owner = new(User)
  18. repo.Owner.Name = "testuser"
  19. repo.ExternalTrackerFormat = "https://gitlab.com/{user}/{repo}/{issue}"
  20. Convey("When no external tracker is configured", func() {
  21. Convey("It should be nil", func() {
  22. repo.EnableExternalTracker = false
  23. So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
  24. })
  25. Convey("It should be nil even if other settings are present", func() {
  26. repo.EnableExternalTracker = false
  27. repo.ExternalTrackerFormat = "http://gitlab.com/{user}/{repo}/{issue}"
  28. repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
  29. So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
  30. })
  31. })
  32. Convey("When an external issue tracker is configured", func() {
  33. repo.EnableExternalTracker = true
  34. Convey("It should default to numeric issue style", func() {
  35. metas := repo.ComposeMetas()
  36. So(metas["style"], ShouldEqual, markup.IssueNameStyleNumeric)
  37. })
  38. Convey("It should pass through numeric issue style setting", func() {
  39. repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
  40. metas := repo.ComposeMetas()
  41. So(metas["style"], ShouldEqual, markup.IssueNameStyleNumeric)
  42. })
  43. Convey("It should pass through alphanumeric issue style setting", func() {
  44. repo.ExternalTrackerStyle = markup.IssueNameStyleAlphaNumeric
  45. metas := repo.ComposeMetas()
  46. So(metas["style"], ShouldEqual, markup.IssueNameStyleAlphaNumeric)
  47. })
  48. Convey("It should contain the user name", func() {
  49. metas := repo.ComposeMetas()
  50. So(metas["user"], ShouldEqual, "testuser")
  51. })
  52. Convey("It should contain the repo name", func() {
  53. metas := repo.ComposeMetas()
  54. So(metas["repo"], ShouldEqual, "testrepo")
  55. })
  56. Convey("It should contain the URL format", func() {
  57. metas := repo.ComposeMetas()
  58. So(metas["format"], ShouldEqual, "https://gitlab.com/{user}/{repo}/{issue}")
  59. })
  60. })
  61. })
  62. }