@@ -40,7 +40,7 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
40
40
})
41
41
42
42
ctx := context .Background ()
43
- rules , _ , err := client .Repositories .GetRulesForBranch (ctx , "o" , "repo" , "branch" )
43
+ rules , _ , err := client .Repositories .GetRulesForBranch (ctx , "o" , "repo" , "branch" , nil )
44
44
if err != nil {
45
45
t .Errorf ("Repositories.GetRulesForBranch returned error: %v" , err )
46
46
}
@@ -55,9 +55,56 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
55
55
}
56
56
57
57
const 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
+ })
58
105
59
106
testNewRequestAndDoFailure (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 )
61
108
if got != nil {
62
109
t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
63
110
}
@@ -94,7 +141,7 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {
94
141
})
95
142
96
143
ctx := context .Background ()
97
- ruleSet , _ , err := client .Repositories .GetAllRulesets (ctx , "o" , "repo" , false )
144
+ ruleSet , _ , err := client .Repositories .GetAllRulesets (ctx , "o" , "repo" , nil )
98
145
if err != nil {
99
146
t .Errorf ("Repositories.GetAllRulesets returned error: %v" , err )
100
147
}
@@ -124,9 +171,63 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {
124
171
}
125
172
126
173
const 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
+ })
127
228
128
229
testNewRequestAndDoFailure (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 )
130
231
if got != nil {
131
232
t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
132
233
}
0 commit comments