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.

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