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.

repo_test.go 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/modules/markdown"
  8. . "github.com/smartystreets/goconvey/convey"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestRepo(t *testing.T) {
  12. Convey("The metas map", t, func() {
  13. var repo = new(Repository)
  14. repo.Name = "testrepo"
  15. repo.Owner = new(User)
  16. repo.Owner.Name = "testuser"
  17. externalTracker := RepoUnit{
  18. Type: UnitTypeExternalTracker,
  19. Config: &ExternalTrackerConfig{
  20. ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
  21. },
  22. }
  23. repo.Units = []*RepoUnit{
  24. &externalTracker,
  25. }
  26. Convey("When no external tracker is configured", func() {
  27. Convey("It should be nil", func() {
  28. repo.Units = nil
  29. So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
  30. })
  31. Convey("It should be nil even if other settings are present", func() {
  32. repo.Units = nil
  33. So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
  34. })
  35. })
  36. Convey("When an external issue tracker is configured", func() {
  37. repo.Units = []*RepoUnit{
  38. &externalTracker,
  39. }
  40. Convey("It should default to numeric issue style", func() {
  41. metas := repo.ComposeMetas()
  42. So(metas["style"], ShouldEqual, markdown.IssueNameStyleNumeric)
  43. })
  44. Convey("It should pass through numeric issue style setting", func() {
  45. externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markdown.IssueNameStyleNumeric
  46. metas := repo.ComposeMetas()
  47. So(metas["style"], ShouldEqual, markdown.IssueNameStyleNumeric)
  48. })
  49. Convey("It should pass through alphanumeric issue style setting", func() {
  50. externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markdown.IssueNameStyleAlphanumeric
  51. metas := repo.ComposeMetas()
  52. So(metas["style"], ShouldEqual, markdown.IssueNameStyleAlphanumeric)
  53. })
  54. Convey("It should contain the user name", func() {
  55. metas := repo.ComposeMetas()
  56. So(metas["user"], ShouldEqual, "testuser")
  57. })
  58. Convey("It should contain the repo name", func() {
  59. metas := repo.ComposeMetas()
  60. So(metas["repo"], ShouldEqual, "testrepo")
  61. })
  62. Convey("It should contain the URL format", func() {
  63. metas := repo.ComposeMetas()
  64. So(metas["format"], ShouldEqual, "https://someurl.com/{user}/{repo}/{issue}")
  65. })
  66. })
  67. })
  68. }
  69. func TestGetRepositoryCount(t *testing.T) {
  70. assert.NoError(t, PrepareTestDatabase())
  71. count, err1 := GetRepositoryCount(&User{ID: int64(10)})
  72. privateCount, err2 := GetPrivateRepositoryCount(&User{ID: int64(10)})
  73. publicCount, err3 := GetPublicRepositoryCount(&User{ID: int64(10)})
  74. assert.NoError(t, err1)
  75. assert.NoError(t, err2)
  76. assert.NoError(t, err3)
  77. assert.Equal(t, int64(3), count)
  78. assert.Equal(t, (privateCount + publicCount), count)
  79. }
  80. func TestGetPublicRepositoryCount(t *testing.T) {
  81. assert.NoError(t, PrepareTestDatabase())
  82. count, err := GetPublicRepositoryCount(&User{ID: int64(10)})
  83. assert.NoError(t, err)
  84. assert.Equal(t, int64(1), count)
  85. }
  86. func TestGetPrivateRepositoryCount(t *testing.T) {
  87. assert.NoError(t, PrepareTestDatabase())
  88. count, err := GetPrivateRepositoryCount(&User{ID: int64(10)})
  89. assert.NoError(t, err)
  90. assert.Equal(t, int64(2), count)
  91. }