@@ -187,26 +187,26 @@ func testAPICreateBranch(t testing.TB, session *TestSession, user, repo, oldBran
187187 return resp .Result ().StatusCode == status
188188}
189189
190- func TestAPIUpdateBranch (t * testing.T ) {
190+ func TestAPIRenameBranch (t * testing.T ) {
191191 onGiteaRun (t , func (t * testing.T , _ * url.URL ) {
192- t .Run ("UpdateBranchWithEmptyRepo " , func (t * testing.T ) {
193- testAPIUpdateBranch (t , "user10" , "user10" , "repo6" , "master" , "test" , http .StatusNotFound )
192+ t .Run ("RenameBranchWithEmptyRepo " , func (t * testing.T ) {
193+ testAPIRenameBranch (t , "user10" , "user10" , "repo6" , "master" , "test" , http .StatusNotFound )
194194 })
195- t .Run ("UpdateBranchWithSameBranchNames " , func (t * testing.T ) {
196- resp := testAPIUpdateBranch (t , "user2" , "user2" , "repo1" , "master" , "master" , http .StatusUnprocessableEntity )
195+ t .Run ("RenameBranchWithSameBranchNames " , func (t * testing.T ) {
196+ resp := testAPIRenameBranch (t , "user2" , "user2" , "repo1" , "master" , "master" , http .StatusUnprocessableEntity )
197197 assert .Contains (t , resp .Body .String (), "Cannot rename a branch using the same name or rename to a branch that already exists." )
198198 })
199- t .Run ("UpdateBranchThatAlreadyExists " , func (t * testing.T ) {
200- resp := testAPIUpdateBranch (t , "user2" , "user2" , "repo1" , "master" , "branch2" , http .StatusUnprocessableEntity )
199+ t .Run ("RenameBranchThatAlreadyExists " , func (t * testing.T ) {
200+ resp := testAPIRenameBranch (t , "user2" , "user2" , "repo1" , "master" , "branch2" , http .StatusUnprocessableEntity )
201201 assert .Contains (t , resp .Body .String (), "Cannot rename a branch using the same name or rename to a branch that already exists." )
202202 })
203- t .Run ("UpdateBranchWithNonExistentBranch " , func (t * testing.T ) {
204- resp := testAPIUpdateBranch (t , "user2" , "user2" , "repo1" , "i-dont-exist" , "new-branch-name" , http .StatusNotFound )
203+ t .Run ("RenameBranchWithNonExistentBranch " , func (t * testing.T ) {
204+ resp := testAPIRenameBranch (t , "user2" , "user2" , "repo1" , "i-dont-exist" , "new-branch-name" , http .StatusNotFound )
205205 assert .Contains (t , resp .Body .String (), "Branch doesn't exist." )
206206 })
207- t .Run ("UpdateBranchWithNonAdminDoer " , func (t * testing.T ) {
207+ t .Run ("RenameBranchWithNonAdminDoer " , func (t * testing.T ) {
208208 // don't allow default branch renaming
209- resp := testAPIUpdateBranch (t , "user40" , "user2" , "repo1" , "master" , "new-branch-name" , http .StatusForbidden )
209+ resp := testAPIRenameBranch (t , "user40" , "user2" , "repo1" , "master" , "new-branch-name" , http .StatusForbidden )
210210 assert .Contains (t , resp .Body .String (), "User must be a repo or site admin to rename default or protected branches." )
211211
212212 // don't allow protected branch renaming
@@ -216,10 +216,10 @@ func TestAPIUpdateBranch(t *testing.T) {
216216 }).AddTokenAuth (token )
217217 MakeRequest (t , req , http .StatusCreated )
218218 testAPICreateBranchProtection (t , "protected-branch" , 1 , http .StatusCreated )
219- resp = testAPIUpdateBranch (t , "user40" , "user2" , "repo1" , "protected-branch" , "new-branch-name" , http .StatusForbidden )
219+ resp = testAPIRenameBranch (t , "user40" , "user2" , "repo1" , "protected-branch" , "new-branch-name" , http .StatusForbidden )
220220 assert .Contains (t , resp .Body .String (), "User must be a repo or site admin to rename default or protected branches." )
221221 })
222- t .Run ("UpdateBranchWithGlobedBasedProtectionRulesAndAdminAccess " , func (t * testing.T ) {
222+ t .Run ("RenameBranchWithGlobedBasedProtectionRulesAndAdminAccess " , func (t * testing.T ) {
223223 // don't allow branch that falls under glob-based protection rules to be renamed
224224 token := getUserToken (t , "user2" , auth_model .AccessTokenScopeWriteRepository )
225225 req := NewRequestWithJSON (t , "POST" , "/api/v1/repos/user2/repo1/branch_protections" , & api.BranchProtection {
@@ -234,18 +234,18 @@ func TestAPIUpdateBranch(t *testing.T) {
234234 }).AddTokenAuth (token )
235235 MakeRequest (t , req , http .StatusCreated )
236236
237- resp := testAPIUpdateBranch (t , "user2" , "user2" , "repo1" , from , "new-branch-name" , http .StatusForbidden )
237+ resp := testAPIRenameBranch (t , "user2" , "user2" , "repo1" , from , "new-branch-name" , http .StatusForbidden )
238238 assert .Contains (t , resp .Body .String (), "Branch is protected by glob-based protection rules." )
239239 })
240- t .Run ("UpdateBranchNormalScenario " , func (t * testing.T ) {
241- testAPIUpdateBranch (t , "user2" , "user2" , "repo1" , "branch2" , "new-branch-name" , http .StatusNoContent )
240+ t .Run ("RenameBranchNormalScenario " , func (t * testing.T ) {
241+ testAPIRenameBranch (t , "user2" , "user2" , "repo1" , "branch2" , "new-branch-name" , http .StatusNoContent )
242242 })
243243 })
244244}
245245
246- func testAPIUpdateBranch (t * testing.T , doerName , ownerName , repoName , from , to string , expectedHTTPStatus int ) * httptest.ResponseRecorder {
246+ func testAPIRenameBranch (t * testing.T , doerName , ownerName , repoName , from , to string , expectedHTTPStatus int ) * httptest.ResponseRecorder {
247247 token := getUserToken (t , doerName , auth_model .AccessTokenScopeWriteRepository )
248- req := NewRequestWithJSON (t , "PATCH" , "api/v1/repos/" + ownerName + "/" + repoName + "/branches/" + from , & api.UpdateBranchRepoOption {
248+ req := NewRequestWithJSON (t , "PATCH" , "api/v1/repos/" + ownerName + "/" + repoName + "/branches/" + from , & api.RenameBranchRepoOption {
249249 Name : to ,
250250 }).AddTokenAuth (token )
251251 return MakeRequest (t , req , expectedHTTPStatus )
0 commit comments