|
9 | 9 | "fmt" |
10 | 10 | "net/http" |
11 | 11 | "testing" |
| 12 | + "time" |
12 | 13 |
|
13 | 14 | "github.com/google/go-cmp/cmp" |
14 | 15 | ) |
@@ -413,6 +414,149 @@ func TestActionsService_RemoveRepositoryAccessRunnerGroup(t *testing.T) { |
413 | 414 | }) |
414 | 415 | } |
415 | 416 |
|
| 417 | +func TestActionsService_ListRunnerGroupHostedRunners(t *testing.T) { |
| 418 | + t.Parallel() |
| 419 | + client, mux, _ := setup(t) |
| 420 | + |
| 421 | + mux.HandleFunc("/orgs/o/actions/runner-groups/2/hosted-runners", func(w http.ResponseWriter, r *http.Request) { |
| 422 | + testMethod(t, r, "GET") |
| 423 | + testFormValues(t, r, values{"per_page": "2", "page": "2"}) |
| 424 | + fmt.Fprint(w, `{ |
| 425 | + "total_count": 2, |
| 426 | + "runners": [ |
| 427 | + { |
| 428 | + "id": 5, |
| 429 | + "name": "My hosted ubuntu runner", |
| 430 | + "runner_group_id": 2, |
| 431 | + "platform": "linux-x64", |
| 432 | + "image_details": { |
| 433 | + "id": "ubuntu-20.04", |
| 434 | + "size_gb": 86 |
| 435 | + }, |
| 436 | + "machine_size_details": { |
| 437 | + "id": "4-core", |
| 438 | + "cpu_cores": 4, |
| 439 | + "memory_gb": 16, |
| 440 | + "storage_gb": 150 |
| 441 | + }, |
| 442 | + "status": "Ready", |
| 443 | + "maximum_runners": 10, |
| 444 | + "public_ip_enabled": true, |
| 445 | + "public_ips": [ |
| 446 | + { |
| 447 | + "enabled": true, |
| 448 | + "prefix": "20.80.208.150", |
| 449 | + "length": 31 |
| 450 | + } |
| 451 | + ], |
| 452 | + "last_active_on": "2023-04-26T15:23:37Z" |
| 453 | + }, |
| 454 | + { |
| 455 | + "id": 7, |
| 456 | + "name": "My hosted Windows runner", |
| 457 | + "runner_group_id": 2, |
| 458 | + "platform": "win-x64", |
| 459 | + "image_details": { |
| 460 | + "id": "windows-latest", |
| 461 | + "size_gb": 256 |
| 462 | + }, |
| 463 | + "machine_size_details": { |
| 464 | + "id": "8-core", |
| 465 | + "cpu_cores": 8, |
| 466 | + "memory_gb": 32, |
| 467 | + "storage_gb": 300 |
| 468 | + }, |
| 469 | + "status": "Ready", |
| 470 | + "maximum_runners": 20, |
| 471 | + "public_ip_enabled": false, |
| 472 | + "public_ips": [], |
| 473 | + "last_active_on": "2023-04-26T15:23:37Z" |
| 474 | + } |
| 475 | + ] |
| 476 | + }`) |
| 477 | + }) |
| 478 | + |
| 479 | + opts := &ListOptions{Page: 2, PerPage: 2} |
| 480 | + ctx := t.Context() |
| 481 | + runners, _, err := client.Actions.ListRunnerGroupHostedRunners(ctx, "o", 2, opts) |
| 482 | + if err != nil { |
| 483 | + t.Errorf("Actions.ListRunnerGroupHostedRunners returned error: %v", err) |
| 484 | + } |
| 485 | + |
| 486 | + lastActiveOn := Timestamp{time.Date(2023, 4, 26, 15, 23, 37, 0, time.UTC)} |
| 487 | + |
| 488 | + want := &HostedRunners{ |
| 489 | + TotalCount: 2, |
| 490 | + Runners: []*HostedRunner{ |
| 491 | + { |
| 492 | + ID: Ptr(int64(5)), |
| 493 | + Name: Ptr("My hosted ubuntu runner"), |
| 494 | + RunnerGroupID: Ptr(int64(2)), |
| 495 | + Platform: Ptr("linux-x64"), |
| 496 | + ImageDetails: &HostedRunnerImageDetail{ |
| 497 | + ID: Ptr("ubuntu-20.04"), |
| 498 | + SizeGB: Ptr(int64(86)), |
| 499 | + }, |
| 500 | + MachineSizeDetails: &HostedRunnerMachineSpec{ |
| 501 | + ID: "4-core", |
| 502 | + CPUCores: 4, |
| 503 | + MemoryGB: 16, |
| 504 | + StorageGB: 150, |
| 505 | + }, |
| 506 | + Status: Ptr("Ready"), |
| 507 | + MaximumRunners: Ptr(int64(10)), |
| 508 | + PublicIPEnabled: Ptr(true), |
| 509 | + PublicIPs: []*HostedRunnerPublicIP{ |
| 510 | + { |
| 511 | + Enabled: true, |
| 512 | + Prefix: "20.80.208.150", |
| 513 | + Length: 31, |
| 514 | + }, |
| 515 | + }, |
| 516 | + LastActiveOn: Ptr(lastActiveOn), |
| 517 | + }, |
| 518 | + { |
| 519 | + ID: Ptr(int64(7)), |
| 520 | + Name: Ptr("My hosted Windows runner"), |
| 521 | + RunnerGroupID: Ptr(int64(2)), |
| 522 | + Platform: Ptr("win-x64"), |
| 523 | + ImageDetails: &HostedRunnerImageDetail{ |
| 524 | + ID: Ptr("windows-latest"), |
| 525 | + SizeGB: Ptr(int64(256)), |
| 526 | + }, |
| 527 | + MachineSizeDetails: &HostedRunnerMachineSpec{ |
| 528 | + ID: "8-core", |
| 529 | + CPUCores: 8, |
| 530 | + MemoryGB: 32, |
| 531 | + StorageGB: 300, |
| 532 | + }, |
| 533 | + Status: Ptr("Ready"), |
| 534 | + MaximumRunners: Ptr(int64(20)), |
| 535 | + PublicIPEnabled: Ptr(false), |
| 536 | + PublicIPs: []*HostedRunnerPublicIP{}, |
| 537 | + LastActiveOn: Ptr(lastActiveOn), |
| 538 | + }, |
| 539 | + }, |
| 540 | + } |
| 541 | + if !cmp.Equal(runners, want) { |
| 542 | + t.Errorf("Actions.ListRunnerGroupHostedRunners returned %+v, want %+v", runners, want) |
| 543 | + } |
| 544 | + |
| 545 | + const methodName = "ListRunnerGroupHostedRunners" |
| 546 | + testBadOptions(t, methodName, func() (err error) { |
| 547 | + _, _, err = client.Actions.ListRunnerGroupHostedRunners(ctx, "\n", 2, opts) |
| 548 | + return err |
| 549 | + }) |
| 550 | + |
| 551 | + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 552 | + got, resp, err := client.Actions.ListRunnerGroupHostedRunners(ctx, "o", 2, opts) |
| 553 | + if got != nil { |
| 554 | + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 555 | + } |
| 556 | + return resp, err |
| 557 | + }) |
| 558 | +} |
| 559 | + |
416 | 560 | func TestActionsService_ListRunnerGroupRunners(t *testing.T) { |
417 | 561 | t.Parallel() |
418 | 562 | client, mux, _ := setup(t) |
|
0 commit comments