forgejo-sdk/gitea/repo_transfer_test.go
Gusted 603e4358f8 Fix CI tests (#579)
- `master` -> `main`, due to https://github.com/go-gitea/gitea/pull/19354
- Fix incorrect variable being passed into assert in `TestPull`.
- Fix `createTestRepo` to only delete existing TestRepo if the result's repo wasn't redirected(e.g. due to being transferred or renamed). Fixes the error in TransferRepo.
- Remove a check for tag verfication, for some developers this will always fail due to local git configs forcing signing on tags.

Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/579
Reviewed-by: 6543 <6543@obermui.de>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-committed-by: Gusted <williamzijl7@hotmail.com>
2022-04-22 15:52:45 +08:00

40 lines
1.2 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(c.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)
_, resp, err := c.TransferRepo(c.username, repo.Name, TransferRepoOption{NewOwner: org.UserName})
assert.EqualValues(t, 422, resp.StatusCode)
assert.Error(t, err)
_, err = c.DeleteRepo(repo.Owner.UserName, repo.Name)
assert.NoError(t, err)
_, err = c.DeleteRepo(newRepo.Owner.UserName, newRepo.Name)
assert.NoError(t, err)
_, err = c.DeleteOrg(org.UserName)
assert.NoError(t, err)
}