Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Jan 11, 2025
1 parent 79a6bab commit b2c24a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 14 additions & 0 deletions models/repo/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,25 @@ func CreatePendingRepositoryTransfer(ctx context.Context, doer, newOwner *user_m
return err
}

if _, err := user_model.GetUserByID(ctx, newOwner.ID); err != nil {
return err
}

// Make sure repo is ready to transfer
if err := TestRepositoryReadyForTransfer(repo.Status); err != nil {
return err
}

_, err = GetPendingRepositoryTransfer(ctx, repo)
if err == nil {
return ErrRepoTransferInProgress{
Uname: repo.Owner.LowerName,
Name: repo.Name,
}
} else if !IsErrNoPendingTransfer(err) {
return err
}

repo.Status = RepositoryPendingTransfer
if err := UpdateRepositoryCols(ctx, repo, "status"); err != nil {
return err
Expand Down
16 changes: 9 additions & 7 deletions services/repository/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ func TestTransferOwnership(t *testing.T) {
func TestStartRepositoryTransferSetPermission(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
recipient := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
assert.NoError(t, repo.LoadOwner(db.DefaultContext))

hasAccess, err := access_model.HasAnyUnitAccess(db.DefaultContext, recipient.ID, repo)
assert.NoError(t, err)
Expand All @@ -85,7 +85,7 @@ func TestStartRepositoryTransferSetPermission(t *testing.T) {
func TestRepositoryTransfer(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})

transfer, err := repo_model.GetPendingRepositoryTransfer(db.DefaultContext, repo)
Expand Down Expand Up @@ -116,10 +116,12 @@ func TestRepositoryTransfer(t *testing.T) {
assert.Error(t, err)
assert.True(t, repo_model.IsErrRepoTransferInProgress(err))

// Unknown user
err = repo_model.CreatePendingRepositoryTransfer(db.DefaultContext, doer, &user_model.User{ID: 1000, LowerName: "user1000"}, repo.ID, nil)
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
// Unknown user, transfer non-existent transfer repo id = 2
err = repo_model.CreatePendingRepositoryTransfer(db.DefaultContext, doer, &user_model.User{ID: 1000, LowerName: "user1000"}, repo2.ID, nil)
assert.Error(t, err)

// Cancel transfer
assert.NoError(t, RejectRepositoryTransfer(db.DefaultContext, repo, doer))
err = RejectRepositoryTransfer(db.DefaultContext, repo2, doer)
assert.True(t, repo_model.IsErrNoPendingTransfer(err))
}

0 comments on commit b2c24a7

Please sign in to comment.