summaryrefslogtreecommitdiffstats
path: root/integrations/api_repo_test.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-01-31 16:49:04 +0100
committerGitHub <noreply@github.com>2020-01-31 15:49:04 +0000
commit13bc82009c2def4e729f11340e74a14d6c6b32e8 (patch)
treeb545d0af8fdebbddb79fee55b8e643c9f392ff49 /integrations/api_repo_test.go
parentd816f7018b0726f868fa0cddf02ffae184601395 (diff)
downloadgitea-13bc82009c2def4e729f11340e74a14d6c6b32e8.tar.gz
gitea-13bc82009c2def4e729f11340e74a14d6c6b32e8.zip
API endpoint for repo transfer (#9947)
* squash * optimize * fail before make any changes * fix-header
Diffstat (limited to 'integrations/api_repo_test.go')
-rw-r--r--integrations/api_repo_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go
index 6c3835788d..715fc629aa 100644
--- a/integrations/api_repo_test.go
+++ b/integrations/api_repo_test.go
@@ -392,3 +392,54 @@ func testAPIRepoCreateConflict(t *testing.T, u *url.URL) {
assert.Equal(t, respJSON["message"], "The repository with the same name already exists.")
})
}
+
+func TestAPIRepoTransfer(t *testing.T) {
+ testCases := []struct {
+ ctxUserID int64
+ newOwner string
+ teams *[]int64
+ expectedStatus int
+ }{
+ {ctxUserID: 1, newOwner: "user2", teams: nil, expectedStatus: http.StatusAccepted},
+ {ctxUserID: 2, newOwner: "user1", teams: nil, expectedStatus: http.StatusAccepted},
+ {ctxUserID: 2, newOwner: "user6", teams: nil, expectedStatus: http.StatusForbidden},
+ {ctxUserID: 1, newOwner: "user2", teams: &[]int64{2}, expectedStatus: http.StatusUnprocessableEntity},
+ {ctxUserID: 1, newOwner: "user3", teams: &[]int64{5}, expectedStatus: http.StatusForbidden},
+ {ctxUserID: 1, newOwner: "user3", teams: &[]int64{2}, expectedStatus: http.StatusAccepted},
+ }
+
+ defer prepareTestEnv(t)()
+
+ //create repo to move
+ user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ session := loginUser(t, user.Name)
+ token := getTokenForLoggedInUser(t, session)
+ repoName := "moveME"
+ repo := new(models.Repository)
+ req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/user/repos?token=%s", token), &api.CreateRepoOption{
+ Name: repoName,
+ Description: "repo move around",
+ Private: false,
+ Readme: "Default",
+ AutoInit: true,
+ })
+ resp := session.MakeRequest(t, req, http.StatusCreated)
+ DecodeJSON(t, resp, repo)
+
+ //start testing
+ for _, testCase := range testCases {
+ user = models.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
+ repo = models.AssertExistsAndLoadBean(t, &models.Repository{ID: repo.ID}).(*models.Repository)
+ session = loginUser(t, user.Name)
+ token = getTokenForLoggedInUser(t, session)
+ req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer?token=%s", repo.OwnerName, repo.Name, token), &api.TransferRepoOption{
+ NewOwner: testCase.newOwner,
+ TeamIDs: testCase.teams,
+ })
+ session.MakeRequest(t, req, testCase.expectedStatus)
+ }
+
+ //cleanup
+ repo = models.AssertExistsAndLoadBean(t, &models.Repository{ID: repo.ID}).(*models.Repository)
+ _ = models.DeleteRepository(user, repo.OwnerID, repo.ID)
+}