forgejo-sdk/gitea/repo_transfer_test.go
Lunny Xiao 22f2853429 Use goproxy.io instead of goproxy.cn (#574)
Fix CI, Fix #572

Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/574
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2022-03-29 07:09:57 +08:00

39 lines
1.3 KiB
Go

// Copyright 2020 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 gitea
import (
"log"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRepoTransfer(t *testing.T) {
log.Printf("== TestRepoTransfer ==")
c := newTestClient()
org, _, err := c.AdminCreateOrg(c.username, CreateOrgOption{Name: "TransferOrg"})
assert.NoError(t, err)
repo, err := createTestRepo(t, "ToMove", c)
assert.NoError(t, err)
newRepo, _, err := c.TransferRepo(repo.Owner.UserName, repo.Name, TransferRepoOption{NewOwner: org.UserName})
assert.NoError(t, err) // admin transfer repository will execute immediately but not set as pendding.
assert.NotNil(t, newRepo)
assert.EqualValues(t, "ToMove", newRepo.Name)
repo, err = createTestRepo(t, "ToMove", c)
assert.NoError(t, err)
_, _, err = c.TransferRepo(repo.Owner.UserName, repo.Name, TransferRepoOption{NewOwner: org.UserName})
assert.Error(t, err, err.Error()) // org.UserName/repo.Name has exist
_, err = c.DeleteRepo(repo.Owner.UserName, repo.Name)
assert.NoError(t, err)
_, err = c.DeleteRepo(newRepo.Owner.UserName, newRepo.Name)
assert.Error(t, err)
_, err = c.DeleteOrg(org.UserName)
assert.NoError(t, err)
}