aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKemal Zebari <60799661+kemzeb@users.noreply.github.com>2024-12-11 21:02:35 -0800
committerGitHub <noreply@github.com>2024-12-12 05:02:35 +0000
commit01b1896bf5eacfd7f4f64d9ebb0ad165e3e60a5c (patch)
treeca50b20d23874de2505c885f4e4f5eff820e816b /tests
parent1e751d81b321c07f14ad25e034bf87a1e060e5ef (diff)
downloadgitea-01b1896bf5eacfd7f4f64d9ebb0ad165e3e60a5c.tar.gz
gitea-01b1896bf5eacfd7f4f64d9ebb0ad165e3e60a5c.zip
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_branch_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/integration/api_branch_test.go b/tests/integration/api_branch_test.go
index 8e49516aa7..24a041de17 100644
--- a/tests/integration/api_branch_test.go
+++ b/tests/integration/api_branch_test.go
@@ -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)()