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.

50 lines
1.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 repository
  5. import (
  6. "sync"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/notification"
  10. "code.gitea.io/gitea/modules/notification/action"
  11. "github.com/stretchr/testify/assert"
  12. "github.com/unknwon/com"
  13. )
  14. var notifySync sync.Once
  15. func registerNotifier() {
  16. notifySync.Do(func() {
  17. notification.RegisterNotifier(action.NewNotifier())
  18. })
  19. }
  20. func TestTransferOwnership(t *testing.T) {
  21. registerNotifier()
  22. assert.NoError(t, models.PrepareTestDatabase())
  23. doer := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
  24. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
  25. repo.Owner = models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
  26. assert.NoError(t, TransferOwnership(doer, "user2", repo))
  27. transferredRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
  28. assert.EqualValues(t, 2, transferredRepo.OwnerID)
  29. assert.False(t, com.IsExist(models.RepoPath("user3", "repo3")))
  30. assert.True(t, com.IsExist(models.RepoPath("user2", "repo3")))
  31. models.AssertExistsAndLoadBean(t, &models.Action{
  32. OpType: models.ActionTransferRepo,
  33. ActUserID: 2,
  34. RepoID: 3,
  35. Content: "user3/repo3",
  36. })
  37. models.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
  38. }