1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 "net/http"
12 "testing"
13 "time"
14
15 "github.com/google/go-cmp/cmp"
16 )
17
18 func TestChecksService_GetCheckRun(t *testing.T) {
19 client, mux, _, teardown := setup()
20 defer teardown()
21
22 mux.HandleFunc("/repos/o/r/check-runs/1", func(w http.ResponseWriter, r *http.Request) {
23 testMethod(t, r, "GET")
24 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
25 fmt.Fprint(w, `{
26 "id": 1,
27 "name":"testCheckRun",
28 "status": "completed",
29 "conclusion": "neutral",
30 "started_at": "2018-05-04T01:14:52Z",
31 "completed_at": "2018-05-04T01:14:52Z"}`)
32 })
33 ctx := context.Background()
34 checkRun, _, err := client.Checks.GetCheckRun(ctx, "o", "r", 1)
35 if err != nil {
36 t.Errorf("Checks.GetCheckRun return error: %v", err)
37 }
38 startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
39 completeAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
40
41 want := &CheckRun{
42 ID: Int64(1),
43 Status: String("completed"),
44 Conclusion: String("neutral"),
45 StartedAt: &Timestamp{startedAt},
46 CompletedAt: &Timestamp{completeAt},
47 Name: String("testCheckRun"),
48 }
49 if !cmp.Equal(checkRun, want) {
50 t.Errorf("Checks.GetCheckRun return %+v, want %+v", checkRun, want)
51 }
52
53 const methodName = "GetCheckRun"
54 testBadOptions(t, methodName, func() (err error) {
55 _, _, err = client.Checks.GetCheckRun(ctx, "\n", "\n", -1)
56 return err
57 })
58
59 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
60 got, resp, err := client.Checks.GetCheckRun(ctx, "o", "r", 1)
61 if got != nil {
62 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
63 }
64 return resp, err
65 })
66 }
67
68 func TestChecksService_GetCheckSuite(t *testing.T) {
69 client, mux, _, teardown := setup()
70 defer teardown()
71
72 mux.HandleFunc("/repos/o/r/check-suites/1", func(w http.ResponseWriter, r *http.Request) {
73 testMethod(t, r, "GET")
74 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
75 fmt.Fprint(w, `{
76 "id": 1,
77 "head_branch":"master",
78 "head_sha": "deadbeef",
79 "conclusion": "neutral",
80 "before": "deadbeefb",
81 "after": "deadbeefa",
82 "status": "completed"}`)
83 })
84 ctx := context.Background()
85 checkSuite, _, err := client.Checks.GetCheckSuite(ctx, "o", "r", 1)
86 if err != nil {
87 t.Errorf("Checks.GetCheckSuite return error: %v", err)
88 }
89 want := &CheckSuite{
90 ID: Int64(1),
91 HeadBranch: String("master"),
92 HeadSHA: String("deadbeef"),
93 AfterSHA: String("deadbeefa"),
94 BeforeSHA: String("deadbeefb"),
95 Status: String("completed"),
96 Conclusion: String("neutral"),
97 }
98 if !cmp.Equal(checkSuite, want) {
99 t.Errorf("Checks.GetCheckSuite return %+v, want %+v", checkSuite, want)
100 }
101
102 const methodName = "GetCheckSuite"
103 testBadOptions(t, methodName, func() (err error) {
104 _, _, err = client.Checks.GetCheckSuite(ctx, "\n", "\n", -1)
105 return err
106 })
107
108 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
109 got, resp, err := client.Checks.GetCheckSuite(ctx, "o", "r", 1)
110 if got != nil {
111 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
112 }
113 return resp, err
114 })
115 }
116
117 func TestChecksService_CreateCheckRun(t *testing.T) {
118 client, mux, _, teardown := setup()
119 defer teardown()
120
121 mux.HandleFunc("/repos/o/r/check-runs", func(w http.ResponseWriter, r *http.Request) {
122 testMethod(t, r, "POST")
123 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
124 fmt.Fprint(w, `{
125 "id": 1,
126 "name":"testCreateCheckRun",
127 "head_sha":"deadbeef",
128 "status": "in_progress",
129 "conclusion": null,
130 "started_at": "2018-05-04T01:14:52Z",
131 "completed_at": null,
132 "output":{"title": "Mighty test report", "summary":"", "text":""}}`)
133 })
134 startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
135 checkRunOpt := CreateCheckRunOptions{
136 Name: "testCreateCheckRun",
137 HeadSHA: "deadbeef",
138 Status: String("in_progress"),
139 StartedAt: &Timestamp{startedAt},
140 Output: &CheckRunOutput{
141 Title: String("Mighty test report"),
142 Summary: String(""),
143 Text: String(""),
144 },
145 }
146
147 ctx := context.Background()
148 checkRun, _, err := client.Checks.CreateCheckRun(ctx, "o", "r", checkRunOpt)
149 if err != nil {
150 t.Errorf("Checks.CreateCheckRun return error: %v", err)
151 }
152
153 want := &CheckRun{
154 ID: Int64(1),
155 Status: String("in_progress"),
156 StartedAt: &Timestamp{startedAt},
157 HeadSHA: String("deadbeef"),
158 Name: String("testCreateCheckRun"),
159 Output: &CheckRunOutput{
160 Title: String("Mighty test report"),
161 Summary: String(""),
162 Text: String(""),
163 },
164 }
165 if !cmp.Equal(checkRun, want) {
166 t.Errorf("Checks.CreateCheckRun return %+v, want %+v", checkRun, want)
167 }
168
169 const methodName = "CreateCheckRun"
170 testBadOptions(t, methodName, func() (err error) {
171 _, _, err = client.Checks.CreateCheckRun(ctx, "\n", "\n", CreateCheckRunOptions{})
172 return err
173 })
174
175 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
176 got, resp, err := client.Checks.CreateCheckRun(ctx, "o", "r", checkRunOpt)
177 if got != nil {
178 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
179 }
180 return resp, err
181 })
182 }
183
184 func TestChecksService_ListCheckRunAnnotations(t *testing.T) {
185 client, mux, _, teardown := setup()
186 defer teardown()
187
188 mux.HandleFunc("/repos/o/r/check-runs/1/annotations", func(w http.ResponseWriter, r *http.Request) {
189 testMethod(t, r, "GET")
190 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
191 testFormValues(t, r, values{
192 "page": "1",
193 })
194 fmt.Fprint(w, `[{
195 "path": "README.md",
196 "start_line": 2,
197 "end_line": 2,
198 "start_column": 1,
199 "end_column": 5,
200 "annotation_level": "warning",
201 "message": "Check your spelling for 'banaas'.",
202 "title": "Spell check",
203 "raw_details": "Do you mean 'bananas' or 'banana'?"}]`,
204 )
205 })
206
207 ctx := context.Background()
208 checkRunAnnotations, _, err := client.Checks.ListCheckRunAnnotations(ctx, "o", "r", 1, &ListOptions{Page: 1})
209 if err != nil {
210 t.Errorf("Checks.ListCheckRunAnnotations return error: %v", err)
211 }
212
213 want := []*CheckRunAnnotation{{
214 Path: String("README.md"),
215 StartLine: Int(2),
216 EndLine: Int(2),
217 StartColumn: Int(1),
218 EndColumn: Int(5),
219 AnnotationLevel: String("warning"),
220 Message: String("Check your spelling for 'banaas'."),
221 Title: String("Spell check"),
222 RawDetails: String("Do you mean 'bananas' or 'banana'?"),
223 }}
224
225 if !cmp.Equal(checkRunAnnotations, want) {
226 t.Errorf("Checks.ListCheckRunAnnotations returned %+v, want %+v", checkRunAnnotations, want)
227 }
228
229 const methodName = "ListCheckRunAnnotations"
230 testBadOptions(t, methodName, func() (err error) {
231 _, _, err = client.Checks.ListCheckRunAnnotations(ctx, "\n", "\n", -1, &ListOptions{})
232 return err
233 })
234
235 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
236 got, resp, err := client.Checks.ListCheckRunAnnotations(ctx, "o", "r", 1, nil)
237 if got != nil {
238 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
239 }
240 return resp, err
241 })
242 }
243
244 func TestChecksService_UpdateCheckRun(t *testing.T) {
245 client, mux, _, teardown := setup()
246 defer teardown()
247
248 mux.HandleFunc("/repos/o/r/check-runs/1", func(w http.ResponseWriter, r *http.Request) {
249 testMethod(t, r, "PATCH")
250 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
251 fmt.Fprint(w, `{
252 "id": 1,
253 "name":"testUpdateCheckRun",
254 "status": "completed",
255 "conclusion": "neutral",
256 "started_at": "2018-05-04T01:14:52Z",
257 "completed_at": "2018-05-04T01:14:52Z",
258 "output":{"title": "Mighty test report", "summary":"There are 0 failures, 2 warnings and 1 notice", "text":"You may have misspelled some words."}}`)
259 })
260 startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
261 updateCheckRunOpt := UpdateCheckRunOptions{
262 Name: "testUpdateCheckRun",
263 Status: String("completed"),
264 CompletedAt: &Timestamp{startedAt},
265 Output: &CheckRunOutput{
266 Title: String("Mighty test report"),
267 Summary: String("There are 0 failures, 2 warnings and 1 notice"),
268 Text: String("You may have misspelled some words."),
269 },
270 }
271
272 ctx := context.Background()
273 checkRun, _, err := client.Checks.UpdateCheckRun(ctx, "o", "r", 1, updateCheckRunOpt)
274 if err != nil {
275 t.Errorf("Checks.UpdateCheckRun return error: %v", err)
276 }
277
278 want := &CheckRun{
279 ID: Int64(1),
280 Status: String("completed"),
281 StartedAt: &Timestamp{startedAt},
282 CompletedAt: &Timestamp{startedAt},
283 Conclusion: String("neutral"),
284 Name: String("testUpdateCheckRun"),
285 Output: &CheckRunOutput{
286 Title: String("Mighty test report"),
287 Summary: String("There are 0 failures, 2 warnings and 1 notice"),
288 Text: String("You may have misspelled some words."),
289 },
290 }
291 if !cmp.Equal(checkRun, want) {
292 t.Errorf("Checks.UpdateCheckRun return %+v, want %+v", checkRun, want)
293 }
294
295 const methodName = "UpdateCheckRun"
296 testBadOptions(t, methodName, func() (err error) {
297 _, _, err = client.Checks.UpdateCheckRun(ctx, "\n", "\n", -1, UpdateCheckRunOptions{})
298 return err
299 })
300
301 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
302 got, resp, err := client.Checks.UpdateCheckRun(ctx, "o", "r", 1, updateCheckRunOpt)
303 if got != nil {
304 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
305 }
306 return resp, err
307 })
308 }
309
310 func TestChecksService_ListCheckRunsForRef(t *testing.T) {
311 client, mux, _, teardown := setup()
312 defer teardown()
313
314 mux.HandleFunc("/repos/o/r/commits/master/check-runs", func(w http.ResponseWriter, r *http.Request) {
315 testMethod(t, r, "GET")
316 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
317 testFormValues(t, r, values{
318 "check_name": "testing",
319 "page": "1",
320 "status": "completed",
321 "filter": "all",
322 "app_id": "1",
323 })
324 fmt.Fprint(w, `{"total_count":1,
325 "check_runs": [{
326 "id": 1,
327 "head_sha": "deadbeef",
328 "status": "completed",
329 "conclusion": "neutral",
330 "started_at": "2018-05-04T01:14:52Z",
331 "completed_at": "2018-05-04T01:14:52Z",
332 "app": {
333 "id": 1}}]}`,
334 )
335 })
336
337 opt := &ListCheckRunsOptions{
338 CheckName: String("testing"),
339 Status: String("completed"),
340 Filter: String("all"),
341 AppID: Int64(1),
342 ListOptions: ListOptions{Page: 1},
343 }
344 ctx := context.Background()
345 checkRuns, _, err := client.Checks.ListCheckRunsForRef(ctx, "o", "r", "master", opt)
346 if err != nil {
347 t.Errorf("Checks.ListCheckRunsForRef return error: %v", err)
348 }
349 startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
350 want := &ListCheckRunsResults{
351 Total: Int(1),
352 CheckRuns: []*CheckRun{{
353 ID: Int64(1),
354 Status: String("completed"),
355 StartedAt: &Timestamp{startedAt},
356 CompletedAt: &Timestamp{startedAt},
357 Conclusion: String("neutral"),
358 HeadSHA: String("deadbeef"),
359 App: &App{ID: Int64(1)},
360 }},
361 }
362
363 if !cmp.Equal(checkRuns, want) {
364 t.Errorf("Checks.ListCheckRunsForRef returned %+v, want %+v", checkRuns, want)
365 }
366
367 const methodName = "ListCheckRunsForRef"
368 testBadOptions(t, methodName, func() (err error) {
369 _, _, err = client.Checks.ListCheckRunsForRef(ctx, "\n", "\n", "\n", &ListCheckRunsOptions{})
370 return err
371 })
372
373 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
374 got, resp, err := client.Checks.ListCheckRunsForRef(ctx, "o", "r", "master", opt)
375 if got != nil {
376 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
377 }
378 return resp, err
379 })
380 }
381
382 func TestChecksService_ListCheckRunsCheckSuite(t *testing.T) {
383 client, mux, _, teardown := setup()
384 defer teardown()
385
386 mux.HandleFunc("/repos/o/r/check-suites/1/check-runs", func(w http.ResponseWriter, r *http.Request) {
387 testMethod(t, r, "GET")
388 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
389 testFormValues(t, r, values{
390 "check_name": "testing",
391 "page": "1",
392 "status": "completed",
393 "filter": "all",
394 })
395 fmt.Fprint(w, `{"total_count":1,
396 "check_runs": [{
397 "id": 1,
398 "head_sha": "deadbeef",
399 "status": "completed",
400 "conclusion": "neutral",
401 "started_at": "2018-05-04T01:14:52Z",
402 "completed_at": "2018-05-04T01:14:52Z"}]}`,
403 )
404 })
405
406 opt := &ListCheckRunsOptions{
407 CheckName: String("testing"),
408 Status: String("completed"),
409 Filter: String("all"),
410 ListOptions: ListOptions{Page: 1},
411 }
412 ctx := context.Background()
413 checkRuns, _, err := client.Checks.ListCheckRunsCheckSuite(ctx, "o", "r", 1, opt)
414 if err != nil {
415 t.Errorf("Checks.ListCheckRunsCheckSuite return error: %v", err)
416 }
417 startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
418 want := &ListCheckRunsResults{
419 Total: Int(1),
420 CheckRuns: []*CheckRun{{
421 ID: Int64(1),
422 Status: String("completed"),
423 StartedAt: &Timestamp{startedAt},
424 CompletedAt: &Timestamp{startedAt},
425 Conclusion: String("neutral"),
426 HeadSHA: String("deadbeef"),
427 }},
428 }
429
430 if !cmp.Equal(checkRuns, want) {
431 t.Errorf("Checks.ListCheckRunsCheckSuite returned %+v, want %+v", checkRuns, want)
432 }
433
434 const methodName = "ListCheckRunsCheckSuite"
435 testBadOptions(t, methodName, func() (err error) {
436 _, _, err = client.Checks.ListCheckRunsCheckSuite(ctx, "\n", "\n", -1, &ListCheckRunsOptions{})
437 return err
438 })
439
440 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
441 got, resp, err := client.Checks.ListCheckRunsCheckSuite(ctx, "o", "r", 1, opt)
442 if got != nil {
443 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
444 }
445 return resp, err
446 })
447 }
448
449 func TestChecksService_ListCheckSuiteForRef(t *testing.T) {
450 client, mux, _, teardown := setup()
451 defer teardown()
452
453 mux.HandleFunc("/repos/o/r/commits/master/check-suites", func(w http.ResponseWriter, r *http.Request) {
454 testMethod(t, r, "GET")
455 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
456 testFormValues(t, r, values{
457 "check_name": "testing",
458 "page": "1",
459 "app_id": "2",
460 })
461 fmt.Fprint(w, `{"total_count":1,
462 "check_suites": [{
463 "id": 1,
464 "head_sha": "deadbeef",
465 "head_branch": "master",
466 "status": "completed",
467 "conclusion": "neutral",
468 "before": "deadbeefb",
469 "after": "deadbeefa"}]}`,
470 )
471 })
472
473 opt := &ListCheckSuiteOptions{
474 CheckName: String("testing"),
475 AppID: Int(2),
476 ListOptions: ListOptions{Page: 1},
477 }
478 ctx := context.Background()
479 checkSuites, _, err := client.Checks.ListCheckSuitesForRef(ctx, "o", "r", "master", opt)
480 if err != nil {
481 t.Errorf("Checks.ListCheckSuitesForRef return error: %v", err)
482 }
483 want := &ListCheckSuiteResults{
484 Total: Int(1),
485 CheckSuites: []*CheckSuite{{
486 ID: Int64(1),
487 Status: String("completed"),
488 Conclusion: String("neutral"),
489 HeadSHA: String("deadbeef"),
490 HeadBranch: String("master"),
491 BeforeSHA: String("deadbeefb"),
492 AfterSHA: String("deadbeefa"),
493 }},
494 }
495
496 if !cmp.Equal(checkSuites, want) {
497 t.Errorf("Checks.ListCheckSuitesForRef returned %+v, want %+v", checkSuites, want)
498 }
499
500 const methodName = "ListCheckSuitesForRef"
501 testBadOptions(t, methodName, func() (err error) {
502 _, _, err = client.Checks.ListCheckSuitesForRef(ctx, "\n", "\n", "\n", &ListCheckSuiteOptions{})
503 return err
504 })
505
506 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
507 got, resp, err := client.Checks.ListCheckSuitesForRef(ctx, "o", "r", "master", opt)
508 if got != nil {
509 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
510 }
511 return resp, err
512 })
513 }
514
515 func TestChecksService_SetCheckSuitePreferences(t *testing.T) {
516 client, mux, _, teardown := setup()
517 defer teardown()
518
519 mux.HandleFunc("/repos/o/r/check-suites/preferences", func(w http.ResponseWriter, r *http.Request) {
520 testMethod(t, r, "PATCH")
521 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
522 testBody(t, r, `{"auto_trigger_checks":[{"app_id":2,"setting":false}]}`+"\n")
523 fmt.Fprint(w, `{"preferences":{"auto_trigger_checks":[{"app_id": 2,"setting": false}]}}`)
524 })
525 a := []*AutoTriggerCheck{{
526 AppID: Int64(2),
527 Setting: Bool(false),
528 }}
529 opt := CheckSuitePreferenceOptions{AutoTriggerChecks: a}
530 ctx := context.Background()
531 prefResults, _, err := client.Checks.SetCheckSuitePreferences(ctx, "o", "r", opt)
532 if err != nil {
533 t.Errorf("Checks.SetCheckSuitePreferences return error: %v", err)
534 }
535
536 p := &PreferenceList{
537 AutoTriggerChecks: a,
538 }
539 want := &CheckSuitePreferenceResults{
540 Preferences: p,
541 }
542
543 if !cmp.Equal(prefResults, want) {
544 t.Errorf("Checks.SetCheckSuitePreferences return %+v, want %+v", prefResults, want)
545 }
546
547 const methodName = "SetCheckSuitePreferences"
548 testBadOptions(t, methodName, func() (err error) {
549 _, _, err = client.Checks.SetCheckSuitePreferences(ctx, "\n", "\n", CheckSuitePreferenceOptions{})
550 return err
551 })
552
553 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
554 got, resp, err := client.Checks.SetCheckSuitePreferences(ctx, "o", "r", opt)
555 if got != nil {
556 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
557 }
558 return resp, err
559 })
560 }
561
562 func TestChecksService_CreateCheckSuite(t *testing.T) {
563 client, mux, _, teardown := setup()
564 defer teardown()
565
566 mux.HandleFunc("/repos/o/r/check-suites", func(w http.ResponseWriter, r *http.Request) {
567 testMethod(t, r, "POST")
568 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
569 fmt.Fprint(w, `{
570 "id": 2,
571 "head_branch":"master",
572 "head_sha":"deadbeef",
573 "status": "completed",
574 "conclusion": "neutral",
575 "before": "deadbeefb",
576 "after": "deadbeefa"}`)
577 })
578
579 checkSuiteOpt := CreateCheckSuiteOptions{
580 HeadSHA: "deadbeef",
581 HeadBranch: String("master"),
582 }
583
584 ctx := context.Background()
585 checkSuite, _, err := client.Checks.CreateCheckSuite(ctx, "o", "r", checkSuiteOpt)
586 if err != nil {
587 t.Errorf("Checks.CreateCheckSuite return error: %v", err)
588 }
589
590 want := &CheckSuite{
591 ID: Int64(2),
592 Status: String("completed"),
593 HeadSHA: String("deadbeef"),
594 HeadBranch: String("master"),
595 Conclusion: String("neutral"),
596 BeforeSHA: String("deadbeefb"),
597 AfterSHA: String("deadbeefa"),
598 }
599 if !cmp.Equal(checkSuite, want) {
600 t.Errorf("Checks.CreateCheckSuite return %+v, want %+v", checkSuite, want)
601 }
602
603 const methodName = "CreateCheckSuite"
604 testBadOptions(t, methodName, func() (err error) {
605 _, _, err = client.Checks.CreateCheckSuite(ctx, "\n", "\n", CreateCheckSuiteOptions{})
606 return err
607 })
608
609 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
610 got, resp, err := client.Checks.CreateCheckSuite(ctx, "o", "r", checkSuiteOpt)
611 if got != nil {
612 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
613 }
614 return resp, err
615 })
616 }
617
618 func TestChecksService_ReRequestCheckSuite(t *testing.T) {
619 client, mux, _, teardown := setup()
620 defer teardown()
621
622 mux.HandleFunc("/repos/o/r/check-suites/1/rerequest", func(w http.ResponseWriter, r *http.Request) {
623 testMethod(t, r, "POST")
624 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
625 w.WriteHeader(http.StatusCreated)
626 })
627 ctx := context.Background()
628 resp, err := client.Checks.ReRequestCheckSuite(ctx, "o", "r", 1)
629 if err != nil {
630 t.Errorf("Checks.ReRequestCheckSuite return error: %v", err)
631 }
632 if got, want := resp.StatusCode, http.StatusCreated; got != want {
633 t.Errorf("Checks.ReRequestCheckSuite = %v, want %v", got, want)
634 }
635
636 const methodName = "ReRequestCheckSuite"
637 testBadOptions(t, methodName, func() (err error) {
638 _, err = client.Checks.ReRequestCheckSuite(ctx, "\n", "\n", 1)
639 return err
640 })
641 }
642
643 func Test_CheckRunMarshal(t *testing.T) {
644 testJSONMarshal(t, &CheckRun{}, "{}")
645
646 now := time.Now()
647 ts := now.Format(time.RFC3339Nano)
648
649 c := CheckRun{
650 ID: Int64(1),
651 NodeID: String("n"),
652 HeadSHA: String("h"),
653 ExternalID: String("1"),
654 URL: String("u"),
655 HTMLURL: String("u"),
656 DetailsURL: String("u"),
657 Status: String("s"),
658 Conclusion: String("c"),
659 StartedAt: &Timestamp{Time: now},
660 CompletedAt: &Timestamp{Time: now},
661 Output: &CheckRunOutput{
662 Annotations: []*CheckRunAnnotation{
663 {
664 AnnotationLevel: String("a"),
665 EndLine: Int(1),
666 Message: String("m"),
667 Path: String("p"),
668 RawDetails: String("r"),
669 StartLine: Int(1),
670 Title: String("t"),
671 },
672 },
673 AnnotationsCount: Int(1),
674 AnnotationsURL: String("a"),
675 Images: []*CheckRunImage{
676 {
677 Alt: String("a"),
678 ImageURL: String("i"),
679 Caption: String("c"),
680 },
681 },
682 Title: String("t"),
683 Summary: String("s"),
684 Text: String("t"),
685 },
686 Name: String("n"),
687 CheckSuite: &CheckSuite{
688 ID: Int64(1),
689 },
690 App: &App{
691 ID: Int64(1),
692 NodeID: String("n"),
693 Owner: &User{
694 Login: String("l"),
695 ID: Int64(1),
696 NodeID: String("n"),
697 URL: String("u"),
698 ReposURL: String("r"),
699 EventsURL: String("e"),
700 AvatarURL: String("a"),
701 },
702 Name: String("n"),
703 Description: String("d"),
704 HTMLURL: String("h"),
705 ExternalURL: String("u"),
706 CreatedAt: &Timestamp{now},
707 UpdatedAt: &Timestamp{now},
708 },
709 PullRequests: []*PullRequest{
710 {
711 URL: String("u"),
712 ID: Int64(1),
713 Number: Int(1),
714 Head: &PullRequestBranch{
715 Ref: String("r"),
716 SHA: String("s"),
717 Repo: &Repository{
718 ID: Int64(1),
719 URL: String("s"),
720 Name: String("n"),
721 },
722 },
723 Base: &PullRequestBranch{
724 Ref: String("r"),
725 SHA: String("s"),
726 Repo: &Repository{
727 ID: Int64(1),
728 URL: String("u"),
729 Name: String("n"),
730 },
731 },
732 },
733 },
734 }
735 w := fmt.Sprintf(`{
736 "id": 1,
737 "node_id": "n",
738 "head_sha": "h",
739 "external_id": "1",
740 "url": "u",
741 "html_url": "u",
742 "details_url": "u",
743 "status": "s",
744 "conclusion": "c",
745 "started_at": "%s",
746 "completed_at": "%s",
747 "output": {
748 "title": "t",
749 "summary": "s",
750 "text": "t",
751 "annotations_count": 1,
752 "annotations_url": "a",
753 "annotations": [
754 {
755 "path": "p",
756 "start_line": 1,
757 "end_line": 1,
758 "annotation_level": "a",
759 "message": "m",
760 "title": "t",
761 "raw_details": "r"
762 }
763 ],
764 "images": [
765 {
766 "alt": "a",
767 "image_url": "i",
768 "caption": "c"
769 }
770 ]
771 },
772 "name": "n",
773 "check_suite": {
774 "id": 1
775 },
776 "app": {
777 "id": 1,
778 "node_id": "n",
779 "owner": {
780 "login": "l",
781 "id": 1,
782 "node_id": "n",
783 "avatar_url": "a",
784 "url": "u",
785 "events_url": "e",
786 "repos_url": "r"
787 },
788 "name": "n",
789 "description": "d",
790 "external_url": "u",
791 "html_url": "h",
792 "created_at": "%s",
793 "updated_at": "%s"
794 },
795 "pull_requests": [
796 {
797 "id": 1,
798 "number": 1,
799 "url": "u",
800 "head": {
801 "ref": "r",
802 "sha": "s",
803 "repo": {
804 "id": 1,
805 "name": "n",
806 "url": "s"
807 }
808 },
809 "base": {
810 "ref": "r",
811 "sha": "s",
812 "repo": {
813 "id": 1,
814 "name": "n",
815 "url": "u"
816 }
817 }
818 }
819 ]
820 }`, ts, ts, ts, ts)
821
822 testJSONMarshal(t, &c, w)
823 }
824
825 func Test_CheckSuiteMarshal(t *testing.T) {
826 testJSONMarshal(t, &CheckSuite{}, "{}")
827
828 now := time.Now()
829 ts := now.Format(time.RFC3339Nano)
830
831 c := CheckSuite{
832 ID: Int64(1),
833 NodeID: String("n"),
834 HeadBranch: String("h"),
835 HeadSHA: String("h"),
836 URL: String("u"),
837 BeforeSHA: String("b"),
838 AfterSHA: String("a"),
839 Status: String("s"),
840 Conclusion: String("c"),
841 App: &App{
842 ID: Int64(1),
843 NodeID: String("n"),
844 Owner: &User{
845 Login: String("l"),
846 ID: Int64(1),
847 NodeID: String("n"),
848 URL: String("u"),
849 ReposURL: String("r"),
850 EventsURL: String("e"),
851 AvatarURL: String("a"),
852 },
853 Name: String("n"),
854 Description: String("d"),
855 HTMLURL: String("h"),
856 ExternalURL: String("u"),
857 CreatedAt: &Timestamp{now},
858 UpdatedAt: &Timestamp{now},
859 },
860 Repository: &Repository{
861 ID: Int64(1),
862 },
863 PullRequests: []*PullRequest{
864 {
865 URL: String("u"),
866 ID: Int64(1),
867 Number: Int(1),
868 Head: &PullRequestBranch{
869 Ref: String("r"),
870 SHA: String("s"),
871 Repo: &Repository{
872 ID: Int64(1),
873 URL: String("s"),
874 Name: String("n"),
875 },
876 },
877 Base: &PullRequestBranch{
878 Ref: String("r"),
879 SHA: String("s"),
880 Repo: &Repository{
881 ID: Int64(1),
882 URL: String("u"),
883 Name: String("n"),
884 },
885 },
886 },
887 },
888 HeadCommit: &Commit{
889 SHA: String("s"),
890 },
891 }
892
893 w := fmt.Sprintf(`{
894 "id": 1,
895 "node_id": "n",
896 "head_branch": "h",
897 "head_sha": "h",
898 "url": "u",
899 "before": "b",
900 "after": "a",
901 "status": "s",
902 "conclusion": "c",
903 "app": {
904 "id": 1,
905 "node_id": "n",
906 "owner": {
907 "login": "l",
908 "id": 1,
909 "node_id": "n",
910 "avatar_url": "a",
911 "url": "u",
912 "events_url": "e",
913 "repos_url": "r"
914 },
915 "name": "n",
916 "description": "d",
917 "external_url": "u",
918 "html_url": "h",
919 "created_at": "%s",
920 "updated_at": "%s"
921 },
922 "repository": {
923 "id": 1
924 },
925 "pull_requests": [
926 {
927 "id": 1,
928 "number": 1,
929 "url": "u",
930 "head": {
931 "ref": "r",
932 "sha": "s",
933 "repo": {
934 "id": 1,
935 "name": "n",
936 "url": "s"
937 }
938 },
939 "base": {
940 "ref": "r",
941 "sha": "s",
942 "repo": {
943 "id": 1,
944 "name": "n",
945 "url": "u"
946 }
947 }
948 }
949 ],
950 "head_commit": {
951 "sha": "s"
952 }
953 }`, ts, ts)
954
955 testJSONMarshal(t, &c, w)
956 }
957
958 func TestCheckRunAnnotation_Marshal(t *testing.T) {
959 testJSONMarshal(t, &CheckRunAnnotation{}, "{}")
960
961 u := &CheckRunAnnotation{
962 Path: String("p"),
963 StartLine: Int(1),
964 EndLine: Int(1),
965 StartColumn: Int(1),
966 EndColumn: Int(1),
967 AnnotationLevel: String("al"),
968 Message: String("m"),
969 Title: String("t"),
970 RawDetails: String("rd"),
971 }
972
973 want := `{
974 "path": "p",
975 "start_line": 1,
976 "end_line": 1,
977 "start_column": 1,
978 "end_column": 1,
979 "annotation_level": "al",
980 "message": "m",
981 "title": "t",
982 "raw_details": "rd"
983 }`
984
985 testJSONMarshal(t, u, want)
986 }
987
988 func TestCheckRunImage_Marshal(t *testing.T) {
989 testJSONMarshal(t, &CheckRunImage{}, "{}")
990
991 u := &CheckRunImage{
992 Alt: String("a"),
993 ImageURL: String("i"),
994 Caption: String("c"),
995 }
996
997 want := `{
998 "alt": "a",
999 "image_url": "i",
1000 "caption": "c"
1001 }`
1002
1003 testJSONMarshal(t, u, want)
1004 }
1005
1006 func TestCheckRunAction_Marshal(t *testing.T) {
1007 testJSONMarshal(t, &CheckRunAction{}, "{}")
1008
1009 u := &CheckRunAction{
1010 Label: "l",
1011 Description: "d",
1012 Identifier: "i",
1013 }
1014
1015 want := `{
1016 "label": "l",
1017 "description": "d",
1018 "identifier": "i"
1019 }`
1020
1021 testJSONMarshal(t, u, want)
1022 }
1023
1024 func TestAutoTriggerCheck_Marshal(t *testing.T) {
1025 testJSONMarshal(t, &AutoTriggerCheck{}, "{}")
1026
1027 u := &AutoTriggerCheck{
1028 AppID: Int64(1),
1029 Setting: Bool(false),
1030 }
1031
1032 want := `{
1033 "app_id": 1,
1034 "setting": false
1035 }`
1036
1037 testJSONMarshal(t, u, want)
1038 }
1039
1040 func TestCreateCheckSuiteOptions_Marshal(t *testing.T) {
1041 testJSONMarshal(t, &CreateCheckSuiteOptions{}, "{}")
1042
1043 u := &CreateCheckSuiteOptions{
1044 HeadSHA: "hsha",
1045 HeadBranch: String("hb"),
1046 }
1047
1048 want := `{
1049 "head_sha": "hsha",
1050 "head_branch": "hb"
1051 }`
1052
1053 testJSONMarshal(t, u, want)
1054 }
1055
1056 func TestCheckRunOutput_Marshal(t *testing.T) {
1057 testJSONMarshal(t, &CheckRunOutput{}, "{}")
1058
1059 u := &CheckRunOutput{
1060 Title: String("ti"),
1061 Summary: String("s"),
1062 Text: String("t"),
1063 AnnotationsCount: Int(1),
1064 AnnotationsURL: String("au"),
1065 Annotations: []*CheckRunAnnotation{
1066 {
1067 Path: String("p"),
1068 StartLine: Int(1),
1069 EndLine: Int(1),
1070 StartColumn: Int(1),
1071 EndColumn: Int(1),
1072 AnnotationLevel: String("al"),
1073 Message: String("m"),
1074 Title: String("t"),
1075 RawDetails: String("rd"),
1076 },
1077 },
1078 Images: []*CheckRunImage{
1079 {
1080 Alt: String("a"),
1081 ImageURL: String("i"),
1082 Caption: String("c"),
1083 },
1084 },
1085 }
1086
1087 want := `{
1088 "title": "ti",
1089 "summary": "s",
1090 "text": "t",
1091 "annotations_count": 1,
1092 "annotations_url": "au",
1093 "annotations": [
1094 {
1095 "path": "p",
1096 "start_line": 1,
1097 "end_line": 1,
1098 "start_column": 1,
1099 "end_column": 1,
1100 "annotation_level": "al",
1101 "message": "m",
1102 "title": "t",
1103 "raw_details": "rd"
1104 }
1105 ],
1106 "images": [
1107 {
1108 "alt": "a",
1109 "image_url": "i",
1110 "caption": "c"
1111 }
1112 ]
1113 }`
1114
1115 testJSONMarshal(t, u, want)
1116 }
1117
1118 func TestCreateCheckRunOptions_Marshal(t *testing.T) {
1119 testJSONMarshal(t, &CreateCheckRunOptions{}, "{}")
1120
1121 u := &CreateCheckRunOptions{
1122 Name: "n",
1123 HeadSHA: "hsha",
1124 DetailsURL: String("durl"),
1125 ExternalID: String("eid"),
1126 Status: String("s"),
1127 Conclusion: String("c"),
1128 StartedAt: &Timestamp{referenceTime},
1129 CompletedAt: &Timestamp{referenceTime},
1130 Output: &CheckRunOutput{
1131 Title: String("ti"),
1132 Summary: String("s"),
1133 Text: String("t"),
1134 AnnotationsCount: Int(1),
1135 AnnotationsURL: String("au"),
1136 Annotations: []*CheckRunAnnotation{
1137 {
1138 Path: String("p"),
1139 StartLine: Int(1),
1140 EndLine: Int(1),
1141 StartColumn: Int(1),
1142 EndColumn: Int(1),
1143 AnnotationLevel: String("al"),
1144 Message: String("m"),
1145 Title: String("t"),
1146 RawDetails: String("rd"),
1147 },
1148 },
1149 Images: []*CheckRunImage{
1150 {
1151 Alt: String("a"),
1152 ImageURL: String("i"),
1153 Caption: String("c"),
1154 },
1155 },
1156 },
1157 Actions: []*CheckRunAction{
1158 {
1159 Label: "l",
1160 Description: "d",
1161 Identifier: "i",
1162 },
1163 },
1164 }
1165
1166 want := `{
1167 "name": "n",
1168 "head_sha": "hsha",
1169 "details_url": "durl",
1170 "external_id": "eid",
1171 "status": "s",
1172 "conclusion": "c",
1173 "started_at": ` + referenceTimeStr + `,
1174 "completed_at": ` + referenceTimeStr + `,
1175 "output": {
1176 "title": "ti",
1177 "summary": "s",
1178 "text": "t",
1179 "annotations_count": 1,
1180 "annotations_url": "au",
1181 "annotations": [
1182 {
1183 "path": "p",
1184 "start_line": 1,
1185 "end_line": 1,
1186 "start_column": 1,
1187 "end_column": 1,
1188 "annotation_level": "al",
1189 "message": "m",
1190 "title": "t",
1191 "raw_details": "rd"
1192 }
1193 ],
1194 "images": [
1195 {
1196 "alt": "a",
1197 "image_url": "i",
1198 "caption": "c"
1199 }
1200 ]
1201 },
1202 "actions": [
1203 {
1204 "label": "l",
1205 "description": "d",
1206 "identifier": "i"
1207 }
1208 ]
1209 }`
1210
1211 testJSONMarshal(t, u, want)
1212 }
1213
1214 func TestUpdateCheckRunOptions_Marshal(t *testing.T) {
1215 testJSONMarshal(t, &UpdateCheckRunOptions{}, "{}")
1216
1217 u := &UpdateCheckRunOptions{
1218 Name: "n",
1219 DetailsURL: String("durl"),
1220 ExternalID: String("eid"),
1221 Status: String("s"),
1222 Conclusion: String("c"),
1223 CompletedAt: &Timestamp{referenceTime},
1224 Output: &CheckRunOutput{
1225 Title: String("ti"),
1226 Summary: String("s"),
1227 Text: String("t"),
1228 AnnotationsCount: Int(1),
1229 AnnotationsURL: String("au"),
1230 Annotations: []*CheckRunAnnotation{
1231 {
1232 Path: String("p"),
1233 StartLine: Int(1),
1234 EndLine: Int(1),
1235 StartColumn: Int(1),
1236 EndColumn: Int(1),
1237 AnnotationLevel: String("al"),
1238 Message: String("m"),
1239 Title: String("t"),
1240 RawDetails: String("rd"),
1241 },
1242 },
1243 Images: []*CheckRunImage{
1244 {
1245 Alt: String("a"),
1246 ImageURL: String("i"),
1247 Caption: String("c"),
1248 },
1249 },
1250 },
1251 Actions: []*CheckRunAction{
1252 {
1253 Label: "l",
1254 Description: "d",
1255 Identifier: "i",
1256 },
1257 },
1258 }
1259
1260 want := `{
1261 "name": "n",
1262 "details_url": "durl",
1263 "external_id": "eid",
1264 "status": "s",
1265 "conclusion": "c",
1266 "completed_at": ` + referenceTimeStr + `,
1267 "output": {
1268 "title": "ti",
1269 "summary": "s",
1270 "text": "t",
1271 "annotations_count": 1,
1272 "annotations_url": "au",
1273 "annotations": [
1274 {
1275 "path": "p",
1276 "start_line": 1,
1277 "end_line": 1,
1278 "start_column": 1,
1279 "end_column": 1,
1280 "annotation_level": "al",
1281 "message": "m",
1282 "title": "t",
1283 "raw_details": "rd"
1284 }
1285 ],
1286 "images": [
1287 {
1288 "alt": "a",
1289 "image_url": "i",
1290 "caption": "c"
1291 }
1292 ]
1293 },
1294 "actions": [
1295 {
1296 "label": "l",
1297 "description": "d",
1298 "identifier": "i"
1299 }
1300 ]
1301 }`
1302
1303 testJSONMarshal(t, u, want)
1304 }
1305
1306 func TestListCheckRunsResults_Marshal(t *testing.T) {
1307 testJSONMarshal(t, &ListCheckRunsResults{}, "{}")
1308
1309 l := &ListCheckRunsResults{
1310 Total: Int(1),
1311 CheckRuns: []*CheckRun{
1312 {
1313 ID: Int64(1),
1314 NodeID: String("n"),
1315 HeadSHA: String("h"),
1316 ExternalID: String("1"),
1317 URL: String("u"),
1318 HTMLURL: String("u"),
1319 DetailsURL: String("u"),
1320 Status: String("s"),
1321 Conclusion: String("c"),
1322 StartedAt: &Timestamp{referenceTime},
1323 CompletedAt: &Timestamp{referenceTime},
1324 Output: &CheckRunOutput{
1325 Annotations: []*CheckRunAnnotation{
1326 {
1327 AnnotationLevel: String("a"),
1328 EndLine: Int(1),
1329 Message: String("m"),
1330 Path: String("p"),
1331 RawDetails: String("r"),
1332 StartLine: Int(1),
1333 Title: String("t"),
1334 },
1335 },
1336 AnnotationsCount: Int(1),
1337 AnnotationsURL: String("a"),
1338 Images: []*CheckRunImage{
1339 {
1340 Alt: String("a"),
1341 ImageURL: String("i"),
1342 Caption: String("c"),
1343 },
1344 },
1345 Title: String("t"),
1346 Summary: String("s"),
1347 Text: String("t"),
1348 },
1349 Name: String("n"),
1350 CheckSuite: &CheckSuite{
1351 ID: Int64(1),
1352 },
1353 App: &App{
1354 ID: Int64(1),
1355 NodeID: String("n"),
1356 Owner: &User{
1357 Login: String("l"),
1358 ID: Int64(1),
1359 NodeID: String("n"),
1360 URL: String("u"),
1361 ReposURL: String("r"),
1362 EventsURL: String("e"),
1363 AvatarURL: String("a"),
1364 },
1365 Name: String("n"),
1366 Description: String("d"),
1367 HTMLURL: String("h"),
1368 ExternalURL: String("u"),
1369 CreatedAt: &Timestamp{referenceTime},
1370 UpdatedAt: &Timestamp{referenceTime},
1371 },
1372 PullRequests: []*PullRequest{
1373 {
1374 URL: String("u"),
1375 ID: Int64(1),
1376 Number: Int(1),
1377 Head: &PullRequestBranch{
1378 Ref: String("r"),
1379 SHA: String("s"),
1380 Repo: &Repository{
1381 ID: Int64(1),
1382 URL: String("s"),
1383 Name: String("n"),
1384 },
1385 },
1386 Base: &PullRequestBranch{
1387 Ref: String("r"),
1388 SHA: String("s"),
1389 Repo: &Repository{
1390 ID: Int64(1),
1391 URL: String("u"),
1392 Name: String("n"),
1393 },
1394 },
1395 },
1396 },
1397 },
1398 },
1399 }
1400
1401 w := `{
1402 "total_count": 1,
1403 "check_runs": [
1404 {
1405 "id": 1,
1406 "node_id": "n",
1407 "head_sha": "h",
1408 "external_id": "1",
1409 "url": "u",
1410 "html_url": "u",
1411 "details_url": "u",
1412 "status": "s",
1413 "conclusion": "c",
1414 "started_at": ` + referenceTimeStr + `,
1415 "completed_at": ` + referenceTimeStr + `,
1416 "output": {
1417 "title": "t",
1418 "summary": "s",
1419 "text": "t",
1420 "annotations_count": 1,
1421 "annotations_url": "a",
1422 "annotations": [
1423 {
1424 "path": "p",
1425 "start_line": 1,
1426 "end_line": 1,
1427 "annotation_level": "a",
1428 "message": "m",
1429 "title": "t",
1430 "raw_details": "r"
1431 }
1432 ],
1433 "images": [
1434 {
1435 "alt": "a",
1436 "image_url": "i",
1437 "caption": "c"
1438 }
1439 ]
1440 },
1441 "name": "n",
1442 "check_suite": {
1443 "id": 1
1444 },
1445 "app": {
1446 "id": 1,
1447 "node_id": "n",
1448 "owner": {
1449 "login": "l",
1450 "id": 1,
1451 "node_id": "n",
1452 "avatar_url": "a",
1453 "url": "u",
1454 "events_url": "e",
1455 "repos_url": "r"
1456 },
1457 "name": "n",
1458 "description": "d",
1459 "external_url": "u",
1460 "html_url": "h",
1461 "created_at": ` + referenceTimeStr + `,
1462 "updated_at": ` + referenceTimeStr + `
1463 },
1464 "pull_requests": [
1465 {
1466 "id": 1,
1467 "number": 1,
1468 "url": "u",
1469 "head": {
1470 "ref": "r",
1471 "sha": "s",
1472 "repo": {
1473 "id": 1,
1474 "name": "n",
1475 "url": "s"
1476 }
1477 },
1478 "base": {
1479 "ref": "r",
1480 "sha": "s",
1481 "repo": {
1482 "id": 1,
1483 "name": "n",
1484 "url": "u"
1485 }
1486 }
1487 }
1488 ]
1489 }
1490 ]
1491 }`
1492
1493 testJSONMarshal(t, &l, w)
1494 }
1495
1496 func TestListCheckSuiteResults_Marshal(t *testing.T) {
1497 testJSONMarshal(t, &ListCheckSuiteResults{}, "{}")
1498
1499 l := &ListCheckSuiteResults{
1500 Total: Int(1),
1501 CheckSuites: []*CheckSuite{
1502 {
1503 ID: Int64(1),
1504 NodeID: String("n"),
1505 HeadBranch: String("h"),
1506 HeadSHA: String("h"),
1507 URL: String("u"),
1508 BeforeSHA: String("b"),
1509 AfterSHA: String("a"),
1510 Status: String("s"),
1511 Conclusion: String("c"),
1512 App: &App{
1513 ID: Int64(1),
1514 NodeID: String("n"),
1515 Owner: &User{
1516 Login: String("l"),
1517 ID: Int64(1),
1518 NodeID: String("n"),
1519 URL: String("u"),
1520 ReposURL: String("r"),
1521 EventsURL: String("e"),
1522 AvatarURL: String("a"),
1523 },
1524 Name: String("n"),
1525 Description: String("d"),
1526 HTMLURL: String("h"),
1527 ExternalURL: String("u"),
1528 CreatedAt: &Timestamp{referenceTime},
1529 UpdatedAt: &Timestamp{referenceTime},
1530 },
1531 Repository: &Repository{
1532 ID: Int64(1),
1533 },
1534 PullRequests: []*PullRequest{
1535 {
1536 URL: String("u"),
1537 ID: Int64(1),
1538 Number: Int(1),
1539 Head: &PullRequestBranch{
1540 Ref: String("r"),
1541 SHA: String("s"),
1542 Repo: &Repository{
1543 ID: Int64(1),
1544 URL: String("s"),
1545 Name: String("n"),
1546 },
1547 },
1548 Base: &PullRequestBranch{
1549 Ref: String("r"),
1550 SHA: String("s"),
1551 Repo: &Repository{
1552 ID: Int64(1),
1553 URL: String("u"),
1554 Name: String("n"),
1555 },
1556 },
1557 },
1558 },
1559 HeadCommit: &Commit{
1560 SHA: String("s"),
1561 },
1562 },
1563 },
1564 }
1565
1566 w := `{
1567 "total_count": 1,
1568 "check_suites": [
1569 {
1570 "id": 1,
1571 "node_id": "n",
1572 "head_branch": "h",
1573 "head_sha": "h",
1574 "url": "u",
1575 "before": "b",
1576 "after": "a",
1577 "status": "s",
1578 "conclusion": "c",
1579 "app": {
1580 "id": 1,
1581 "node_id": "n",
1582 "owner": {
1583 "login": "l",
1584 "id": 1,
1585 "node_id": "n",
1586 "avatar_url": "a",
1587 "url": "u",
1588 "events_url": "e",
1589 "repos_url": "r"
1590 },
1591 "name": "n",
1592 "description": "d",
1593 "external_url": "u",
1594 "html_url": "h",
1595 "created_at": ` + referenceTimeStr + `,
1596 "updated_at": ` + referenceTimeStr + `
1597 },
1598 "repository": {
1599 "id": 1
1600 },
1601 "pull_requests": [
1602 {
1603 "id": 1,
1604 "number": 1,
1605 "url": "u",
1606 "head": {
1607 "ref": "r",
1608 "sha": "s",
1609 "repo": {
1610 "id": 1,
1611 "name": "n",
1612 "url": "s"
1613 }
1614 },
1615 "base": {
1616 "ref": "r",
1617 "sha": "s",
1618 "repo": {
1619 "id": 1,
1620 "name": "n",
1621 "url": "u"
1622 }
1623 }
1624 }
1625 ],
1626 "head_commit": {
1627 "sha": "s"
1628 }
1629 }
1630 ]
1631 }`
1632
1633 testJSONMarshal(t, &l, w)
1634 }
1635
1636 func TestCheckSuitePreferenceOptions_Marshal(t *testing.T) {
1637 testJSONMarshal(t, &CheckSuitePreferenceOptions{}, "{}")
1638
1639 u := &CheckSuitePreferenceOptions{
1640 AutoTriggerChecks: []*AutoTriggerCheck{
1641 {
1642 AppID: Int64(1),
1643 Setting: Bool(false),
1644 },
1645 },
1646 }
1647
1648 want := `{
1649 "auto_trigger_checks": [
1650 {
1651 "app_id": 1,
1652 "setting": false
1653 }
1654 ]
1655 }`
1656
1657 testJSONMarshal(t, u, want)
1658 }
1659
1660 func TestPreferenceList_Marshal(t *testing.T) {
1661 testJSONMarshal(t, &PreferenceList{}, "{}")
1662
1663 u := &PreferenceList{
1664 AutoTriggerChecks: []*AutoTriggerCheck{
1665 {
1666 AppID: Int64(1),
1667 Setting: Bool(false),
1668 },
1669 },
1670 }
1671
1672 want := `{
1673 "auto_trigger_checks": [
1674 {
1675 "app_id": 1,
1676 "setting": false
1677 }
1678 ]
1679 }`
1680
1681 testJSONMarshal(t, u, want)
1682 }
1683
1684 func TestCheckSuitePreferenceResults_Marshal(t *testing.T) {
1685 testJSONMarshal(t, &CheckSuitePreferenceResults{}, "{}")
1686
1687 u := &CheckSuitePreferenceResults{
1688 Preferences: &PreferenceList{
1689 AutoTriggerChecks: []*AutoTriggerCheck{
1690 {
1691 AppID: Int64(1),
1692 Setting: Bool(false),
1693 },
1694 },
1695 },
1696 Repository: &Repository{
1697 ID: Int64(1),
1698 URL: String("u"),
1699 Name: String("n"),
1700 },
1701 }
1702
1703 want := `{
1704 "preferences": {
1705 "auto_trigger_checks": [
1706 {
1707 "app_id": 1,
1708 "setting": false
1709 }
1710 ]
1711 },
1712 "repository": {
1713 "id":1,
1714 "name":"n",
1715 "url":"u"
1716 }
1717 }`
1718
1719 testJSONMarshal(t, u, want)
1720 }
1721
1722 func TestChecksService_ReRequestCheckRun(t *testing.T) {
1723 client, mux, _, teardown := setup()
1724 defer teardown()
1725
1726 mux.HandleFunc("/repos/o/r/check-runs/1/rerequest", func(w http.ResponseWriter, r *http.Request) {
1727 testMethod(t, r, "POST")
1728 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
1729 w.WriteHeader(http.StatusCreated)
1730 })
1731 ctx := context.Background()
1732 resp, err := client.Checks.ReRequestCheckRun(ctx, "o", "r", 1)
1733 if err != nil {
1734 t.Errorf("Checks.ReRequestCheckRun return error: %v", err)
1735 }
1736 if got, want := resp.StatusCode, http.StatusCreated; got != want {
1737 t.Errorf("Checks.ReRequestCheckRun = %v, want %v", got, want)
1738 }
1739
1740 const methodName = "ReRequestCheckRun"
1741 testBadOptions(t, methodName, func() (err error) {
1742 _, err = client.Checks.ReRequestCheckRun(ctx, "\n", "\n", 1)
1743 return err
1744 })
1745 }
1746
View as plain text