@@ -31,7 +31,7 @@ func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
31
31
assert .True (t , branch .UserCanMerge )
32
32
}
33
33
34
- func testAPIGetBranchProtection (t * testing.T , branchName string , expectedHTTPStatus int ) {
34
+ func testAPIGetBranchProtection (t * testing.T , branchName string , expectedHTTPStatus int ) * api. BranchProtection {
35
35
token := getUserToken (t , "user2" , auth_model .AccessTokenScopeReadRepository )
36
36
req := NewRequestf (t , "GET" , "/api/v1/repos/user2/repo1/branch_protections/%s?token=%s" , branchName , token )
37
37
resp := MakeRequest (t , req , expectedHTTPStatus )
@@ -40,7 +40,9 @@ func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPSta
40
40
var branchProtection api.BranchProtection
41
41
DecodeJSON (t , resp , & branchProtection )
42
42
assert .EqualValues (t , branchName , branchProtection .RuleName )
43
+ return & branchProtection
43
44
}
45
+ return nil
44
46
}
45
47
46
48
func testAPICreateBranchProtection (t * testing.T , branchName string , expectedHTTPStatus int ) {
@@ -186,6 +188,24 @@ func TestAPIBranchProtection(t *testing.T) {
186
188
EnablePush : true ,
187
189
}, http .StatusOK )
188
190
191
+ // enable status checks, require the "test1" check to pass
192
+ testAPIEditBranchProtection (t , "master" , & api.BranchProtection {
193
+ EnableStatusCheck : true ,
194
+ StatusCheckContexts : []string {"test1" },
195
+ }, http .StatusOK )
196
+ bp := testAPIGetBranchProtection (t , "master" , http .StatusOK )
197
+ assert .Equal (t , true , bp .EnableStatusCheck )
198
+ assert .Equal (t , []string {"test1" }, bp .StatusCheckContexts )
199
+
200
+ // disable status checks, clear the list of required checks
201
+ testAPIEditBranchProtection (t , "master" , & api.BranchProtection {
202
+ EnableStatusCheck : false ,
203
+ StatusCheckContexts : []string {},
204
+ }, http .StatusOK )
205
+ bp = testAPIGetBranchProtection (t , "master" , http .StatusOK )
206
+ assert .Equal (t , false , bp .EnableStatusCheck )
207
+ assert .Equal (t , []string {}, bp .StatusCheckContexts )
208
+
189
209
testAPIDeleteBranchProtection (t , "master" , http .StatusNoContent )
190
210
191
211
// Test branch deletion
0 commit comments