mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 03:33:09 +00:00
e81ccc406b
Change all license headers to comply with REUSE specification. Fix #16132 Co-authored-by: flynnnnnnnnnn <flynnnnnnnnnn@github> Co-authored-by: John Olheiser <john.olheiser@gmail.com>
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package models
|
|
|
|
import (
|
|
"testing"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRepositoryTransfer(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
|
|
|
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))
|
|
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
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)
|
|
|
|
user6 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
// 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_model.User{ID: 1000, LowerName: "user1000"}, repo.ID, nil)
|
|
assert.Error(t, err)
|
|
|
|
// Cancel transfer
|
|
assert.NoError(t, CancelRepositoryTransfer(repo))
|
|
}
|