2021-03-01 06:17:30 +05:30
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-03-01 06:17:30 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepositoryTransfer(t *testing.T) {
|
2021-09-19 17:19:59 +05:30
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2021-03-01 06:17:30 +05:30
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
doer := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
|
2021-03-01 06:17:30 +05:30
|
|
|
|
|
|
|
transfer, err := GetPendingRepositoryTransfer(repo)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, transfer)
|
|
|
|
|
|
|
|
// Cancel transfer
|
|
|
|
assert.NoError(t, CancelRepositoryTransfer(repo))
|
|
|
|
|
|
|
|
transfer, err = GetPendingRepositoryTransfer(repo)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, transfer)
|
|
|
|
assert.True(t, IsErrNoPendingTransfer(err))
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
2021-03-01 06:17:30 +05:30
|
|
|
|
|
|
|
assert.NoError(t, CreatePendingRepositoryTransfer(doer, user2, repo.ID, nil))
|
|
|
|
|
|
|
|
transfer, err = GetPendingRepositoryTransfer(repo)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NoError(t, transfer.LoadAttributes())
|
|
|
|
assert.Equal(t, "user2", transfer.Recipient.Name)
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
user6 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
2021-03-01 06:17:30 +05:30
|
|
|
|
|
|
|
// Only transfer can be started at any given time
|
|
|
|
err = CreatePendingRepositoryTransfer(doer, user6, repo.ID, nil)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrRepoTransferInProgress(err))
|
|
|
|
|
|
|
|
// Unknown user
|
|
|
|
err = CreatePendingRepositoryTransfer(doer, &User{ID: 1000, LowerName: "user1000"}, repo.ID, nil)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
// Cancel transfer
|
|
|
|
assert.NoError(t, CancelRepositoryTransfer(repo))
|
|
|
|
}
|