@@ -86,7 +86,20 @@ func TestActionsService_CreateRequiredWorkflow(t *testing.T) {
86
86
testMethod (t , r , "PUT" )
87
87
testHeader (t , r , "Content-Type" , "application/json" )
88
88
testBody (t , r , `{"workflow_file_path":".github/workflows/ci.yaml","repository_id":53,"scope":"selected","selected_repository_ids":[32,91]}` + "\n " )
89
- w .WriteHeader (http .StatusCreated )
89
+ fmt .Fprint (w , `{
90
+ "id": 2,
91
+ "name": "Required CI",
92
+ "path": ".github/workflows/ci.yml",
93
+ "scope": "selected",
94
+ "ref": "refs/head/main",
95
+ "state": "active",
96
+ "selected_repositories_url": "https://api.github.com/orgs/octo-org/actions/required_workflows/2/repositories",
97
+ "created_at": "2020-01-22T19:33:08Z",
98
+ "updated_at": "2020-01-22T19:33:08Z",
99
+ "repository": {
100
+ "id": 53,
101
+ "name": "Hello-World",
102
+ "url": "https://api.github.com/repos/o/Hello-World"}}` )
90
103
})
91
104
input := & CreateUpdateRequiredWorkflowOptions {
92
105
WorkflowFilePath : String (".github/workflows/ci.yaml" ),
@@ -95,20 +108,39 @@ func TestActionsService_CreateRequiredWorkflow(t *testing.T) {
95
108
SelectedRepositoryIDs : & SelectedRepoIDs {32 , 91 },
96
109
}
97
110
ctx := context .Background ()
98
- _ , err := client .Actions .CreateRequiredWorkflow (ctx , "o" , input )
99
-
111
+ requiredWokflow , _ , err := client .Actions .CreateRequiredWorkflow (ctx , "o" , input )
100
112
if err != nil {
101
113
t .Errorf ("Actions.CreateRequiredWorkflow returned error: %v" , err )
102
114
}
115
+ want := & OrgRequiredWorkflow {
116
+ ID : Int64 (2 ),
117
+ Name : String ("Required CI" ),
118
+ Path : String (".github/workflows/ci.yml" ),
119
+ Scope : String ("selected" ),
120
+ Ref : String ("refs/head/main" ),
121
+ State : String ("active" ),
122
+ SelectedRepositoriesURL : String ("https://api.github.com/orgs/octo-org/actions/required_workflows/2/repositories" ),
123
+ CreatedAt : & Timestamp {time .Date (2020 , time .January , 22 , 19 , 33 , 8 , 0 , time .UTC )},
124
+ UpdatedAt : & Timestamp {time .Date (2020 , time .January , 22 , 19 , 33 , 8 , 0 , time .UTC )},
125
+ Repository : & Repository {ID : Int64 (53 ), URL : String ("https://api.github.com/repos/o/Hello-World" ), Name : String ("Hello-World" )},
126
+ }
127
+
128
+ if ! cmp .Equal (requiredWokflow , want ) {
129
+ t .Errorf ("Actions.CreateRequiredWorkflow returned %+v, want %+v" , requiredWokflow , want )
130
+ }
103
131
104
132
const methodName = "CreateRequiredWorkflow"
105
133
testBadOptions (t , methodName , func () (err error ) {
106
- _ , err = client .Actions .CreateRequiredWorkflow (ctx , "\n " , input )
134
+ _ , _ , err = client .Actions .CreateRequiredWorkflow (ctx , "\n " , input )
107
135
return err
108
136
})
109
137
110
138
testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
111
- return client .Actions .CreateRequiredWorkflow (ctx , "o" , input )
139
+ got , resp , err := client .Actions .CreateRequiredWorkflow (ctx , "o" , input )
140
+ if got != nil {
141
+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
142
+ }
143
+ return resp , err
112
144
})
113
145
}
114
146
@@ -169,7 +201,20 @@ func TestActionsService_UpdateRequiredWorkflow(t *testing.T) {
169
201
testMethod (t , r , "PATCH" )
170
202
testHeader (t , r , "Content-Type" , "application/json" )
171
203
testBody (t , r , `{"workflow_file_path":".github/workflows/ci.yaml","repository_id":53,"scope":"selected","selected_repository_ids":[32,91]}` + "\n " )
172
- w .WriteHeader (http .StatusOK )
204
+ fmt .Fprint (w , `{
205
+ "id": 12345,
206
+ "name": "Required CI",
207
+ "path": ".github/workflows/ci.yml",
208
+ "scope": "selected",
209
+ "ref": "refs/head/main",
210
+ "state": "active",
211
+ "selected_repositories_url": "https://api.github.com/orgs/octo-org/actions/required_workflows/12345/repositories",
212
+ "created_at": "2020-01-22T19:33:08Z",
213
+ "updated_at": "2020-01-22T19:33:08Z",
214
+ "repository": {
215
+ "id": 53,
216
+ "name": "Hello-World",
217
+ "url": "https://api.github.com/repos/o/Hello-World"}}` )
173
218
})
174
219
input := & CreateUpdateRequiredWorkflowOptions {
175
220
WorkflowFilePath : String (".github/workflows/ci.yaml" ),
@@ -178,20 +223,41 @@ func TestActionsService_UpdateRequiredWorkflow(t *testing.T) {
178
223
SelectedRepositoryIDs : & SelectedRepoIDs {32 , 91 },
179
224
}
180
225
ctx := context .Background ()
181
- _ , err := client .Actions .UpdateRequiredWorkflow (ctx , "o" , 12345 , input )
226
+
227
+ requiredWokflow , _ , err := client .Actions .UpdateRequiredWorkflow (ctx , "o" , 12345 , input )
182
228
183
229
if err != nil {
184
230
t .Errorf ("Actions.UpdateRequiredWorkflow returned error: %v" , err )
185
231
}
232
+ want := & OrgRequiredWorkflow {
233
+ ID : Int64 (12345 ),
234
+ Name : String ("Required CI" ),
235
+ Path : String (".github/workflows/ci.yml" ),
236
+ Scope : String ("selected" ),
237
+ Ref : String ("refs/head/main" ),
238
+ State : String ("active" ),
239
+ SelectedRepositoriesURL : String ("https://api.github.com/orgs/octo-org/actions/required_workflows/12345/repositories" ),
240
+ CreatedAt : & Timestamp {time .Date (2020 , time .January , 22 , 19 , 33 , 8 , 0 , time .UTC )},
241
+ UpdatedAt : & Timestamp {time .Date (2020 , time .January , 22 , 19 , 33 , 8 , 0 , time .UTC )},
242
+ Repository : & Repository {ID : Int64 (53 ), URL : String ("https://api.github.com/repos/o/Hello-World" ), Name : String ("Hello-World" )},
243
+ }
244
+
245
+ if ! cmp .Equal (requiredWokflow , want ) {
246
+ t .Errorf ("Actions.UpdateRequiredWorkflow returned %+v, want %+v" , requiredWokflow , want )
247
+ }
186
248
187
249
const methodName = "UpdateRequiredWorkflow"
188
250
testBadOptions (t , methodName , func () (err error ) {
189
- _ , err = client .Actions .UpdateRequiredWorkflow (ctx , "\n " , 12345 , input )
251
+ _ , _ , err = client .Actions .UpdateRequiredWorkflow (ctx , "\n " , 12345 , input )
190
252
return err
191
253
})
192
254
193
255
testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
194
- return client .Actions .UpdateRequiredWorkflow (ctx , "o" , 12345 , input )
256
+ got , resp , err := client .Actions .UpdateRequiredWorkflow (ctx , "o" , 12345 , input )
257
+ if got != nil {
258
+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
259
+ }
260
+ return resp , err
195
261
})
196
262
}
197
263
0 commit comments