mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 18:06:38 +01:00 
			
		
		
		
	Implement update branch API (#32433)
Resolves #22526. Builds upon #23061. --------- Co-authored-by: sillyguodong <33891828+sillyguodong@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -5,6 +5,7 @@ package integration | ||||
|  | ||||
| import ( | ||||
| 	"net/http" | ||||
| 	"net/http/httptest" | ||||
| 	"net/url" | ||||
| 	"testing" | ||||
|  | ||||
| @@ -186,6 +187,37 @@ func testAPICreateBranch(t testing.TB, session *TestSession, user, repo, oldBran | ||||
| 	return resp.Result().StatusCode == status | ||||
| } | ||||
|  | ||||
| func TestAPIUpdateBranch(t *testing.T) { | ||||
| 	onGiteaRun(t, func(t *testing.T, _ *url.URL) { | ||||
| 		t.Run("UpdateBranchWithEmptyRepo", func(t *testing.T) { | ||||
| 			testAPIUpdateBranch(t, "user10", "repo6", "master", "test", http.StatusNotFound) | ||||
| 		}) | ||||
| 		t.Run("UpdateBranchWithSameBranchNames", func(t *testing.T) { | ||||
| 			resp := testAPIUpdateBranch(t, "user2", "repo1", "master", "master", http.StatusUnprocessableEntity) | ||||
| 			assert.Contains(t, resp.Body.String(), "Cannot rename a branch using the same name or rename to a branch that already exists.") | ||||
| 		}) | ||||
| 		t.Run("UpdateBranchThatAlreadyExists", func(t *testing.T) { | ||||
| 			resp := testAPIUpdateBranch(t, "user2", "repo1", "master", "branch2", http.StatusUnprocessableEntity) | ||||
| 			assert.Contains(t, resp.Body.String(), "Cannot rename a branch using the same name or rename to a branch that already exists.") | ||||
| 		}) | ||||
| 		t.Run("UpdateBranchWithNonExistentBranch", func(t *testing.T) { | ||||
| 			resp := testAPIUpdateBranch(t, "user2", "repo1", "i-dont-exist", "new-branch-name", http.StatusNotFound) | ||||
| 			assert.Contains(t, resp.Body.String(), "Branch doesn't exist.") | ||||
| 		}) | ||||
| 		t.Run("RenameBranchNormalScenario", func(t *testing.T) { | ||||
| 			testAPIUpdateBranch(t, "user2", "repo1", "branch2", "new-branch-name", http.StatusNoContent) | ||||
| 		}) | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func testAPIUpdateBranch(t *testing.T, ownerName, repoName, from, to string, expectedHTTPStatus int) *httptest.ResponseRecorder { | ||||
| 	token := getUserToken(t, ownerName, auth_model.AccessTokenScopeWriteRepository) | ||||
| 	req := NewRequestWithJSON(t, "PATCH", "api/v1/repos/"+ownerName+"/"+repoName+"/branches/"+from, &api.UpdateBranchRepoOption{ | ||||
| 		Name: to, | ||||
| 	}).AddTokenAuth(token) | ||||
| 	return MakeRequest(t, req, expectedHTTPStatus) | ||||
| } | ||||
|  | ||||
| func TestAPIBranchProtection(t *testing.T) { | ||||
| 	defer tests.PrepareTestEnv(t)() | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user