tag_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2020 The Gogs 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 gitutil
  5. import (
  6. "testing"
  7. "github.com/gogs/git-module"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestModuler_ListTagsAfter(t *testing.T) {
  11. MockModule.RepoTags = func(string, ...git.TagsOptions) ([]string, error) {
  12. return []string{
  13. "v2.3.0", "v2.2.1", "v2.1.0",
  14. "v1.3.0", "v1.2.0", "v1.1.0",
  15. "v0.8.0", "v0.5.0", "v0.1.0",
  16. }, nil
  17. }
  18. defer func() {
  19. MockModule = MockModuleStore{}
  20. }()
  21. tests := []struct {
  22. name string
  23. after string
  24. expTagsPage *TagsPage
  25. }{
  26. {
  27. name: "first page",
  28. expTagsPage: &TagsPage{
  29. Tags: []string{
  30. "v2.3.0", "v2.2.1", "v2.1.0",
  31. },
  32. HasLatest: true,
  33. HasNext: true,
  34. },
  35. },
  36. {
  37. name: "second page",
  38. after: "v2.1.0",
  39. expTagsPage: &TagsPage{
  40. Tags: []string{
  41. "v1.3.0", "v1.2.0", "v1.1.0",
  42. },
  43. HasLatest: false,
  44. HasNext: true,
  45. },
  46. },
  47. {
  48. name: "last page",
  49. after: "v1.1.0",
  50. expTagsPage: &TagsPage{
  51. Tags: []string{
  52. "v0.8.0", "v0.5.0", "v0.1.0",
  53. },
  54. HasLatest: false,
  55. PreviousAfter: "v2.1.0",
  56. HasNext: false,
  57. },
  58. },
  59. {
  60. name: "arbitrary after",
  61. after: "v1.2.0",
  62. expTagsPage: &TagsPage{
  63. Tags: []string{
  64. "v1.1.0", "v0.8.0", "v0.5.0",
  65. },
  66. HasLatest: false,
  67. PreviousAfter: "v2.2.1",
  68. HasNext: true,
  69. },
  70. },
  71. {
  72. name: "after the oldest one",
  73. after: "v0.1.0",
  74. expTagsPage: &TagsPage{
  75. Tags: []string{},
  76. HasLatest: false,
  77. PreviousAfter: "v1.1.0",
  78. HasNext: false,
  79. },
  80. },
  81. {
  82. name: "after does not exist",
  83. after: "v2.2.9",
  84. expTagsPage: &TagsPage{
  85. Tags: []string{
  86. "v2.3.0", "v2.2.1", "v2.1.0",
  87. },
  88. HasLatest: true,
  89. HasNext: true,
  90. },
  91. },
  92. }
  93. for _, test := range tests {
  94. t.Run(test.name, func(t *testing.T) {
  95. tagsPage, err := Module.ListTagsAfter("", test.after, 3)
  96. if err != nil {
  97. t.Fatal(err)
  98. }
  99. assert.Equal(t, test.expTagsPage, tagsPage)
  100. })
  101. }
  102. }