@@ -187,26 +187,26 @@ func testAPICreateBranch(t testing.TB, session *TestSession, user, repo, oldBran
187
187
return resp .Result ().StatusCode == status
188
188
}
189
189
190
- func TestAPIUpdateBranch (t * testing.T ) {
190
+ func TestAPIRenameBranch (t * testing.T ) {
191
191
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 )
194
194
})
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 )
197
197
assert .Contains (t , resp .Body .String (), "Cannot rename a branch using the same name or rename to a branch that already exists." )
198
198
})
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 )
201
201
assert .Contains (t , resp .Body .String (), "Cannot rename a branch using the same name or rename to a branch that already exists." )
202
202
})
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 )
205
205
assert .Contains (t , resp .Body .String (), "Branch doesn't exist." )
206
206
})
207
- t .Run ("UpdateBranchWithNonAdminDoer " , func (t * testing.T ) {
207
+ t .Run ("RenameBranchWithNonAdminDoer " , func (t * testing.T ) {
208
208
// 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 )
210
210
assert .Contains (t , resp .Body .String (), "User must be a repo or site admin to rename default or protected branches." )
211
211
212
212
// don't allow protected branch renaming
@@ -216,10 +216,10 @@ func TestAPIUpdateBranch(t *testing.T) {
216
216
}).AddTokenAuth (token )
217
217
MakeRequest (t , req , http .StatusCreated )
218
218
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 )
220
220
assert .Contains (t , resp .Body .String (), "User must be a repo or site admin to rename default or protected branches." )
221
221
})
222
- t .Run ("UpdateBranchWithGlobedBasedProtectionRulesAndAdminAccess " , func (t * testing.T ) {
222
+ t .Run ("RenameBranchWithGlobedBasedProtectionRulesAndAdminAccess " , func (t * testing.T ) {
223
223
// don't allow branch that falls under glob-based protection rules to be renamed
224
224
token := getUserToken (t , "user2" , auth_model .AccessTokenScopeWriteRepository )
225
225
req := NewRequestWithJSON (t , "POST" , "/api/v1/repos/user2/repo1/branch_protections" , & api.BranchProtection {
@@ -234,18 +234,18 @@ func TestAPIUpdateBranch(t *testing.T) {
234
234
}).AddTokenAuth (token )
235
235
MakeRequest (t , req , http .StatusCreated )
236
236
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 )
238
238
assert .Contains (t , resp .Body .String (), "Branch is protected by glob-based protection rules." )
239
239
})
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 )
242
242
})
243
243
})
244
244
}
245
245
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 {
247
247
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 {
249
249
Name : to ,
250
250
}).AddTokenAuth (token )
251
251
return MakeRequest (t , req , expectedHTTPStatus )
0 commit comments