2024-02-23 00:26:49 +00:00
|
|
|
// Copyright 2024 The Forgjo Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-02-04 08:04:44 +00:00
|
|
|
// 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.
|
|
|
|
|
2024-02-23 00:26:49 +00:00
|
|
|
package forgejo
|
2020-02-04 08:04:44 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepoTransfer(t *testing.T) {
|
|
|
|
log.Printf("== TestRepoTransfer ==")
|
|
|
|
c := newTestClient()
|
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
org, _, err := c.AdminCreateOrg(c.username, CreateOrgOption{Name: "TransferOrg"})
|
2020-02-04 08:04:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
repo, err := createTestRepo(t, "ToMove", c)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-22 08:52:45 +01:00
|
|
|
newRepo, _, err := c.TransferRepo(c.username, repo.Name, TransferRepoOption{NewOwner: org.UserName})
|
2022-03-29 00:09:57 +01:00
|
|
|
assert.NoError(t, err) // admin transfer repository will execute immediately but not set as pendding.
|
2020-02-04 08:04:44 +00:00
|
|
|
assert.NotNil(t, newRepo)
|
2022-03-29 00:09:57 +01:00
|
|
|
assert.EqualValues(t, "ToMove", newRepo.Name)
|
2020-02-04 08:04:44 +00:00
|
|
|
|
|
|
|
repo, err = createTestRepo(t, "ToMove", c)
|
|
|
|
assert.NoError(t, err)
|
2022-04-22 08:52:45 +01:00
|
|
|
_, resp, err := c.TransferRepo(c.username, repo.Name, TransferRepoOption{NewOwner: org.UserName})
|
|
|
|
assert.EqualValues(t, 422, resp.StatusCode)
|
|
|
|
assert.Error(t, err)
|
2020-02-04 08:04:44 +00:00
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.DeleteRepo(repo.Owner.UserName, repo.Name)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
_, err = c.DeleteRepo(newRepo.Owner.UserName, newRepo.Name)
|
2022-04-22 08:52:45 +01:00
|
|
|
assert.NoError(t, err)
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.DeleteOrg(org.UserName)
|
|
|
|
assert.NoError(t, err)
|
2020-02-04 08:04:44 +00:00
|
|
|
}
|