1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 "net/http"
12 "net/url"
13 "testing"
14 "time"
15
16 "github.com/google/go-cmp/cmp"
17 )
18
19 func TestActionsService_ListWorkflowRunsByID(t *testing.T) {
20 client, mux, _, teardown := setup()
21 defer teardown()
22
23 mux.HandleFunc("/repos/o/r/actions/workflows/29679449/runs", func(w http.ResponseWriter, r *http.Request) {
24 testMethod(t, r, "GET")
25 testFormValues(t, r, values{"per_page": "2", "page": "2"})
26 fmt.Fprint(w, `{"total_count":4,"workflow_runs":[{"id":399444496,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`)
27 })
28
29 opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}}
30 ctx := context.Background()
31 runs, _, err := client.Actions.ListWorkflowRunsByID(ctx, "o", "r", 29679449, opts)
32 if err != nil {
33 t.Errorf("Actions.ListWorkFlowRunsByID returned error: %v", err)
34 }
35
36 want := &WorkflowRuns{
37 TotalCount: Int(4),
38 WorkflowRuns: []*WorkflowRun{
39 {ID: Int64(399444496), RunNumber: Int(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
40 {ID: Int64(399444497), RunNumber: Int(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
41 },
42 }
43 if !cmp.Equal(runs, want) {
44 t.Errorf("Actions.ListWorkflowRunsByID returned %+v, want %+v", runs, want)
45 }
46
47 const methodName = "ListWorkflowRunsByID"
48 testBadOptions(t, methodName, func() (err error) {
49 _, _, err = client.Actions.ListWorkflowRunsByID(ctx, "\n", "\n", 29679449, opts)
50 return err
51 })
52
53 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
54 got, resp, err := client.Actions.ListWorkflowRunsByID(ctx, "o", "r", 29679449, opts)
55 if got != nil {
56 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
57 }
58 return resp, err
59 })
60 }
61
62 func TestActionsService_ListWorkflowRunsFileName(t *testing.T) {
63 client, mux, _, teardown := setup()
64 defer teardown()
65
66 mux.HandleFunc("/repos/o/r/actions/workflows/29679449/runs", func(w http.ResponseWriter, r *http.Request) {
67 testMethod(t, r, "GET")
68 testFormValues(t, r, values{"per_page": "2", "page": "2"})
69 fmt.Fprint(w, `{"total_count":4,"workflow_runs":[{"id":399444496,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`)
70 })
71
72 opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}}
73 ctx := context.Background()
74 runs, _, err := client.Actions.ListWorkflowRunsByFileName(ctx, "o", "r", "29679449", opts)
75 if err != nil {
76 t.Errorf("Actions.ListWorkFlowRunsByFileName returned error: %v", err)
77 }
78
79 want := &WorkflowRuns{
80 TotalCount: Int(4),
81 WorkflowRuns: []*WorkflowRun{
82 {ID: Int64(399444496), RunNumber: Int(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
83 {ID: Int64(399444497), RunNumber: Int(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
84 },
85 }
86 if !cmp.Equal(runs, want) {
87 t.Errorf("Actions.ListWorkflowRunsByFileName returned %+v, want %+v", runs, want)
88 }
89
90 const methodName = "ListWorkflowRunsByFileName"
91 testBadOptions(t, methodName, func() (err error) {
92 _, _, err = client.Actions.ListWorkflowRunsByFileName(ctx, "\n", "\n", "29679449", opts)
93 return err
94 })
95
96 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
97 got, resp, err := client.Actions.ListWorkflowRunsByFileName(ctx, "o", "r", "29679449", opts)
98 if got != nil {
99 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
100 }
101 return resp, err
102 })
103 }
104
105 func TestActionsService_GetWorkflowRunByID(t *testing.T) {
106 client, mux, _, teardown := setup()
107 defer teardown()
108
109 mux.HandleFunc("/repos/o/r/actions/runs/29679449", func(w http.ResponseWriter, r *http.Request) {
110 testMethod(t, r, "GET")
111 fmt.Fprint(w, `{"id":399444496,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}}`)
112 })
113
114 ctx := context.Background()
115 runs, _, err := client.Actions.GetWorkflowRunByID(ctx, "o", "r", 29679449)
116 if err != nil {
117 t.Errorf("Actions.GetWorkflowRunByID returned error: %v", err)
118 }
119
120 want := &WorkflowRun{
121 ID: Int64(399444496),
122 RunNumber: Int(296),
123 CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)},
124 UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)},
125 }
126
127 if !cmp.Equal(runs, want) {
128 t.Errorf("Actions.GetWorkflowRunByID returned %+v, want %+v", runs, want)
129 }
130
131 const methodName = "GetWorkflowRunByID"
132 testBadOptions(t, methodName, func() (err error) {
133 _, _, err = client.Actions.GetWorkflowRunByID(ctx, "\n", "\n", 29679449)
134 return err
135 })
136
137 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
138 got, resp, err := client.Actions.GetWorkflowRunByID(ctx, "o", "r", 29679449)
139 if got != nil {
140 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
141 }
142 return resp, err
143 })
144 }
145
146 func TestActionsService_GetWorkflowRunAttempt(t *testing.T) {
147 client, mux, _, teardown := setup()
148 defer teardown()
149
150 mux.HandleFunc("/repos/o/r/actions/runs/29679449/attempts/3", func(w http.ResponseWriter, r *http.Request) {
151 testMethod(t, r, "GET")
152 testFormValues(t, r, values{"exclude_pull_requests": "true"})
153 fmt.Fprint(w, `{"id":399444496,"run_number":296,"run_attempt":3,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}}`)
154 })
155
156 opts := &WorkflowRunAttemptOptions{ExcludePullRequests: Bool(true)}
157 ctx := context.Background()
158 runs, _, err := client.Actions.GetWorkflowRunAttempt(ctx, "o", "r", 29679449, 3, opts)
159 if err != nil {
160 t.Errorf("Actions.GetWorkflowRunAttempt returned error: %v", err)
161 }
162
163 want := &WorkflowRun{
164 ID: Int64(399444496),
165 RunNumber: Int(296),
166 RunAttempt: Int(3),
167 CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)},
168 UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)},
169 }
170
171 if !cmp.Equal(runs, want) {
172 t.Errorf("Actions.GetWorkflowRunAttempt returned %+v, want %+v", runs, want)
173 }
174
175 const methodName = "GetWorkflowRunAttempt"
176 testBadOptions(t, methodName, func() (err error) {
177 _, _, err = client.Actions.GetWorkflowRunAttempt(ctx, "\n", "\n", 29679449, 3, opts)
178 return err
179 })
180
181 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
182 got, resp, err := client.Actions.GetWorkflowRunAttempt(ctx, "o", "r", 29679449, 3, opts)
183 if got != nil {
184 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
185 }
186 return resp, err
187 })
188 }
189
190 func TestActionsService_RerunWorkflowRunByID(t *testing.T) {
191 client, mux, _, teardown := setup()
192 defer teardown()
193
194 mux.HandleFunc("/repos/o/r/actions/runs/3434/rerun", func(w http.ResponseWriter, r *http.Request) {
195 testMethod(t, r, "POST")
196 w.WriteHeader(http.StatusCreated)
197 })
198
199 ctx := context.Background()
200 resp, err := client.Actions.RerunWorkflowByID(ctx, "o", "r", 3434)
201 if err != nil {
202 t.Errorf("Actions.RerunWorkflowByID returned error: %v", err)
203 }
204 if resp.StatusCode != http.StatusCreated {
205 t.Errorf("Actions.RerunWorkflowRunByID returned status: %d, want %d", resp.StatusCode, http.StatusCreated)
206 }
207
208 const methodName = "RerunWorkflowByID"
209 testBadOptions(t, methodName, func() (err error) {
210 _, err = client.Actions.RerunWorkflowByID(ctx, "\n", "\n", 3434)
211 return err
212 })
213
214 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
215 return client.Actions.RerunWorkflowByID(ctx, "o", "r", 3434)
216 })
217 }
218
219 func TestActionsService_RerunFailedJobsByID(t *testing.T) {
220 client, mux, _, teardown := setup()
221 defer teardown()
222
223 mux.HandleFunc("/repos/o/r/actions/runs/3434/rerun-failed-jobs", func(w http.ResponseWriter, r *http.Request) {
224 testMethod(t, r, "POST")
225 w.WriteHeader(http.StatusCreated)
226 })
227
228 ctx := context.Background()
229 resp, err := client.Actions.RerunFailedJobsByID(ctx, "o", "r", 3434)
230 if err != nil {
231 t.Errorf("Actions.RerunFailedJobsByID returned error: %v", err)
232 }
233 if resp.StatusCode != http.StatusCreated {
234 t.Errorf("Actions.RerunFailedJobsByID returned status: %d, want %d", resp.StatusCode, http.StatusCreated)
235 }
236
237 const methodName = "RerunFailedJobsByID"
238 testBadOptions(t, methodName, func() (err error) {
239 _, err = client.Actions.RerunFailedJobsByID(ctx, "\n", "\n", 3434)
240 return err
241 })
242
243 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
244 return client.Actions.RerunFailedJobsByID(ctx, "o", "r", 3434)
245 })
246 }
247
248 func TestActionsService_RerunJobByID(t *testing.T) {
249 client, mux, _, teardown := setup()
250 defer teardown()
251
252 mux.HandleFunc("/repos/o/r/actions/jobs/3434/rerun", func(w http.ResponseWriter, r *http.Request) {
253 testMethod(t, r, "POST")
254 w.WriteHeader(http.StatusCreated)
255 })
256
257 ctx := context.Background()
258 resp, err := client.Actions.RerunJobByID(ctx, "o", "r", 3434)
259 if err != nil {
260 t.Errorf("Actions.RerunJobByID returned error: %v", err)
261 }
262 if resp.StatusCode != http.StatusCreated {
263 t.Errorf("Actions.RerunJobByID returned status: %d, want %d", resp.StatusCode, http.StatusCreated)
264 }
265
266 const methodName = "RerunJobByID"
267 testBadOptions(t, methodName, func() (err error) {
268 _, err = client.Actions.RerunJobByID(ctx, "\n", "\n", 3434)
269 return err
270 })
271
272 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
273 return client.Actions.RerunJobByID(ctx, "o", "r", 3434)
274 })
275 }
276
277 func TestActionsService_CancelWorkflowRunByID(t *testing.T) {
278 client, mux, _, teardown := setup()
279 defer teardown()
280
281 mux.HandleFunc("/repos/o/r/actions/runs/3434/cancel", func(w http.ResponseWriter, r *http.Request) {
282 testMethod(t, r, "POST")
283 w.WriteHeader(http.StatusAccepted)
284 })
285
286 ctx := context.Background()
287 resp, err := client.Actions.CancelWorkflowRunByID(ctx, "o", "r", 3434)
288 if _, ok := err.(*AcceptedError); !ok {
289 t.Errorf("Actions.CancelWorkflowRunByID returned error: %v (want AcceptedError)", err)
290 }
291 if resp.StatusCode != http.StatusAccepted {
292 t.Errorf("Actions.CancelWorkflowRunByID returned status: %d, want %d", resp.StatusCode, http.StatusAccepted)
293 }
294
295 const methodName = "CancelWorkflowRunByID"
296 testBadOptions(t, methodName, func() (err error) {
297 _, err = client.Actions.CancelWorkflowRunByID(ctx, "\n", "\n", 3434)
298 return err
299 })
300
301 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
302 return client.Actions.CancelWorkflowRunByID(ctx, "o", "r", 3434)
303 })
304 }
305
306 func TestActionsService_GetWorkflowRunLogs(t *testing.T) {
307 client, mux, _, teardown := setup()
308 defer teardown()
309
310 mux.HandleFunc("/repos/o/r/actions/runs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
311 testMethod(t, r, "GET")
312 http.Redirect(w, r, "http://github.com/a", http.StatusFound)
313 })
314
315 ctx := context.Background()
316 url, resp, err := client.Actions.GetWorkflowRunLogs(ctx, "o", "r", 399444496, true)
317 if err != nil {
318 t.Errorf("Actions.GetWorkflowRunLogs returned error: %v", err)
319 }
320 if resp.StatusCode != http.StatusFound {
321 t.Errorf("Actions.GetWorkflowRunLogs returned status: %d, want %d", resp.StatusCode, http.StatusFound)
322 }
323 want := "http://github.com/a"
324 if url.String() != want {
325 t.Errorf("Actions.GetWorkflowRunLogs returned %+v, want %+v", url.String(), want)
326 }
327
328 const methodName = "GetWorkflowRunLogs"
329 testBadOptions(t, methodName, func() (err error) {
330 _, _, err = client.Actions.GetWorkflowRunLogs(ctx, "\n", "\n", 399444496, true)
331 return err
332 })
333 }
334
335 func TestActionsService_GetWorkflowRunLogs_StatusMovedPermanently_dontFollowRedirects(t *testing.T) {
336 client, mux, _, teardown := setup()
337 defer teardown()
338
339 mux.HandleFunc("/repos/o/r/actions/runs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
340 testMethod(t, r, "GET")
341 http.Redirect(w, r, "http://github.com/a", http.StatusMovedPermanently)
342 })
343
344 ctx := context.Background()
345 _, resp, _ := client.Actions.GetWorkflowRunLogs(ctx, "o", "r", 399444496, false)
346 if resp.StatusCode != http.StatusMovedPermanently {
347 t.Errorf("Actions.GetWorkflowJobLogs returned status: %d, want %d", resp.StatusCode, http.StatusMovedPermanently)
348 }
349 }
350
351 func TestActionsService_GetWorkflowRunLogs_StatusMovedPermanently_followRedirects(t *testing.T) {
352 client, mux, serverURL, teardown := setup()
353 defer teardown()
354
355
356 mux.HandleFunc("/repos/o/r/actions/runs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
357 testMethod(t, r, "GET")
358 redirectURL, _ := url.Parse(serverURL + baseURLPath + "/redirect")
359 http.Redirect(w, r, redirectURL.String(), http.StatusMovedPermanently)
360 })
361
362 mux.HandleFunc("/redirect", func(w http.ResponseWriter, r *http.Request) {
363 testMethod(t, r, "GET")
364 http.Redirect(w, r, "http://github.com/a", http.StatusFound)
365 })
366
367 ctx := context.Background()
368 url, resp, err := client.Actions.GetWorkflowRunLogs(ctx, "o", "r", 399444496, true)
369 if err != nil {
370 t.Errorf("Actions.GetWorkflowJobLogs returned error: %v", err)
371 }
372
373 if resp.StatusCode != http.StatusFound {
374 t.Errorf("Actions.GetWorkflowJobLogs returned status: %d, want %d", resp.StatusCode, http.StatusFound)
375 }
376
377 want := "http://github.com/a"
378 if url.String() != want {
379 t.Errorf("Actions.GetWorkflowJobLogs returned %+v, want %+v", url.String(), want)
380 }
381
382 const methodName = "GetWorkflowRunLogs"
383 testBadOptions(t, methodName, func() (err error) {
384 _, _, err = client.Actions.GetWorkflowRunLogs(ctx, "\n", "\n", 399444496, true)
385 return err
386 })
387 }
388
389 func TestActionService_ListRepositoryWorkflowRuns(t *testing.T) {
390 client, mux, _, teardown := setup()
391 defer teardown()
392
393 mux.HandleFunc("/repos/o/r/actions/runs", func(w http.ResponseWriter, r *http.Request) {
394 testMethod(t, r, "GET")
395 testFormValues(t, r, values{"per_page": "2", "page": "2"})
396 fmt.Fprint(w, `{"total_count":2,
397 "workflow_runs":[
398 {"id":298499444,"run_number":301,"created_at":"2020-04-11T11:14:54Z","updated_at":"2020-04-11T11:14:54Z"},
399 {"id":298499445,"run_number":302,"created_at":"2020-04-11T11:14:54Z","updated_at":"2020-04-11T11:14:54Z"}]}`)
400 })
401
402 opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}}
403 ctx := context.Background()
404 runs, _, err := client.Actions.ListRepositoryWorkflowRuns(ctx, "o", "r", opts)
405
406 if err != nil {
407 t.Errorf("Actions.ListRepositoryWorkflowRuns returned error: %v", err)
408 }
409
410 expected := &WorkflowRuns{
411 TotalCount: Int(2),
412 WorkflowRuns: []*WorkflowRun{
413 {ID: Int64(298499444), RunNumber: Int(301), CreatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}},
414 {ID: Int64(298499445), RunNumber: Int(302), CreatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}},
415 },
416 }
417
418 if !cmp.Equal(runs, expected) {
419 t.Errorf("Actions.ListRepositoryWorkflowRuns returned %+v, want %+v", runs, expected)
420 }
421
422 const methodName = "ListRepositoryWorkflowRuns"
423 testBadOptions(t, methodName, func() (err error) {
424 _, _, err = client.Actions.ListRepositoryWorkflowRuns(ctx, "\n", "\n", opts)
425
426 return err
427 })
428
429 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
430 got, resp, err := client.Actions.ListRepositoryWorkflowRuns(ctx, "o", "r", opts)
431
432 if got != nil {
433 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
434 }
435 return resp, err
436 })
437 }
438
439 func TestActionService_DeleteWorkflowRun(t *testing.T) {
440 client, mux, _, teardown := setup()
441 defer teardown()
442
443 mux.HandleFunc("/repos/o/r/actions/runs/399444496", func(w http.ResponseWriter, r *http.Request) {
444 testMethod(t, r, "DELETE")
445
446 w.WriteHeader(http.StatusNoContent)
447 })
448
449 ctx := context.Background()
450 if _, err := client.Actions.DeleteWorkflowRun(ctx, "o", "r", 399444496); err != nil {
451 t.Errorf("DeleteWorkflowRun returned error: %v", err)
452 }
453
454 const methodName = "DeleteWorkflowRun"
455 testBadOptions(t, methodName, func() (err error) {
456 _, err = client.Actions.DeleteWorkflowRun(ctx, "\n", "\n", 399444496)
457 return err
458 })
459
460 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
461 return client.Actions.DeleteWorkflowRun(ctx, "o", "r", 399444496)
462 })
463 }
464
465 func TestActionService_DeleteWorkflowRunLogs(t *testing.T) {
466 client, mux, _, teardown := setup()
467 defer teardown()
468
469 mux.HandleFunc("/repos/o/r/actions/runs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
470 testMethod(t, r, "DELETE")
471
472 w.WriteHeader(http.StatusNoContent)
473 })
474
475 ctx := context.Background()
476 if _, err := client.Actions.DeleteWorkflowRunLogs(ctx, "o", "r", 399444496); err != nil {
477 t.Errorf("DeleteWorkflowRunLogs returned error: %v", err)
478 }
479
480 const methodName = "DeleteWorkflowRunLogs"
481 testBadOptions(t, methodName, func() (err error) {
482 _, err = client.Actions.DeleteWorkflowRunLogs(ctx, "\n", "\n", 399444496)
483 return err
484 })
485
486 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
487 return client.Actions.DeleteWorkflowRunLogs(ctx, "o", "r", 399444496)
488 })
489 }
490
491 func TestActionsService_GetWorkflowRunUsageByID(t *testing.T) {
492 client, mux, _, teardown := setup()
493 defer teardown()
494
495 mux.HandleFunc("/repos/o/r/actions/runs/29679449/timing", func(w http.ResponseWriter, r *http.Request) {
496 testMethod(t, r, "GET")
497 fmt.Fprint(w, `{"billable":{"UBUNTU":{"total_ms":180000,"jobs":1,"job_runs":[{"job_id":1,"duration_ms":60000}]},"MACOS":{"total_ms":240000,"jobs":2,"job_runs":[{"job_id":2,"duration_ms":30000},{"job_id":3,"duration_ms":10000}]},"WINDOWS":{"total_ms":300000,"jobs":2}},"run_duration_ms":500000}`)
498 })
499
500 ctx := context.Background()
501 workflowRunUsage, _, err := client.Actions.GetWorkflowRunUsageByID(ctx, "o", "r", 29679449)
502 if err != nil {
503 t.Errorf("Actions.GetWorkflowRunUsageByID returned error: %v", err)
504 }
505
506 want := &WorkflowRunUsage{
507 Billable: &WorkflowRunEnvironment{
508 Ubuntu: &WorkflowRunBill{
509 TotalMS: Int64(180000),
510 Jobs: Int(1),
511 JobRuns: []*WorkflowRunJobRun{
512 {
513 JobID: Int(1),
514 DurationMS: Int64(60000),
515 },
516 },
517 },
518 MacOS: &WorkflowRunBill{
519 TotalMS: Int64(240000),
520 Jobs: Int(2),
521 JobRuns: []*WorkflowRunJobRun{
522 {
523 JobID: Int(2),
524 DurationMS: Int64(30000),
525 },
526 {
527 JobID: Int(3),
528 DurationMS: Int64(10000),
529 },
530 },
531 },
532 Windows: &WorkflowRunBill{
533 TotalMS: Int64(300000),
534 Jobs: Int(2),
535 },
536 },
537 RunDurationMS: Int64(500000),
538 }
539
540 if !cmp.Equal(workflowRunUsage, want) {
541 t.Errorf("Actions.GetWorkflowRunUsageByID returned %+v, want %+v", workflowRunUsage, want)
542 }
543
544 const methodName = "GetWorkflowRunUsageByID"
545 testBadOptions(t, methodName, func() (err error) {
546 _, _, err = client.Actions.GetWorkflowRunUsageByID(ctx, "\n", "\n", 29679449)
547 return err
548 })
549
550 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
551 got, resp, err := client.Actions.GetWorkflowRunUsageByID(ctx, "o", "r", 29679449)
552 if got != nil {
553 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
554 }
555 return resp, err
556 })
557 }
558
559 func TestWorkflowRun_Marshal(t *testing.T) {
560 testJSONMarshal(t, &WorkflowRun{}, "{}")
561
562 u := &WorkflowRun{
563 ID: Int64(1),
564 Name: String("n"),
565 NodeID: String("nid"),
566 HeadBranch: String("hb"),
567 HeadSHA: String("hs"),
568 RunNumber: Int(1),
569 RunAttempt: Int(1),
570 Event: String("e"),
571 Status: String("s"),
572 Conclusion: String("c"),
573 WorkflowID: Int64(1),
574 URL: String("u"),
575 HTMLURL: String("h"),
576 PullRequests: []*PullRequest{
577 {
578 URL: String("u"),
579 ID: Int64(1),
580 Number: Int(1),
581 Head: &PullRequestBranch{
582 Ref: String("r"),
583 SHA: String("s"),
584 Repo: &Repository{
585 ID: Int64(1),
586 URL: String("s"),
587 Name: String("n"),
588 },
589 },
590 Base: &PullRequestBranch{
591 Ref: String("r"),
592 SHA: String("s"),
593 Repo: &Repository{
594 ID: Int64(1),
595 URL: String("u"),
596 Name: String("n"),
597 },
598 },
599 },
600 },
601 CreatedAt: &Timestamp{referenceTime},
602 UpdatedAt: &Timestamp{referenceTime},
603 RunStartedAt: &Timestamp{referenceTime},
604 JobsURL: String("j"),
605 LogsURL: String("l"),
606 CheckSuiteURL: String("c"),
607 ArtifactsURL: String("a"),
608 CancelURL: String("c"),
609 RerunURL: String("r"),
610 PreviousAttemptURL: String("p"),
611 HeadCommit: &HeadCommit{
612 Message: String("m"),
613 Author: &CommitAuthor{
614 Name: String("n"),
615 Email: String("e"),
616 Login: String("l"),
617 },
618 URL: String("u"),
619 Distinct: Bool(false),
620 SHA: String("s"),
621 ID: String("i"),
622 TreeID: String("tid"),
623 Timestamp: &Timestamp{referenceTime},
624 Committer: &CommitAuthor{
625 Name: String("n"),
626 Email: String("e"),
627 Login: String("l"),
628 },
629 },
630 WorkflowURL: String("w"),
631 Repository: &Repository{
632 ID: Int64(1),
633 URL: String("u"),
634 Name: String("n"),
635 },
636 HeadRepository: &Repository{
637 ID: Int64(1),
638 URL: String("u"),
639 Name: String("n"),
640 },
641 Actor: &User{
642 Login: String("l"),
643 ID: Int64(1),
644 AvatarURL: String("a"),
645 GravatarID: String("g"),
646 Name: String("n"),
647 Company: String("c"),
648 Blog: String("b"),
649 Location: String("l"),
650 Email: String("e"),
651 Hireable: Bool(true),
652 Bio: String("b"),
653 TwitterUsername: String("t"),
654 PublicRepos: Int(1),
655 Followers: Int(1),
656 Following: Int(1),
657 CreatedAt: &Timestamp{referenceTime},
658 SuspendedAt: &Timestamp{referenceTime},
659 URL: String("u"),
660 },
661 }
662
663 want := `{
664 "id": 1,
665 "name": "n",
666 "node_id": "nid",
667 "head_branch": "hb",
668 "head_sha": "hs",
669 "run_number": 1,
670 "run_attempt": 1,
671 "event": "e",
672 "status": "s",
673 "conclusion": "c",
674 "workflow_id": 1,
675 "url": "u",
676 "html_url": "h",
677 "pull_requests": [
678 {
679 "id":1,
680 "number":1,
681 "url":"u",
682 "head":{
683 "ref":"r",
684 "sha":"s",
685 "repo": {
686 "id":1,
687 "name":"n",
688 "url":"s"
689 }
690 },
691 "base": {
692 "ref":"r",
693 "sha":"s",
694 "repo": {
695 "id":1,
696 "name":"n",
697 "url":"u"
698 }
699 }
700 }
701 ],
702 "created_at": ` + referenceTimeStr + `,
703 "updated_at": ` + referenceTimeStr + `,
704 "run_started_at": ` + referenceTimeStr + `,
705 "jobs_url": "j",
706 "logs_url": "l",
707 "check_suite_url": "c",
708 "artifacts_url": "a",
709 "cancel_url": "c",
710 "rerun_url": "r",
711 "previous_attempt_url": "p",
712 "head_commit": {
713 "message": "m",
714 "author": {
715 "name": "n",
716 "email": "e",
717 "username": "l"
718 },
719 "url": "u",
720 "distinct": false,
721 "sha": "s",
722 "id": "i",
723 "tree_id": "tid",
724 "timestamp": ` + referenceTimeStr + `,
725 "committer": {
726 "name": "n",
727 "email": "e",
728 "username": "l"
729 }
730 },
731 "workflow_url": "w",
732 "repository": {
733 "id": 1,
734 "url": "u",
735 "name": "n"
736 },
737 "head_repository": {
738 "id": 1,
739 "url": "u",
740 "name": "n"
741 },
742 "actor": {
743 "login": "l",
744 "id": 1,
745 "avatar_url": "a",
746 "gravatar_id": "g",
747 "name": "n",
748 "company": "c",
749 "blog": "b",
750 "location": "l",
751 "email": "e",
752 "hireable": true,
753 "bio": "b",
754 "twitter_username": "t",
755 "public_repos": 1,
756 "followers": 1,
757 "following": 1,
758 "created_at": ` + referenceTimeStr + `,
759 "suspended_at": ` + referenceTimeStr + `,
760 "url": "u"
761 }
762 }`
763
764 testJSONMarshal(t, u, want)
765 }
766
767 func TestWorkflowRuns_Marshal(t *testing.T) {
768 testJSONMarshal(t, &WorkflowRuns{}, "{}")
769
770 u := &WorkflowRuns{
771 TotalCount: Int(1),
772 WorkflowRuns: []*WorkflowRun{
773 {
774 ID: Int64(1),
775 Name: String("n"),
776 NodeID: String("nid"),
777 HeadBranch: String("hb"),
778 HeadSHA: String("hs"),
779 RunNumber: Int(1),
780 RunAttempt: Int(1),
781 Event: String("e"),
782 Status: String("s"),
783 Conclusion: String("c"),
784 WorkflowID: Int64(1),
785 URL: String("u"),
786 HTMLURL: String("h"),
787 PullRequests: []*PullRequest{
788 {
789 URL: String("u"),
790 ID: Int64(1),
791 Number: Int(1),
792 Head: &PullRequestBranch{
793 Ref: String("r"),
794 SHA: String("s"),
795 Repo: &Repository{
796 ID: Int64(1),
797 URL: String("s"),
798 Name: String("n"),
799 },
800 },
801 Base: &PullRequestBranch{
802 Ref: String("r"),
803 SHA: String("s"),
804 Repo: &Repository{
805 ID: Int64(1),
806 URL: String("u"),
807 Name: String("n"),
808 },
809 },
810 },
811 },
812 CreatedAt: &Timestamp{referenceTime},
813 UpdatedAt: &Timestamp{referenceTime},
814 RunStartedAt: &Timestamp{referenceTime},
815 JobsURL: String("j"),
816 LogsURL: String("l"),
817 CheckSuiteURL: String("c"),
818 ArtifactsURL: String("a"),
819 CancelURL: String("c"),
820 RerunURL: String("r"),
821 PreviousAttemptURL: String("p"),
822 HeadCommit: &HeadCommit{
823 Message: String("m"),
824 Author: &CommitAuthor{
825 Name: String("n"),
826 Email: String("e"),
827 Login: String("l"),
828 },
829 URL: String("u"),
830 Distinct: Bool(false),
831 SHA: String("s"),
832 ID: String("i"),
833 TreeID: String("tid"),
834 Timestamp: &Timestamp{referenceTime},
835 Committer: &CommitAuthor{
836 Name: String("n"),
837 Email: String("e"),
838 Login: String("l"),
839 },
840 },
841 WorkflowURL: String("w"),
842 Repository: &Repository{
843 ID: Int64(1),
844 URL: String("u"),
845 Name: String("n"),
846 },
847 HeadRepository: &Repository{
848 ID: Int64(1),
849 URL: String("u"),
850 Name: String("n"),
851 },
852 Actor: &User{
853 Login: String("l"),
854 ID: Int64(1),
855 AvatarURL: String("a"),
856 GravatarID: String("g"),
857 Name: String("n"),
858 Company: String("c"),
859 Blog: String("b"),
860 Location: String("l"),
861 Email: String("e"),
862 Hireable: Bool(true),
863 Bio: String("b"),
864 TwitterUsername: String("t"),
865 PublicRepos: Int(1),
866 Followers: Int(1),
867 Following: Int(1),
868 CreatedAt: &Timestamp{referenceTime},
869 SuspendedAt: &Timestamp{referenceTime},
870 URL: String("u"),
871 },
872 },
873 },
874 }
875
876 want := `{
877 "total_count": 1,
878 "workflow_runs": [
879 {
880 "id": 1,
881 "name": "n",
882 "node_id": "nid",
883 "head_branch": "hb",
884 "head_sha": "hs",
885 "run_number": 1,
886 "run_attempt": 1,
887 "event": "e",
888 "status": "s",
889 "conclusion": "c",
890 "workflow_id": 1,
891 "url": "u",
892 "html_url": "h",
893 "pull_requests": [
894 {
895 "id":1,
896 "number":1,
897 "url":"u",
898 "head":{
899 "ref":"r",
900 "sha":"s",
901 "repo": {
902 "id":1,
903 "name":"n",
904 "url":"s"
905 }
906 },
907 "base": {
908 "ref":"r",
909 "sha":"s",
910 "repo": {
911 "id":1,
912 "name":"n",
913 "url":"u"
914 }
915 }
916 }
917 ],
918 "created_at": ` + referenceTimeStr + `,
919 "updated_at": ` + referenceTimeStr + `,
920 "run_started_at": ` + referenceTimeStr + `,
921 "jobs_url": "j",
922 "logs_url": "l",
923 "check_suite_url": "c",
924 "artifacts_url": "a",
925 "cancel_url": "c",
926 "rerun_url": "r",
927 "previous_attempt_url": "p",
928 "head_commit": {
929 "message": "m",
930 "author": {
931 "name": "n",
932 "email": "e",
933 "username": "l"
934 },
935 "url": "u",
936 "distinct": false,
937 "sha": "s",
938 "id": "i",
939 "tree_id": "tid",
940 "timestamp": ` + referenceTimeStr + `,
941 "committer": {
942 "name": "n",
943 "email": "e",
944 "username": "l"
945 }
946 },
947 "workflow_url": "w",
948 "repository": {
949 "id": 1,
950 "url": "u",
951 "name": "n"
952 },
953 "head_repository": {
954 "id": 1,
955 "url": "u",
956 "name": "n"
957 },
958 "actor": {
959 "login": "l",
960 "id": 1,
961 "avatar_url": "a",
962 "gravatar_id": "g",
963 "name": "n",
964 "company": "c",
965 "blog": "b",
966 "location": "l",
967 "email": "e",
968 "hireable": true,
969 "bio": "b",
970 "twitter_username": "t",
971 "public_repos": 1,
972 "followers": 1,
973 "following": 1,
974 "created_at": ` + referenceTimeStr + `,
975 "suspended_at": ` + referenceTimeStr + `,
976 "url": "u"
977 }
978 }
979 ]
980 }`
981
982 testJSONMarshal(t, u, want)
983 }
984
985 func TestWorkflowRunBill_Marshal(t *testing.T) {
986 testJSONMarshal(t, &WorkflowRunBill{}, "{}")
987
988 u := &WorkflowRunBill{
989 TotalMS: Int64(1),
990 Jobs: Int(1),
991 }
992
993 want := `{
994 "total_ms": 1,
995 "jobs": 1
996 }`
997
998 testJSONMarshal(t, u, want)
999 }
1000
1001 func TestWorkflowRunEnvironment_Marshal(t *testing.T) {
1002 testJSONMarshal(t, &WorkflowRunEnvironment{}, "{}")
1003
1004 u := &WorkflowRunEnvironment{
1005 Ubuntu: &WorkflowRunBill{
1006 TotalMS: Int64(1),
1007 Jobs: Int(1),
1008 },
1009 MacOS: &WorkflowRunBill{
1010 TotalMS: Int64(1),
1011 Jobs: Int(1),
1012 },
1013 Windows: &WorkflowRunBill{
1014 TotalMS: Int64(1),
1015 Jobs: Int(1),
1016 },
1017 }
1018
1019 want := `{
1020 "UBUNTU": {
1021 "total_ms": 1,
1022 "jobs": 1
1023 },
1024 "MACOS": {
1025 "total_ms": 1,
1026 "jobs": 1
1027 },
1028 "WINDOWS": {
1029 "total_ms": 1,
1030 "jobs": 1
1031 }
1032 }`
1033
1034 testJSONMarshal(t, u, want)
1035 }
1036
1037 func TestWorkflowRunUsage_Marshal(t *testing.T) {
1038 testJSONMarshal(t, &WorkflowRunUsage{}, "{}")
1039
1040 u := &WorkflowRunUsage{
1041 Billable: &WorkflowRunEnvironment{
1042 Ubuntu: &WorkflowRunBill{
1043 TotalMS: Int64(1),
1044 Jobs: Int(1),
1045 },
1046 MacOS: &WorkflowRunBill{
1047 TotalMS: Int64(1),
1048 Jobs: Int(1),
1049 },
1050 Windows: &WorkflowRunBill{
1051 TotalMS: Int64(1),
1052 Jobs: Int(1),
1053 },
1054 },
1055 RunDurationMS: Int64(1),
1056 }
1057
1058 want := `{
1059 "billable": {
1060 "UBUNTU": {
1061 "total_ms": 1,
1062 "jobs": 1
1063 },
1064 "MACOS": {
1065 "total_ms": 1,
1066 "jobs": 1
1067 },
1068 "WINDOWS": {
1069 "total_ms": 1,
1070 "jobs": 1
1071 }
1072 },
1073 "run_duration_ms": 1
1074 }`
1075
1076 testJSONMarshal(t, u, want)
1077 }
1078
View as plain text