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.

152 lines
4.0 KiB

  1. // Copyright 2018 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/git"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestRelease_Create(t *testing.T) {
  11. assert.NoError(t, PrepareTestDatabase())
  12. user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  13. repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
  14. repoPath := RepoPath(user.Name, repo.Name)
  15. gitRepo, err := git.OpenRepository(repoPath)
  16. assert.NoError(t, err)
  17. assert.NoError(t, CreateRelease(gitRepo, &Release{
  18. RepoID: repo.ID,
  19. PublisherID: user.ID,
  20. TagName: "v0.1",
  21. Target: "master",
  22. Title: "v0.1 is released",
  23. Note: "v0.1 is released",
  24. IsDraft: false,
  25. IsPrerelease: false,
  26. IsTag: false,
  27. }, nil))
  28. assert.NoError(t, CreateRelease(gitRepo, &Release{
  29. RepoID: repo.ID,
  30. PublisherID: user.ID,
  31. TagName: "v0.1.1",
  32. Target: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
  33. Title: "v0.1.1 is released",
  34. Note: "v0.1.1 is released",
  35. IsDraft: false,
  36. IsPrerelease: false,
  37. IsTag: false,
  38. }, nil))
  39. assert.NoError(t, CreateRelease(gitRepo, &Release{
  40. RepoID: repo.ID,
  41. PublisherID: user.ID,
  42. TagName: "v0.1.2",
  43. Target: "65f1bf2",
  44. Title: "v0.1.2 is released",
  45. Note: "v0.1.2 is released",
  46. IsDraft: false,
  47. IsPrerelease: false,
  48. IsTag: false,
  49. }, nil))
  50. assert.NoError(t, CreateRelease(gitRepo, &Release{
  51. RepoID: repo.ID,
  52. PublisherID: user.ID,
  53. TagName: "v0.1.3",
  54. Target: "65f1bf2",
  55. Title: "v0.1.3 is released",
  56. Note: "v0.1.3 is released",
  57. IsDraft: true,
  58. IsPrerelease: false,
  59. IsTag: false,
  60. }, nil))
  61. assert.NoError(t, CreateRelease(gitRepo, &Release{
  62. RepoID: repo.ID,
  63. PublisherID: user.ID,
  64. TagName: "v0.1.4",
  65. Target: "65f1bf2",
  66. Title: "v0.1.4 is released",
  67. Note: "v0.1.4 is released",
  68. IsDraft: false,
  69. IsPrerelease: true,
  70. IsTag: false,
  71. }, nil))
  72. assert.NoError(t, CreateRelease(gitRepo, &Release{
  73. RepoID: repo.ID,
  74. PublisherID: user.ID,
  75. TagName: "v0.1.5",
  76. Target: "65f1bf2",
  77. Title: "v0.1.5 is released",
  78. Note: "v0.1.5 is released",
  79. IsDraft: false,
  80. IsPrerelease: false,
  81. IsTag: true,
  82. }, nil))
  83. }
  84. func TestRelease_MirrorDelete(t *testing.T) {
  85. assert.NoError(t, PrepareTestDatabase())
  86. user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  87. repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
  88. repoPath := RepoPath(user.Name, repo.Name)
  89. migrationOptions := MigrateRepoOptions{
  90. Name: "test_mirror",
  91. Description: "Test mirror",
  92. IsPrivate: false,
  93. IsMirror: true,
  94. RemoteAddr: repoPath,
  95. Wiki: true,
  96. }
  97. mirror, err := MigrateRepository(user, user, migrationOptions)
  98. assert.NoError(t, err)
  99. gitRepo, err := git.OpenRepository(repoPath)
  100. assert.NoError(t, err)
  101. findOptions := FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
  102. initCount, err := GetReleaseCountByRepoID(mirror.ID, findOptions)
  103. assert.NoError(t, err)
  104. assert.NoError(t, CreateRelease(gitRepo, &Release{
  105. RepoID: repo.ID,
  106. PublisherID: user.ID,
  107. TagName: "v0.2",
  108. Target: "master",
  109. Title: "v0.2 is released",
  110. Note: "v0.2 is released",
  111. IsDraft: false,
  112. IsPrerelease: false,
  113. IsTag: true,
  114. }, nil))
  115. err = mirror.GetMirror()
  116. assert.NoError(t, err)
  117. _, ok := mirror.Mirror.runSync()
  118. assert.True(t, ok)
  119. count, err := GetReleaseCountByRepoID(mirror.ID, findOptions)
  120. assert.EqualValues(t, initCount+1, count)
  121. release, err := GetRelease(repo.ID, "v0.2")
  122. assert.NoError(t, err)
  123. assert.NoError(t, DeleteReleaseByID(release.ID, user, true))
  124. _, ok = mirror.Mirror.runSync()
  125. assert.True(t, ok)
  126. count, err = GetReleaseCountByRepoID(mirror.ID, findOptions)
  127. assert.EqualValues(t, initCount, count)
  128. }