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.

93 lines
2.6 KiB

  1. // Copyright 2019 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 mirror
  5. import (
  6. "path/filepath"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/git"
  10. "code.gitea.io/gitea/modules/repository"
  11. "code.gitea.io/gitea/modules/structs"
  12. release_service "code.gitea.io/gitea/services/release"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func TestMain(m *testing.M) {
  16. models.MainTest(m, filepath.Join("..", ".."))
  17. }
  18. func TestRelease_MirrorDelete(t *testing.T) {
  19. assert.NoError(t, models.PrepareTestDatabase())
  20. user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
  21. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  22. repoPath := models.RepoPath(user.Name, repo.Name)
  23. opts := structs.MigrateRepoOption{
  24. RepoName: "test_mirror",
  25. Description: "Test mirror",
  26. Private: false,
  27. Mirror: true,
  28. CloneAddr: repoPath,
  29. Wiki: true,
  30. Releases: false,
  31. }
  32. mirrorRepo, err := repository.CreateRepository(user, user, models.CreateRepoOptions{
  33. Name: opts.RepoName,
  34. Description: opts.Description,
  35. IsPrivate: opts.Private,
  36. IsMirror: opts.Mirror,
  37. Status: models.RepositoryBeingMigrated,
  38. })
  39. assert.NoError(t, err)
  40. mirror, err := repository.MigrateRepositoryGitData(user, user, mirrorRepo, opts)
  41. assert.NoError(t, err)
  42. gitRepo, err := git.OpenRepository(repoPath)
  43. assert.NoError(t, err)
  44. defer gitRepo.Close()
  45. findOptions := models.FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
  46. initCount, err := models.GetReleaseCountByRepoID(mirror.ID, findOptions)
  47. assert.NoError(t, err)
  48. assert.NoError(t, release_service.CreateRelease(gitRepo, &models.Release{
  49. RepoID: repo.ID,
  50. PublisherID: user.ID,
  51. TagName: "v0.2",
  52. Target: "master",
  53. Title: "v0.2 is released",
  54. Note: "v0.2 is released",
  55. IsDraft: false,
  56. IsPrerelease: false,
  57. IsTag: true,
  58. }, nil))
  59. err = mirror.GetMirror()
  60. assert.NoError(t, err)
  61. _, ok := runSync(mirror.Mirror)
  62. assert.True(t, ok)
  63. count, err := models.GetReleaseCountByRepoID(mirror.ID, findOptions)
  64. assert.NoError(t, err)
  65. assert.EqualValues(t, initCount+1, count)
  66. release, err := models.GetRelease(repo.ID, "v0.2")
  67. assert.NoError(t, err)
  68. assert.NoError(t, release_service.DeleteReleaseByID(release.ID, user, true))
  69. _, ok = runSync(mirror.Mirror)
  70. assert.True(t, ok)
  71. count, err = models.GetReleaseCountByRepoID(mirror.ID, findOptions)
  72. assert.NoError(t, err)
  73. assert.EqualValues(t, initCount, count)
  74. }