@@ -40,7 +40,7 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
4040})
4141
4242ctx := context .Background ()
43- rules , _ , err := client .Repositories .GetRulesForBranch (ctx , "o" , "repo" , "branch" )
43+ rules , _ , err := client .Repositories .GetRulesForBranch (ctx , "o" , "repo" , "branch" , nil )
4444if err != nil {
4545t .Errorf ("Repositories.GetRulesForBranch returned error: %v" , err )
4646}
@@ -55,9 +55,56 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
5555}
5656
5757const methodName = "GetRulesForBranch"
58+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
59+ got , resp , err := client .Repositories .GetRulesForBranch (ctx , "o" , "repo" , "branch" , nil )
60+ if got != nil {
61+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
62+ }
63+ return resp , err
64+ })
65+ }
66+
67+ func TestRepositoriesService_GetRulesForBranch_ListOptions (t * testing.T ) {
68+ t .Parallel ()
69+ client , mux , _ := setup (t )
70+
71+ mux .HandleFunc ("/repos/o/repo/rules/branches/branch" , func (w http.ResponseWriter , r * http.Request ) {
72+ testMethod (t , r , "GET" )
73+ testFormValues (t , r , values {
74+ "page" : "2" ,
75+ "per_page" : "35" ,
76+ })
77+ fmt .Fprint (w , `[
78+ {
79+ "ruleset_id": 42069,
80+ "type": "creation"
81+ }
82+ ]` )
83+ })
84+
85+ opts := & ListOptions {Page : 2 , PerPage : 35 }
86+ ctx := context .Background ()
87+ rules , _ , err := client .Repositories .GetRulesForBranch (ctx , "o" , "repo" , "branch" , opts )
88+ if err != nil {
89+ t .Errorf ("Repositories.GetRulesForBranch returned error: %v" , err )
90+ }
91+
92+ want := & BranchRules {
93+ Creation : []* BranchRuleMetadata {{RulesetID : 42069 }},
94+ }
95+
96+ if ! cmp .Equal (rules , want ) {
97+ t .Errorf ("Repositories.GetRulesForBranch returned %+v, want %+v" , rules , want )
98+ }
99+
100+ const methodName = "GetRulesForBranch"
101+ testBadOptions (t , methodName , func () (err error ) {
102+ _ , _ , err = client .Repositories .GetRulesForBranch (ctx , "\n " , "\n " , "\n " , opts )
103+ return err
104+ })
58105
59106testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
60- got , resp , err := client .Repositories .GetRulesForBranch (ctx , "o" , "repo" , "branch" )
107+ got , resp , err := client .Repositories .GetRulesForBranch (ctx , "o" , "repo" , "branch" , opts )
61108if got != nil {
62109t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
63110}
@@ -94,7 +141,7 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {
94141})
95142
96143ctx := context .Background ()
97- ruleSet , _ , err := client .Repositories .GetAllRulesets (ctx , "o" , "repo" , false )
144+ ruleSet , _ , err := client .Repositories .GetAllRulesets (ctx , "o" , "repo" , nil )
98145if err != nil {
99146t .Errorf ("Repositories.GetAllRulesets returned error: %v" , err )
100147}
@@ -124,9 +171,63 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {
124171}
125172
126173const methodName = "GetAllRulesets"
174+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
175+ got , resp , err := client .Repositories .GetAllRulesets (ctx , "o" , "repo" , nil )
176+ if got != nil {
177+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
178+ }
179+ return resp , err
180+ })
181+ }
182+
183+ func TestRepositoriesService_GetAllRulesets_ListOptions (t * testing.T ) {
184+ t .Parallel ()
185+ client , mux , _ := setup (t )
186+
187+ mux .HandleFunc ("/repos/o/repo/rulesets" , func (w http.ResponseWriter , r * http.Request ) {
188+ testMethod (t , r , "GET" )
189+ testFormValues (t , r , values {
190+ "includes_parents" : "false" ,
191+ "page" : "2" ,
192+ "per_page" : "35" ,
193+ })
194+ fmt .Fprint (w , `[
195+ {
196+ "id": 42
197+ }
198+ ]` )
199+ })
200+
201+ opts := & RepositoryListRulesetsOptions {
202+ IncludesParents : Ptr (false ),
203+ ListOptions : ListOptions {
204+ Page : 2 ,
205+ PerPage : 35 ,
206+ },
207+ }
208+ ctx := context .Background ()
209+ ruleSet , _ , err := client .Repositories .GetAllRulesets (ctx , "o" , "repo" , opts )
210+ if err != nil {
211+ t .Errorf ("Repositories.GetAllRulesets returned error: %v" , err )
212+ }
213+
214+ want := []* RepositoryRuleset {
215+ {
216+ ID : Ptr (int64 (42 )),
217+ },
218+ }
219+ if ! cmp .Equal (ruleSet , want ) {
220+ t .Errorf ("Repositories.GetAllRulesets returned %+v, want %+v" , ruleSet , want )
221+ }
222+
223+ const methodName = "GetAllRulesets"
224+ testBadOptions (t , methodName , func () (err error ) {
225+ _ , _ , err = client .Repositories .GetAllRulesets (ctx , "\n " , "\n " , opts )
226+ return err
227+ })
127228
128229testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
129- got , resp , err := client .Repositories .GetAllRulesets (ctx , "o" , "repo" , false )
230+ got , resp , err := client .Repositories .GetAllRulesets (ctx , "o" , "repo" , opts )
130231if got != nil {
131232t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
132233}
0 commit comments