|
|
|
|
|
|
|
|
assert.True(t, branch.UserCanMerge) |
|
|
assert.True(t, branch.UserCanMerge) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) { |
|
|
|
|
|
|
|
|
func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) *api.BranchProtection { |
|
|
token := getUserToken(t, "user2", auth_model.AccessTokenScopeReadRepository) |
|
|
token := getUserToken(t, "user2", auth_model.AccessTokenScopeReadRepository) |
|
|
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branch_protections/%s?token=%s", branchName, token) |
|
|
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branch_protections/%s?token=%s", branchName, token) |
|
|
resp := MakeRequest(t, req, expectedHTTPStatus) |
|
|
resp := MakeRequest(t, req, expectedHTTPStatus) |
|
|
|
|
|
|
|
|
var branchProtection api.BranchProtection |
|
|
var branchProtection api.BranchProtection |
|
|
DecodeJSON(t, resp, &branchProtection) |
|
|
DecodeJSON(t, resp, &branchProtection) |
|
|
assert.EqualValues(t, branchName, branchProtection.RuleName) |
|
|
assert.EqualValues(t, branchName, branchProtection.RuleName) |
|
|
|
|
|
return &branchProtection |
|
|
} |
|
|
} |
|
|
|
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func testAPICreateBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) { |
|
|
func testAPICreateBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) { |
|
|
|
|
|
|
|
|
EnablePush: true, |
|
|
EnablePush: true, |
|
|
}, http.StatusOK) |
|
|
}, http.StatusOK) |
|
|
|
|
|
|
|
|
|
|
|
// enable status checks, require the "test1" check to pass |
|
|
|
|
|
testAPIEditBranchProtection(t, "master", &api.BranchProtection{ |
|
|
|
|
|
EnableStatusCheck: true, |
|
|
|
|
|
StatusCheckContexts: []string{"test1"}, |
|
|
|
|
|
}, http.StatusOK) |
|
|
|
|
|
bp := testAPIGetBranchProtection(t, "master", http.StatusOK) |
|
|
|
|
|
assert.Equal(t, true, bp.EnableStatusCheck) |
|
|
|
|
|
assert.Equal(t, []string{"test1"}, bp.StatusCheckContexts) |
|
|
|
|
|
|
|
|
|
|
|
// disable status checks, clear the list of required checks |
|
|
|
|
|
testAPIEditBranchProtection(t, "master", &api.BranchProtection{ |
|
|
|
|
|
EnableStatusCheck: false, |
|
|
|
|
|
StatusCheckContexts: []string{}, |
|
|
|
|
|
}, http.StatusOK) |
|
|
|
|
|
bp = testAPIGetBranchProtection(t, "master", http.StatusOK) |
|
|
|
|
|
assert.Equal(t, false, bp.EnableStatusCheck) |
|
|
|
|
|
assert.Equal(t, []string{}, bp.StatusCheckContexts) |
|
|
|
|
|
|
|
|
testAPIDeleteBranchProtection(t, "master", http.StatusNoContent) |
|
|
testAPIDeleteBranchProtection(t, "master", http.StatusNoContent) |
|
|
|
|
|
|
|
|
// Test branch deletion |
|
|
// Test branch deletion |