@@ -571,6 +571,112 @@ func TestActionService_DeleteWorkflowRunLogs(t *testing.T) {
571
571
})
572
572
}
573
573
574
+ func TestPendingDeployment_Marshal (t * testing.T ) {
575
+ testJSONMarshal (t , & PendingDeployment {}, "{}" )
576
+
577
+ u := & PendingDeployment {
578
+ Environment : & PendingDeploymentEnvironment {
579
+ ID : Int64 (1 ),
580
+ NodeID : String ("nid" ),
581
+ Name : String ("n" ),
582
+ URL : String ("u" ),
583
+ HTMLURL : String ("hu" ),
584
+ },
585
+ WaitTimer : Int64 (100 ),
586
+ WaitTimerStartedAt : & Timestamp {referenceTime },
587
+ CurrentUserCanApprove : Bool (false ),
588
+ Reviewers : []* RequiredReviewer {
589
+ {
590
+ Type : String ("User" ),
591
+ Reviewer : & User {
592
+ Login : String ("l" ),
593
+ },
594
+ },
595
+ {
596
+ Type : String ("Team" ),
597
+ Reviewer : & Team {
598
+ Name : String ("n" ),
599
+ },
600
+ },
601
+ },
602
+ }
603
+ want := `{
604
+ "environment": {
605
+ "id": 1,
606
+ "node_id": "nid",
607
+ "name": "n",
608
+ "url": "u",
609
+ "html_url": "hu"
610
+ },
611
+ "wait_timer": 100,
612
+ "wait_timer_started_at": ` + referenceTimeStr + `,
613
+ "current_user_can_approve": false,
614
+ "reviewers": [
615
+ {
616
+ "type": "User",
617
+ "reviewer": {
618
+ "login": "l"
619
+ }
620
+ },
621
+ {
622
+ "type": "Team",
623
+ "reviewer": {
624
+ "name": "n"
625
+ }
626
+ }
627
+ ]
628
+ }`
629
+ testJSONMarshal (t , u , want )
630
+ }
631
+
632
+ func TestActionsService_ReviewCustomDeploymentProtectionRule (t * testing.T ) {
633
+ client , mux , _ , teardown := setup ()
634
+ defer teardown ()
635
+
636
+ mux .HandleFunc ("/repos/o/r/actions/runs/9444496/deployment_protection_rule" , func (w http.ResponseWriter , r * http.Request ) {
637
+ testMethod (t , r , "POST" )
638
+
639
+ w .WriteHeader (http .StatusNoContent )
640
+ })
641
+
642
+ request := ReviewCustomDeploymentProtectionRuleRequest {
643
+ EnvironmentName : "production" ,
644
+ State : "approved" ,
645
+ Comment : "Approve deployment" ,
646
+ }
647
+
648
+ ctx := context .Background ()
649
+ if _ , err := client .Actions .ReviewCustomDeploymentProtectionRule (ctx , "o" , "r" , 9444496 , & request ); err != nil {
650
+ t .Errorf ("ReviewCustomDeploymentProtectionRule returned error: %v" , err )
651
+ }
652
+
653
+ const methodName = "ReviewCustomDeploymentProtectionRule"
654
+ testBadOptions (t , methodName , func () (err error ) {
655
+ _ , err = client .Actions .ReviewCustomDeploymentProtectionRule (ctx , "\n " , "\n " , 9444496 , & request )
656
+ return err
657
+ })
658
+
659
+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
660
+ return client .Actions .ReviewCustomDeploymentProtectionRule (ctx , "o" , "r" , 9444496 , & request )
661
+ })
662
+ }
663
+
664
+ func TestReviewCustomDeploymentProtectionRuleRequest_Marshal (t * testing.T ) {
665
+ testJSONMarshal (t , & ReviewCustomDeploymentProtectionRuleRequest {}, "{}" )
666
+
667
+ r := & ReviewCustomDeploymentProtectionRuleRequest {
668
+ EnvironmentName : "e" ,
669
+ State : "rejected" ,
670
+ Comment : "c" ,
671
+ }
672
+ want := `{
673
+ "environment_name": "e",
674
+ "state": "rejected",
675
+ "comment": "c"
676
+ }`
677
+ testJSONMarshal (t , r , want )
678
+ }
679
+
574
680
func TestActionsService_GetWorkflowRunUsageByID (t * testing.T ) {
575
681
client , mux , _ , teardown := setup ()
576
682
defer teardown ()
@@ -1298,3 +1404,121 @@ func TestActionService_PendingDeployments(t *testing.T) {
1298
1404
return resp , err
1299
1405
})
1300
1406
}
1407
+
1408
+ func TestActionService_GetPendingDeployments (t * testing.T ) {
1409
+ client , mux , _ , teardown := setup ()
1410
+ defer teardown ()
1411
+
1412
+ mux .HandleFunc ("/repos/o/r/actions/runs/399444496/pending_deployments" , func (w http.ResponseWriter , r * http.Request ) {
1413
+ testMethod (t , r , "GET" )
1414
+ fmt .Fprint (w , `[
1415
+ {
1416
+ "environment": {
1417
+ "id": 1,
1418
+ "node_id": "nid",
1419
+ "name": "n",
1420
+ "url": "u",
1421
+ "html_url": "hu"
1422
+ },
1423
+ "wait_timer": 0,
1424
+ "wait_timer_started_at": ` + referenceTimeStr + `,
1425
+ "current_user_can_approve": false,
1426
+ "reviewers": []
1427
+ },
1428
+ {
1429
+ "environment": {
1430
+ "id": 2,
1431
+ "node_id": "nid",
1432
+ "name": "n",
1433
+ "url": "u",
1434
+ "html_url": "hu"
1435
+ },
1436
+ "wait_timer": 13,
1437
+ "wait_timer_started_at": ` + referenceTimeStr + `,
1438
+ "current_user_can_approve": true,
1439
+ "reviewers": [
1440
+ {
1441
+ "type": "User",
1442
+ "reviewer": {
1443
+ "login": "l"
1444
+ }
1445
+ },
1446
+ {
1447
+ "type": "Team",
1448
+ "reviewer": {
1449
+ "name": "t",
1450
+ "slug": "s"
1451
+ }
1452
+ }
1453
+ ]
1454
+ }
1455
+ ]` )
1456
+ })
1457
+
1458
+ ctx := context .Background ()
1459
+ deployments , _ , err := client .Actions .GetPendingDeployments (ctx , "o" , "r" , 399444496 )
1460
+ if err != nil {
1461
+ t .Errorf ("Actions.GetPendingDeployments returned error: %v" , err )
1462
+ }
1463
+
1464
+ want := []* PendingDeployment {
1465
+ {
1466
+ Environment : & PendingDeploymentEnvironment {
1467
+ ID : Int64 (1 ),
1468
+ NodeID : String ("nid" ),
1469
+ Name : String ("n" ),
1470
+ URL : String ("u" ),
1471
+ HTMLURL : String ("hu" ),
1472
+ },
1473
+ WaitTimer : Int64 (0 ),
1474
+ WaitTimerStartedAt : & Timestamp {referenceTime },
1475
+ CurrentUserCanApprove : Bool (false ),
1476
+ Reviewers : []* RequiredReviewer {},
1477
+ },
1478
+ {
1479
+ Environment : & PendingDeploymentEnvironment {
1480
+ ID : Int64 (2 ),
1481
+ NodeID : String ("nid" ),
1482
+ Name : String ("n" ),
1483
+ URL : String ("u" ),
1484
+ HTMLURL : String ("hu" ),
1485
+ },
1486
+ WaitTimer : Int64 (13 ),
1487
+ WaitTimerStartedAt : & Timestamp {referenceTime },
1488
+ CurrentUserCanApprove : Bool (true ),
1489
+ Reviewers : []* RequiredReviewer {
1490
+ {
1491
+ Type : String ("User" ),
1492
+ Reviewer : & User {
1493
+ Login : String ("l" ),
1494
+ },
1495
+ },
1496
+ {
1497
+ Type : String ("Team" ),
1498
+ Reviewer : & Team {
1499
+ Name : String ("t" ),
1500
+ Slug : String ("s" ),
1501
+ },
1502
+ },
1503
+ },
1504
+ },
1505
+ }
1506
+
1507
+ if ! cmp .Equal (deployments , want ) {
1508
+ t .Errorf ("Actions.GetPendingDeployments returned %+v, want %+v" , deployments , want )
1509
+ }
1510
+
1511
+ const methodName = "GetPendingDeployments"
1512
+ testBadOptions (t , methodName , func () (err error ) {
1513
+ _ , _ , err = client .Actions .GetPendingDeployments (ctx , "\n " , "\n " , 399444496 )
1514
+ return err
1515
+ })
1516
+
1517
+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
1518
+ got , resp , err := client .Actions .GetPendingDeployments (ctx , "o" , "r" , 399444496 )
1519
+ if got != nil {
1520
+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
1521
+ }
1522
+ return resp , err
1523
+ })
1524
+ }
0 commit comments