aboutsummaryrefslogtreecommitdiffstats
path: root/integrations/api_branch_test.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-04-19 04:38:09 +0200
committerGitHub <noreply@github.com>2020-04-19 10:38:09 +0800
commit3c5a4d094a572b446435ccf7ebf75836c2d98c57 (patch)
tree9b8e22a014004c4e008024de8b1697565cbac81a /integrations/api_branch_test.go
parent0ef11ff2c909d1775642fa03b09f1342fcaaeb69 (diff)
downloadgitea-3c5a4d094a572b446435ccf7ebf75836c2d98c57.tar.gz
gitea-3c5a4d094a572b446435ccf7ebf75836c2d98c57.zip
[API] Add branch delete (#11112)
* use same process as in routers/repo/branch.go/deleteBranch * make sure default branch can not be deleted * remove IsDefaultBranch from UI process - it is worth its own pull * permissions
Diffstat (limited to 'integrations/api_branch_test.go')
-rw-r--r--integrations/api_branch_test.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/integrations/api_branch_test.go b/integrations/api_branch_test.go
index b6452a6ab4..8417ab36c5 100644
--- a/integrations/api_branch_test.go
+++ b/integrations/api_branch_test.go
@@ -80,6 +80,13 @@ func testAPIDeleteBranchProtection(t *testing.T, branchName string, expectedHTTP
session.MakeRequest(t, req, expectedHTTPStatus)
}
+func testAPIDeleteBranch(t *testing.T, branchName string, expectedHTTPStatus int) {
+ session := loginUser(t, "user2")
+ token := getTokenForLoggedInUser(t, session)
+ req := NewRequestf(t, "DELETE", "/api/v1/repos/user2/repo1/branches/%s?token=%s", branchName, token)
+ session.MakeRequest(t, req, expectedHTTPStatus)
+}
+
func TestAPIGetBranch(t *testing.T) {
for _, test := range []struct {
BranchName string
@@ -106,10 +113,17 @@ func TestAPIBranchProtection(t *testing.T) {
// Can only create once
testAPICreateBranchProtection(t, "master", http.StatusForbidden)
+ // Can't delete a protected branch
+ testAPIDeleteBranch(t, "master", http.StatusForbidden)
+
testAPIGetBranchProtection(t, "master", http.StatusOK)
testAPIEditBranchProtection(t, "master", &api.BranchProtection{
EnablePush: true,
}, http.StatusOK)
testAPIDeleteBranchProtection(t, "master", http.StatusNoContent)
+
+ // Test branch deletion
+ testAPIDeleteBranch(t, "master", http.StatusForbidden)
+ testAPIDeleteBranch(t, "branch2", http.StatusNoContent)
}