A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
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.

53 lines
1.5 KiB

  1. // Copyright 2021 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. "github.com/stretchr/testify/assert"
  8. )
  9. func TestRepositoryTransfer(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. doer := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  12. repo := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
  13. transfer, err := GetPendingRepositoryTransfer(repo)
  14. assert.NoError(t, err)
  15. assert.NotNil(t, transfer)
  16. // Cancel transfer
  17. assert.NoError(t, CancelRepositoryTransfer(repo))
  18. transfer, err = GetPendingRepositoryTransfer(repo)
  19. assert.Error(t, err)
  20. assert.Nil(t, transfer)
  21. assert.True(t, IsErrNoPendingTransfer(err))
  22. user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  23. assert.NoError(t, CreatePendingRepositoryTransfer(doer, user2, repo.ID, nil))
  24. transfer, err = GetPendingRepositoryTransfer(repo)
  25. assert.Nil(t, err)
  26. assert.NoError(t, transfer.LoadAttributes())
  27. assert.Equal(t, "user2", transfer.Recipient.Name)
  28. user6 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  29. // Only transfer can be started at any given time
  30. err = CreatePendingRepositoryTransfer(doer, user6, repo.ID, nil)
  31. assert.Error(t, err)
  32. assert.True(t, IsErrRepoTransferInProgress(err))
  33. // Unknown user
  34. err = CreatePendingRepositoryTransfer(doer, &User{ID: 1000, LowerName: "user1000"}, repo.ID, nil)
  35. assert.Error(t, err)
  36. // Cancel transfer
  37. assert.NoError(t, CancelRepositoryTransfer(repo))
  38. }