github.com/google/go-github/v69@v69.2.0/github/checks_test.go (about) 1 // Copyright 2018 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 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 t.Parallel() 20 client, mux, _ := setup(t) 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: Ptr(int64(1)), 43 Status: Ptr("completed"), 44 Conclusion: Ptr("neutral"), 45 StartedAt: &Timestamp{startedAt}, 46 CompletedAt: &Timestamp{completeAt}, 47 Name: Ptr("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 t.Parallel() 70 client, mux, _ := setup(t) 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: Ptr(int64(1)), 91 HeadBranch: Ptr("master"), 92 HeadSHA: Ptr("deadbeef"), 93 AfterSHA: Ptr("deadbeefa"), 94 BeforeSHA: Ptr("deadbeefb"), 95 Status: Ptr("completed"), 96 Conclusion: Ptr("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 t.Parallel() 119 client, mux, _ := setup(t) 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: Ptr("in_progress"), 139 StartedAt: &Timestamp{startedAt}, 140 Output: &CheckRunOutput{ 141 Title: Ptr("Mighty test report"), 142 Summary: Ptr(""), 143 Text: Ptr(""), 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: Ptr(int64(1)), 155 Status: Ptr("in_progress"), 156 StartedAt: &Timestamp{startedAt}, 157 HeadSHA: Ptr("deadbeef"), 158 Name: Ptr("testCreateCheckRun"), 159 Output: &CheckRunOutput{ 160 Title: Ptr("Mighty test report"), 161 Summary: Ptr(""), 162 Text: Ptr(""), 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 t.Parallel() 186 client, mux, _ := setup(t) 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: Ptr("README.md"), 215 StartLine: Ptr(2), 216 EndLine: Ptr(2), 217 StartColumn: Ptr(1), 218 EndColumn: Ptr(5), 219 AnnotationLevel: Ptr("warning"), 220 Message: Ptr("Check your spelling for 'banaas'."), 221 Title: Ptr("Spell check"), 222 RawDetails: Ptr("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 t.Parallel() 246 client, mux, _ := setup(t) 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: Ptr("completed"), 264 CompletedAt: &Timestamp{startedAt}, 265 Output: &CheckRunOutput{ 266 Title: Ptr("Mighty test report"), 267 Summary: Ptr("There are 0 failures, 2 warnings and 1 notice"), 268 Text: Ptr("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: Ptr(int64(1)), 280 Status: Ptr("completed"), 281 StartedAt: &Timestamp{startedAt}, 282 CompletedAt: &Timestamp{startedAt}, 283 Conclusion: Ptr("neutral"), 284 Name: Ptr("testUpdateCheckRun"), 285 Output: &CheckRunOutput{ 286 Title: Ptr("Mighty test report"), 287 Summary: Ptr("There are 0 failures, 2 warnings and 1 notice"), 288 Text: Ptr("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 t.Parallel() 312 client, mux, _ := setup(t) 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: Ptr("testing"), 339 Status: Ptr("completed"), 340 Filter: Ptr("all"), 341 AppID: Ptr(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: Ptr(1), 352 CheckRuns: []*CheckRun{{ 353 ID: Ptr(int64(1)), 354 Status: Ptr("completed"), 355 StartedAt: &Timestamp{startedAt}, 356 CompletedAt: &Timestamp{startedAt}, 357 Conclusion: Ptr("neutral"), 358 HeadSHA: Ptr("deadbeef"), 359 App: &App{ID: Ptr(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 t.Parallel() 384 client, mux, _ := setup(t) 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: Ptr("testing"), 408 Status: Ptr("completed"), 409 Filter: Ptr("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: Ptr(1), 420 CheckRuns: []*CheckRun{{ 421 ID: Ptr(int64(1)), 422 Status: Ptr("completed"), 423 StartedAt: &Timestamp{startedAt}, 424 CompletedAt: &Timestamp{startedAt}, 425 Conclusion: Ptr("neutral"), 426 HeadSHA: Ptr("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 t.Parallel() 451 client, mux, _ := setup(t) 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: Ptr("testing"), 475 AppID: Ptr(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: Ptr(1), 485 CheckSuites: []*CheckSuite{{ 486 ID: Ptr(int64(1)), 487 Status: Ptr("completed"), 488 Conclusion: Ptr("neutral"), 489 HeadSHA: Ptr("deadbeef"), 490 HeadBranch: Ptr("master"), 491 BeforeSHA: Ptr("deadbeefb"), 492 AfterSHA: Ptr("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 t.Parallel() 517 client, mux, _ := setup(t) 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: Ptr(int64(2)), 527 Setting: Ptr(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 t.Parallel() 564 client, mux, _ := setup(t) 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: Ptr("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: Ptr(int64(2)), 592 Status: Ptr("completed"), 593 HeadSHA: Ptr("deadbeef"), 594 HeadBranch: Ptr("master"), 595 Conclusion: Ptr("neutral"), 596 BeforeSHA: Ptr("deadbeefb"), 597 AfterSHA: Ptr("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 t.Parallel() 620 client, mux, _ := setup(t) 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 t.Parallel() 645 testJSONMarshal(t, &CheckRun{}, "{}") 646 647 now := time.Now() 648 ts := now.Format(time.RFC3339Nano) 649 650 c := CheckRun{ 651 ID: Ptr(int64(1)), 652 NodeID: Ptr("n"), 653 HeadSHA: Ptr("h"), 654 ExternalID: Ptr("1"), 655 URL: Ptr("u"), 656 HTMLURL: Ptr("u"), 657 DetailsURL: Ptr("u"), 658 Status: Ptr("s"), 659 Conclusion: Ptr("c"), 660 StartedAt: &Timestamp{Time: now}, 661 CompletedAt: &Timestamp{Time: now}, 662 Output: &CheckRunOutput{ 663 Annotations: []*CheckRunAnnotation{ 664 { 665 AnnotationLevel: Ptr("a"), 666 EndLine: Ptr(1), 667 Message: Ptr("m"), 668 Path: Ptr("p"), 669 RawDetails: Ptr("r"), 670 StartLine: Ptr(1), 671 Title: Ptr("t"), 672 }, 673 }, 674 AnnotationsCount: Ptr(1), 675 AnnotationsURL: Ptr("a"), 676 Images: []*CheckRunImage{ 677 { 678 Alt: Ptr("a"), 679 ImageURL: Ptr("i"), 680 Caption: Ptr("c"), 681 }, 682 }, 683 Title: Ptr("t"), 684 Summary: Ptr("s"), 685 Text: Ptr("t"), 686 }, 687 Name: Ptr("n"), 688 CheckSuite: &CheckSuite{ 689 ID: Ptr(int64(1)), 690 }, 691 App: &App{ 692 ID: Ptr(int64(1)), 693 NodeID: Ptr("n"), 694 Owner: &User{ 695 Login: Ptr("l"), 696 ID: Ptr(int64(1)), 697 NodeID: Ptr("n"), 698 URL: Ptr("u"), 699 ReposURL: Ptr("r"), 700 EventsURL: Ptr("e"), 701 AvatarURL: Ptr("a"), 702 }, 703 Name: Ptr("n"), 704 Description: Ptr("d"), 705 HTMLURL: Ptr("h"), 706 ExternalURL: Ptr("u"), 707 CreatedAt: &Timestamp{now}, 708 UpdatedAt: &Timestamp{now}, 709 }, 710 PullRequests: []*PullRequest{ 711 { 712 URL: Ptr("u"), 713 ID: Ptr(int64(1)), 714 Number: Ptr(1), 715 Head: &PullRequestBranch{ 716 Ref: Ptr("r"), 717 SHA: Ptr("s"), 718 Repo: &Repository{ 719 ID: Ptr(int64(1)), 720 URL: Ptr("s"), 721 Name: Ptr("n"), 722 }, 723 }, 724 Base: &PullRequestBranch{ 725 Ref: Ptr("r"), 726 SHA: Ptr("s"), 727 Repo: &Repository{ 728 ID: Ptr(int64(1)), 729 URL: Ptr("u"), 730 Name: Ptr("n"), 731 }, 732 }, 733 }, 734 }, 735 } 736 w := fmt.Sprintf(`{ 737 "id": 1, 738 "node_id": "n", 739 "head_sha": "h", 740 "external_id": "1", 741 "url": "u", 742 "html_url": "u", 743 "details_url": "u", 744 "status": "s", 745 "conclusion": "c", 746 "started_at": "%s", 747 "completed_at": "%s", 748 "output": { 749 "title": "t", 750 "summary": "s", 751 "text": "t", 752 "annotations_count": 1, 753 "annotations_url": "a", 754 "annotations": [ 755 { 756 "path": "p", 757 "start_line": 1, 758 "end_line": 1, 759 "annotation_level": "a", 760 "message": "m", 761 "title": "t", 762 "raw_details": "r" 763 } 764 ], 765 "images": [ 766 { 767 "alt": "a", 768 "image_url": "i", 769 "caption": "c" 770 } 771 ] 772 }, 773 "name": "n", 774 "check_suite": { 775 "id": 1 776 }, 777 "app": { 778 "id": 1, 779 "node_id": "n", 780 "owner": { 781 "login": "l", 782 "id": 1, 783 "node_id": "n", 784 "avatar_url": "a", 785 "url": "u", 786 "events_url": "e", 787 "repos_url": "r" 788 }, 789 "name": "n", 790 "description": "d", 791 "external_url": "u", 792 "html_url": "h", 793 "created_at": "%s", 794 "updated_at": "%s" 795 }, 796 "pull_requests": [ 797 { 798 "id": 1, 799 "number": 1, 800 "url": "u", 801 "head": { 802 "ref": "r", 803 "sha": "s", 804 "repo": { 805 "id": 1, 806 "name": "n", 807 "url": "s" 808 } 809 }, 810 "base": { 811 "ref": "r", 812 "sha": "s", 813 "repo": { 814 "id": 1, 815 "name": "n", 816 "url": "u" 817 } 818 } 819 } 820 ] 821 }`, ts, ts, ts, ts) 822 823 testJSONMarshal(t, &c, w) 824 } 825 826 func Test_CheckSuiteMarshal(t *testing.T) { 827 t.Parallel() 828 testJSONMarshal(t, &CheckSuite{}, "{}") 829 830 now := time.Now() 831 ts := now.Format(time.RFC3339Nano) 832 833 c := CheckSuite{ 834 ID: Ptr(int64(1)), 835 NodeID: Ptr("n"), 836 HeadBranch: Ptr("h"), 837 HeadSHA: Ptr("h"), 838 URL: Ptr("u"), 839 BeforeSHA: Ptr("b"), 840 AfterSHA: Ptr("a"), 841 Status: Ptr("s"), 842 Conclusion: Ptr("c"), 843 App: &App{ 844 ID: Ptr(int64(1)), 845 NodeID: Ptr("n"), 846 Owner: &User{ 847 Login: Ptr("l"), 848 ID: Ptr(int64(1)), 849 NodeID: Ptr("n"), 850 URL: Ptr("u"), 851 ReposURL: Ptr("r"), 852 EventsURL: Ptr("e"), 853 AvatarURL: Ptr("a"), 854 }, 855 Name: Ptr("n"), 856 Description: Ptr("d"), 857 HTMLURL: Ptr("h"), 858 ExternalURL: Ptr("u"), 859 CreatedAt: &Timestamp{now}, 860 UpdatedAt: &Timestamp{now}, 861 }, 862 Repository: &Repository{ 863 ID: Ptr(int64(1)), 864 }, 865 PullRequests: []*PullRequest{ 866 { 867 URL: Ptr("u"), 868 ID: Ptr(int64(1)), 869 Number: Ptr(1), 870 Head: &PullRequestBranch{ 871 Ref: Ptr("r"), 872 SHA: Ptr("s"), 873 Repo: &Repository{ 874 ID: Ptr(int64(1)), 875 URL: Ptr("s"), 876 Name: Ptr("n"), 877 }, 878 }, 879 Base: &PullRequestBranch{ 880 Ref: Ptr("r"), 881 SHA: Ptr("s"), 882 Repo: &Repository{ 883 ID: Ptr(int64(1)), 884 URL: Ptr("u"), 885 Name: Ptr("n"), 886 }, 887 }, 888 }, 889 }, 890 HeadCommit: &Commit{ 891 SHA: Ptr("s"), 892 }, 893 LatestCheckRunsCount: Ptr(int64(1)), 894 Rerequestable: Ptr(true), 895 RunsRerequestable: Ptr(true), 896 } 897 898 w := fmt.Sprintf(`{ 899 "id": 1, 900 "node_id": "n", 901 "head_branch": "h", 902 "head_sha": "h", 903 "url": "u", 904 "before": "b", 905 "after": "a", 906 "status": "s", 907 "conclusion": "c", 908 "app": { 909 "id": 1, 910 "node_id": "n", 911 "owner": { 912 "login": "l", 913 "id": 1, 914 "node_id": "n", 915 "avatar_url": "a", 916 "url": "u", 917 "events_url": "e", 918 "repos_url": "r" 919 }, 920 "name": "n", 921 "description": "d", 922 "external_url": "u", 923 "html_url": "h", 924 "created_at": "%s", 925 "updated_at": "%s" 926 }, 927 "repository": { 928 "id": 1 929 }, 930 "pull_requests": [ 931 { 932 "id": 1, 933 "number": 1, 934 "url": "u", 935 "head": { 936 "ref": "r", 937 "sha": "s", 938 "repo": { 939 "id": 1, 940 "name": "n", 941 "url": "s" 942 } 943 }, 944 "base": { 945 "ref": "r", 946 "sha": "s", 947 "repo": { 948 "id": 1, 949 "name": "n", 950 "url": "u" 951 } 952 } 953 } 954 ], 955 "head_commit": { 956 "sha": "s" 957 }, 958 "latest_check_runs_count": 1, 959 "rerequestable": true, 960 "runs_rerequestable": true 961 }`, ts, ts) 962 963 testJSONMarshal(t, &c, w) 964 } 965 966 func TestCheckRunAnnotation_Marshal(t *testing.T) { 967 t.Parallel() 968 testJSONMarshal(t, &CheckRunAnnotation{}, "{}") 969 970 u := &CheckRunAnnotation{ 971 Path: Ptr("p"), 972 StartLine: Ptr(1), 973 EndLine: Ptr(1), 974 StartColumn: Ptr(1), 975 EndColumn: Ptr(1), 976 AnnotationLevel: Ptr("al"), 977 Message: Ptr("m"), 978 Title: Ptr("t"), 979 RawDetails: Ptr("rd"), 980 } 981 982 want := `{ 983 "path": "p", 984 "start_line": 1, 985 "end_line": 1, 986 "start_column": 1, 987 "end_column": 1, 988 "annotation_level": "al", 989 "message": "m", 990 "title": "t", 991 "raw_details": "rd" 992 }` 993 994 testJSONMarshal(t, u, want) 995 } 996 997 func TestCheckRunImage_Marshal(t *testing.T) { 998 t.Parallel() 999 testJSONMarshal(t, &CheckRunImage{}, "{}") 1000 1001 u := &CheckRunImage{ 1002 Alt: Ptr("a"), 1003 ImageURL: Ptr("i"), 1004 Caption: Ptr("c"), 1005 } 1006 1007 want := `{ 1008 "alt": "a", 1009 "image_url": "i", 1010 "caption": "c" 1011 }` 1012 1013 testJSONMarshal(t, u, want) 1014 } 1015 1016 func TestCheckRunAction_Marshal(t *testing.T) { 1017 t.Parallel() 1018 testJSONMarshal(t, &CheckRunAction{}, "{}") 1019 1020 u := &CheckRunAction{ 1021 Label: "l", 1022 Description: "d", 1023 Identifier: "i", 1024 } 1025 1026 want := `{ 1027 "label": "l", 1028 "description": "d", 1029 "identifier": "i" 1030 }` 1031 1032 testJSONMarshal(t, u, want) 1033 } 1034 1035 func TestAutoTriggerCheck_Marshal(t *testing.T) { 1036 t.Parallel() 1037 testJSONMarshal(t, &AutoTriggerCheck{}, "{}") 1038 1039 u := &AutoTriggerCheck{ 1040 AppID: Ptr(int64(1)), 1041 Setting: Ptr(false), 1042 } 1043 1044 want := `{ 1045 "app_id": 1, 1046 "setting": false 1047 }` 1048 1049 testJSONMarshal(t, u, want) 1050 } 1051 1052 func TestCreateCheckSuiteOptions_Marshal(t *testing.T) { 1053 t.Parallel() 1054 testJSONMarshal(t, &CreateCheckSuiteOptions{}, "{}") 1055 1056 u := &CreateCheckSuiteOptions{ 1057 HeadSHA: "hsha", 1058 HeadBranch: Ptr("hb"), 1059 } 1060 1061 want := `{ 1062 "head_sha": "hsha", 1063 "head_branch": "hb" 1064 }` 1065 1066 testJSONMarshal(t, u, want) 1067 } 1068 1069 func TestCheckRunOutput_Marshal(t *testing.T) { 1070 t.Parallel() 1071 testJSONMarshal(t, &CheckRunOutput{}, "{}") 1072 1073 u := &CheckRunOutput{ 1074 Title: Ptr("ti"), 1075 Summary: Ptr("s"), 1076 Text: Ptr("t"), 1077 AnnotationsCount: Ptr(1), 1078 AnnotationsURL: Ptr("au"), 1079 Annotations: []*CheckRunAnnotation{ 1080 { 1081 Path: Ptr("p"), 1082 StartLine: Ptr(1), 1083 EndLine: Ptr(1), 1084 StartColumn: Ptr(1), 1085 EndColumn: Ptr(1), 1086 AnnotationLevel: Ptr("al"), 1087 Message: Ptr("m"), 1088 Title: Ptr("t"), 1089 RawDetails: Ptr("rd"), 1090 }, 1091 }, 1092 Images: []*CheckRunImage{ 1093 { 1094 Alt: Ptr("a"), 1095 ImageURL: Ptr("i"), 1096 Caption: Ptr("c"), 1097 }, 1098 }, 1099 } 1100 1101 want := `{ 1102 "title": "ti", 1103 "summary": "s", 1104 "text": "t", 1105 "annotations_count": 1, 1106 "annotations_url": "au", 1107 "annotations": [ 1108 { 1109 "path": "p", 1110 "start_line": 1, 1111 "end_line": 1, 1112 "start_column": 1, 1113 "end_column": 1, 1114 "annotation_level": "al", 1115 "message": "m", 1116 "title": "t", 1117 "raw_details": "rd" 1118 } 1119 ], 1120 "images": [ 1121 { 1122 "alt": "a", 1123 "image_url": "i", 1124 "caption": "c" 1125 } 1126 ] 1127 }` 1128 1129 testJSONMarshal(t, u, want) 1130 } 1131 1132 func TestCreateCheckRunOptions_Marshal(t *testing.T) { 1133 t.Parallel() 1134 testJSONMarshal(t, &CreateCheckRunOptions{}, "{}") 1135 1136 u := &CreateCheckRunOptions{ 1137 Name: "n", 1138 HeadSHA: "hsha", 1139 DetailsURL: Ptr("durl"), 1140 ExternalID: Ptr("eid"), 1141 Status: Ptr("s"), 1142 Conclusion: Ptr("c"), 1143 StartedAt: &Timestamp{referenceTime}, 1144 CompletedAt: &Timestamp{referenceTime}, 1145 Output: &CheckRunOutput{ 1146 Title: Ptr("ti"), 1147 Summary: Ptr("s"), 1148 Text: Ptr("t"), 1149 AnnotationsCount: Ptr(1), 1150 AnnotationsURL: Ptr("au"), 1151 Annotations: []*CheckRunAnnotation{ 1152 { 1153 Path: Ptr("p"), 1154 StartLine: Ptr(1), 1155 EndLine: Ptr(1), 1156 StartColumn: Ptr(1), 1157 EndColumn: Ptr(1), 1158 AnnotationLevel: Ptr("al"), 1159 Message: Ptr("m"), 1160 Title: Ptr("t"), 1161 RawDetails: Ptr("rd"), 1162 }, 1163 }, 1164 Images: []*CheckRunImage{ 1165 { 1166 Alt: Ptr("a"), 1167 ImageURL: Ptr("i"), 1168 Caption: Ptr("c"), 1169 }, 1170 }, 1171 }, 1172 Actions: []*CheckRunAction{ 1173 { 1174 Label: "l", 1175 Description: "d", 1176 Identifier: "i", 1177 }, 1178 }, 1179 } 1180 1181 want := `{ 1182 "name": "n", 1183 "head_sha": "hsha", 1184 "details_url": "durl", 1185 "external_id": "eid", 1186 "status": "s", 1187 "conclusion": "c", 1188 "started_at": ` + referenceTimeStr + `, 1189 "completed_at": ` + referenceTimeStr + `, 1190 "output": { 1191 "title": "ti", 1192 "summary": "s", 1193 "text": "t", 1194 "annotations_count": 1, 1195 "annotations_url": "au", 1196 "annotations": [ 1197 { 1198 "path": "p", 1199 "start_line": 1, 1200 "end_line": 1, 1201 "start_column": 1, 1202 "end_column": 1, 1203 "annotation_level": "al", 1204 "message": "m", 1205 "title": "t", 1206 "raw_details": "rd" 1207 } 1208 ], 1209 "images": [ 1210 { 1211 "alt": "a", 1212 "image_url": "i", 1213 "caption": "c" 1214 } 1215 ] 1216 }, 1217 "actions": [ 1218 { 1219 "label": "l", 1220 "description": "d", 1221 "identifier": "i" 1222 } 1223 ] 1224 }` 1225 1226 testJSONMarshal(t, u, want) 1227 } 1228 1229 func TestUpdateCheckRunOptions_Marshal(t *testing.T) { 1230 t.Parallel() 1231 testJSONMarshal(t, &UpdateCheckRunOptions{}, "{}") 1232 1233 u := &UpdateCheckRunOptions{ 1234 Name: "n", 1235 DetailsURL: Ptr("durl"), 1236 ExternalID: Ptr("eid"), 1237 Status: Ptr("s"), 1238 Conclusion: Ptr("c"), 1239 CompletedAt: &Timestamp{referenceTime}, 1240 Output: &CheckRunOutput{ 1241 Title: Ptr("ti"), 1242 Summary: Ptr("s"), 1243 Text: Ptr("t"), 1244 AnnotationsCount: Ptr(1), 1245 AnnotationsURL: Ptr("au"), 1246 Annotations: []*CheckRunAnnotation{ 1247 { 1248 Path: Ptr("p"), 1249 StartLine: Ptr(1), 1250 EndLine: Ptr(1), 1251 StartColumn: Ptr(1), 1252 EndColumn: Ptr(1), 1253 AnnotationLevel: Ptr("al"), 1254 Message: Ptr("m"), 1255 Title: Ptr("t"), 1256 RawDetails: Ptr("rd"), 1257 }, 1258 }, 1259 Images: []*CheckRunImage{ 1260 { 1261 Alt: Ptr("a"), 1262 ImageURL: Ptr("i"), 1263 Caption: Ptr("c"), 1264 }, 1265 }, 1266 }, 1267 Actions: []*CheckRunAction{ 1268 { 1269 Label: "l", 1270 Description: "d", 1271 Identifier: "i", 1272 }, 1273 }, 1274 } 1275 1276 want := `{ 1277 "name": "n", 1278 "details_url": "durl", 1279 "external_id": "eid", 1280 "status": "s", 1281 "conclusion": "c", 1282 "completed_at": ` + referenceTimeStr + `, 1283 "output": { 1284 "title": "ti", 1285 "summary": "s", 1286 "text": "t", 1287 "annotations_count": 1, 1288 "annotations_url": "au", 1289 "annotations": [ 1290 { 1291 "path": "p", 1292 "start_line": 1, 1293 "end_line": 1, 1294 "start_column": 1, 1295 "end_column": 1, 1296 "annotation_level": "al", 1297 "message": "m", 1298 "title": "t", 1299 "raw_details": "rd" 1300 } 1301 ], 1302 "images": [ 1303 { 1304 "alt": "a", 1305 "image_url": "i", 1306 "caption": "c" 1307 } 1308 ] 1309 }, 1310 "actions": [ 1311 { 1312 "label": "l", 1313 "description": "d", 1314 "identifier": "i" 1315 } 1316 ] 1317 }` 1318 1319 testJSONMarshal(t, u, want) 1320 } 1321 1322 func TestListCheckRunsResults_Marshal(t *testing.T) { 1323 t.Parallel() 1324 testJSONMarshal(t, &ListCheckRunsResults{}, "{}") 1325 1326 l := &ListCheckRunsResults{ 1327 Total: Ptr(1), 1328 CheckRuns: []*CheckRun{ 1329 { 1330 ID: Ptr(int64(1)), 1331 NodeID: Ptr("n"), 1332 HeadSHA: Ptr("h"), 1333 ExternalID: Ptr("1"), 1334 URL: Ptr("u"), 1335 HTMLURL: Ptr("u"), 1336 DetailsURL: Ptr("u"), 1337 Status: Ptr("s"), 1338 Conclusion: Ptr("c"), 1339 StartedAt: &Timestamp{referenceTime}, 1340 CompletedAt: &Timestamp{referenceTime}, 1341 Output: &CheckRunOutput{ 1342 Annotations: []*CheckRunAnnotation{ 1343 { 1344 AnnotationLevel: Ptr("a"), 1345 EndLine: Ptr(1), 1346 Message: Ptr("m"), 1347 Path: Ptr("p"), 1348 RawDetails: Ptr("r"), 1349 StartLine: Ptr(1), 1350 Title: Ptr("t"), 1351 }, 1352 }, 1353 AnnotationsCount: Ptr(1), 1354 AnnotationsURL: Ptr("a"), 1355 Images: []*CheckRunImage{ 1356 { 1357 Alt: Ptr("a"), 1358 ImageURL: Ptr("i"), 1359 Caption: Ptr("c"), 1360 }, 1361 }, 1362 Title: Ptr("t"), 1363 Summary: Ptr("s"), 1364 Text: Ptr("t"), 1365 }, 1366 Name: Ptr("n"), 1367 CheckSuite: &CheckSuite{ 1368 ID: Ptr(int64(1)), 1369 }, 1370 App: &App{ 1371 ID: Ptr(int64(1)), 1372 NodeID: Ptr("n"), 1373 Owner: &User{ 1374 Login: Ptr("l"), 1375 ID: Ptr(int64(1)), 1376 NodeID: Ptr("n"), 1377 URL: Ptr("u"), 1378 ReposURL: Ptr("r"), 1379 EventsURL: Ptr("e"), 1380 AvatarURL: Ptr("a"), 1381 }, 1382 Name: Ptr("n"), 1383 Description: Ptr("d"), 1384 HTMLURL: Ptr("h"), 1385 ExternalURL: Ptr("u"), 1386 CreatedAt: &Timestamp{referenceTime}, 1387 UpdatedAt: &Timestamp{referenceTime}, 1388 }, 1389 PullRequests: []*PullRequest{ 1390 { 1391 URL: Ptr("u"), 1392 ID: Ptr(int64(1)), 1393 Number: Ptr(1), 1394 Head: &PullRequestBranch{ 1395 Ref: Ptr("r"), 1396 SHA: Ptr("s"), 1397 Repo: &Repository{ 1398 ID: Ptr(int64(1)), 1399 URL: Ptr("s"), 1400 Name: Ptr("n"), 1401 }, 1402 }, 1403 Base: &PullRequestBranch{ 1404 Ref: Ptr("r"), 1405 SHA: Ptr("s"), 1406 Repo: &Repository{ 1407 ID: Ptr(int64(1)), 1408 URL: Ptr("u"), 1409 Name: Ptr("n"), 1410 }, 1411 }, 1412 }, 1413 }, 1414 }, 1415 }, 1416 } 1417 1418 w := `{ 1419 "total_count": 1, 1420 "check_runs": [ 1421 { 1422 "id": 1, 1423 "node_id": "n", 1424 "head_sha": "h", 1425 "external_id": "1", 1426 "url": "u", 1427 "html_url": "u", 1428 "details_url": "u", 1429 "status": "s", 1430 "conclusion": "c", 1431 "started_at": ` + referenceTimeStr + `, 1432 "completed_at": ` + referenceTimeStr + `, 1433 "output": { 1434 "title": "t", 1435 "summary": "s", 1436 "text": "t", 1437 "annotations_count": 1, 1438 "annotations_url": "a", 1439 "annotations": [ 1440 { 1441 "path": "p", 1442 "start_line": 1, 1443 "end_line": 1, 1444 "annotation_level": "a", 1445 "message": "m", 1446 "title": "t", 1447 "raw_details": "r" 1448 } 1449 ], 1450 "images": [ 1451 { 1452 "alt": "a", 1453 "image_url": "i", 1454 "caption": "c" 1455 } 1456 ] 1457 }, 1458 "name": "n", 1459 "check_suite": { 1460 "id": 1 1461 }, 1462 "app": { 1463 "id": 1, 1464 "node_id": "n", 1465 "owner": { 1466 "login": "l", 1467 "id": 1, 1468 "node_id": "n", 1469 "avatar_url": "a", 1470 "url": "u", 1471 "events_url": "e", 1472 "repos_url": "r" 1473 }, 1474 "name": "n", 1475 "description": "d", 1476 "external_url": "u", 1477 "html_url": "h", 1478 "created_at": ` + referenceTimeStr + `, 1479 "updated_at": ` + referenceTimeStr + ` 1480 }, 1481 "pull_requests": [ 1482 { 1483 "id": 1, 1484 "number": 1, 1485 "url": "u", 1486 "head": { 1487 "ref": "r", 1488 "sha": "s", 1489 "repo": { 1490 "id": 1, 1491 "name": "n", 1492 "url": "s" 1493 } 1494 }, 1495 "base": { 1496 "ref": "r", 1497 "sha": "s", 1498 "repo": { 1499 "id": 1, 1500 "name": "n", 1501 "url": "u" 1502 } 1503 } 1504 } 1505 ] 1506 } 1507 ] 1508 }` 1509 1510 testJSONMarshal(t, &l, w) 1511 } 1512 1513 func TestListCheckSuiteResults_Marshal(t *testing.T) { 1514 t.Parallel() 1515 testJSONMarshal(t, &ListCheckSuiteResults{}, "{}") 1516 1517 l := &ListCheckSuiteResults{ 1518 Total: Ptr(1), 1519 CheckSuites: []*CheckSuite{ 1520 { 1521 ID: Ptr(int64(1)), 1522 NodeID: Ptr("n"), 1523 HeadBranch: Ptr("h"), 1524 HeadSHA: Ptr("h"), 1525 URL: Ptr("u"), 1526 BeforeSHA: Ptr("b"), 1527 AfterSHA: Ptr("a"), 1528 Status: Ptr("s"), 1529 Conclusion: Ptr("c"), 1530 App: &App{ 1531 ID: Ptr(int64(1)), 1532 NodeID: Ptr("n"), 1533 Owner: &User{ 1534 Login: Ptr("l"), 1535 ID: Ptr(int64(1)), 1536 NodeID: Ptr("n"), 1537 URL: Ptr("u"), 1538 ReposURL: Ptr("r"), 1539 EventsURL: Ptr("e"), 1540 AvatarURL: Ptr("a"), 1541 }, 1542 Name: Ptr("n"), 1543 Description: Ptr("d"), 1544 HTMLURL: Ptr("h"), 1545 ExternalURL: Ptr("u"), 1546 CreatedAt: &Timestamp{referenceTime}, 1547 UpdatedAt: &Timestamp{referenceTime}, 1548 }, 1549 Repository: &Repository{ 1550 ID: Ptr(int64(1)), 1551 }, 1552 PullRequests: []*PullRequest{ 1553 { 1554 URL: Ptr("u"), 1555 ID: Ptr(int64(1)), 1556 Number: Ptr(1), 1557 Head: &PullRequestBranch{ 1558 Ref: Ptr("r"), 1559 SHA: Ptr("s"), 1560 Repo: &Repository{ 1561 ID: Ptr(int64(1)), 1562 URL: Ptr("s"), 1563 Name: Ptr("n"), 1564 }, 1565 }, 1566 Base: &PullRequestBranch{ 1567 Ref: Ptr("r"), 1568 SHA: Ptr("s"), 1569 Repo: &Repository{ 1570 ID: Ptr(int64(1)), 1571 URL: Ptr("u"), 1572 Name: Ptr("n"), 1573 }, 1574 }, 1575 }, 1576 }, 1577 HeadCommit: &Commit{ 1578 SHA: Ptr("s"), 1579 }, 1580 }, 1581 }, 1582 } 1583 1584 w := `{ 1585 "total_count": 1, 1586 "check_suites": [ 1587 { 1588 "id": 1, 1589 "node_id": "n", 1590 "head_branch": "h", 1591 "head_sha": "h", 1592 "url": "u", 1593 "before": "b", 1594 "after": "a", 1595 "status": "s", 1596 "conclusion": "c", 1597 "app": { 1598 "id": 1, 1599 "node_id": "n", 1600 "owner": { 1601 "login": "l", 1602 "id": 1, 1603 "node_id": "n", 1604 "avatar_url": "a", 1605 "url": "u", 1606 "events_url": "e", 1607 "repos_url": "r" 1608 }, 1609 "name": "n", 1610 "description": "d", 1611 "external_url": "u", 1612 "html_url": "h", 1613 "created_at": ` + referenceTimeStr + `, 1614 "updated_at": ` + referenceTimeStr + ` 1615 }, 1616 "repository": { 1617 "id": 1 1618 }, 1619 "pull_requests": [ 1620 { 1621 "id": 1, 1622 "number": 1, 1623 "url": "u", 1624 "head": { 1625 "ref": "r", 1626 "sha": "s", 1627 "repo": { 1628 "id": 1, 1629 "name": "n", 1630 "url": "s" 1631 } 1632 }, 1633 "base": { 1634 "ref": "r", 1635 "sha": "s", 1636 "repo": { 1637 "id": 1, 1638 "name": "n", 1639 "url": "u" 1640 } 1641 } 1642 } 1643 ], 1644 "head_commit": { 1645 "sha": "s" 1646 } 1647 } 1648 ] 1649 }` 1650 1651 testJSONMarshal(t, &l, w) 1652 } 1653 1654 func TestCheckSuitePreferenceOptions_Marshal(t *testing.T) { 1655 t.Parallel() 1656 testJSONMarshal(t, &CheckSuitePreferenceOptions{}, "{}") 1657 1658 u := &CheckSuitePreferenceOptions{ 1659 AutoTriggerChecks: []*AutoTriggerCheck{ 1660 { 1661 AppID: Ptr(int64(1)), 1662 Setting: Ptr(false), 1663 }, 1664 }, 1665 } 1666 1667 want := `{ 1668 "auto_trigger_checks": [ 1669 { 1670 "app_id": 1, 1671 "setting": false 1672 } 1673 ] 1674 }` 1675 1676 testJSONMarshal(t, u, want) 1677 } 1678 1679 func TestPreferenceList_Marshal(t *testing.T) { 1680 t.Parallel() 1681 testJSONMarshal(t, &PreferenceList{}, "{}") 1682 1683 u := &PreferenceList{ 1684 AutoTriggerChecks: []*AutoTriggerCheck{ 1685 { 1686 AppID: Ptr(int64(1)), 1687 Setting: Ptr(false), 1688 }, 1689 }, 1690 } 1691 1692 want := `{ 1693 "auto_trigger_checks": [ 1694 { 1695 "app_id": 1, 1696 "setting": false 1697 } 1698 ] 1699 }` 1700 1701 testJSONMarshal(t, u, want) 1702 } 1703 1704 func TestCheckSuitePreferenceResults_Marshal(t *testing.T) { 1705 t.Parallel() 1706 testJSONMarshal(t, &CheckSuitePreferenceResults{}, "{}") 1707 1708 u := &CheckSuitePreferenceResults{ 1709 Preferences: &PreferenceList{ 1710 AutoTriggerChecks: []*AutoTriggerCheck{ 1711 { 1712 AppID: Ptr(int64(1)), 1713 Setting: Ptr(false), 1714 }, 1715 }, 1716 }, 1717 Repository: &Repository{ 1718 ID: Ptr(int64(1)), 1719 URL: Ptr("u"), 1720 Name: Ptr("n"), 1721 }, 1722 } 1723 1724 want := `{ 1725 "preferences": { 1726 "auto_trigger_checks": [ 1727 { 1728 "app_id": 1, 1729 "setting": false 1730 } 1731 ] 1732 }, 1733 "repository": { 1734 "id":1, 1735 "name":"n", 1736 "url":"u" 1737 } 1738 }` 1739 1740 testJSONMarshal(t, u, want) 1741 } 1742 1743 func TestChecksService_ReRequestCheckRun(t *testing.T) { 1744 t.Parallel() 1745 client, mux, _ := setup(t) 1746 1747 mux.HandleFunc("/repos/o/r/check-runs/1/rerequest", func(w http.ResponseWriter, r *http.Request) { 1748 testMethod(t, r, "POST") 1749 testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) 1750 w.WriteHeader(http.StatusCreated) 1751 }) 1752 ctx := context.Background() 1753 resp, err := client.Checks.ReRequestCheckRun(ctx, "o", "r", 1) 1754 if err != nil { 1755 t.Errorf("Checks.ReRequestCheckRun return error: %v", err) 1756 } 1757 if got, want := resp.StatusCode, http.StatusCreated; got != want { 1758 t.Errorf("Checks.ReRequestCheckRun = %v, want %v", got, want) 1759 } 1760 1761 const methodName = "ReRequestCheckRun" 1762 testBadOptions(t, methodName, func() (err error) { 1763 _, err = client.Checks.ReRequestCheckRun(ctx, "\n", "\n", 1) 1764 return err 1765 }) 1766 }