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.

151 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/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. }
  96. mirror, err := MigrateRepository(user, user, migrationOptions)
  97. assert.NoError(t, err)
  98. gitRepo, err := git.OpenRepository(repoPath)
  99. assert.NoError(t, err)
  100. findOptions := FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
  101. initCount, err := GetReleaseCountByRepoID(mirror.ID, findOptions)
  102. assert.NoError(t, err)
  103. assert.NoError(t, CreateRelease(gitRepo, &Release{
  104. RepoID: repo.ID,
  105. PublisherID: user.ID,
  106. TagName: "v0.2",
  107. Target: "master",
  108. Title: "v0.2 is released",
  109. Note: "v0.2 is released",
  110. IsDraft: false,
  111. IsPrerelease: false,
  112. IsTag: true,
  113. }, nil))
  114. err = mirror.GetMirror()
  115. assert.NoError(t, err)
  116. _, ok := mirror.Mirror.runSync()
  117. assert.True(t, ok)
  118. count, err := GetReleaseCountByRepoID(mirror.ID, findOptions)
  119. assert.EqualValues(t, initCount+1, count)
  120. release, err := GetRelease(repo.ID, "v0.2")
  121. assert.NoError(t, err)
  122. assert.NoError(t, DeleteReleaseByID(release.ID, user, true))
  123. _, ok = mirror.Mirror.runSync()
  124. assert.True(t, ok)
  125. count, err = GetReleaseCountByRepoID(mirror.ID, findOptions)
  126. assert.EqualValues(t, initCount, count)
  127. }