@@ -6,6 +6,7 @@ package tfe
6
6
import (
7
7
"context"
8
8
"fmt"
9
+ "os"
9
10
"testing"
10
11
11
12
"github.com/stretchr/testify/assert"
@@ -514,6 +515,112 @@ func TestNotificationConfigurationRead_forTeams(t *testing.T) {
514
515
})
515
516
}
516
517
518
+ func TestNotificationConfigurationReadDeliveryResponses (t * testing.T ) {
519
+ client := testClient (t )
520
+ ctx := context .Background ()
521
+
522
+ runTaskURL := os .Getenv ("TFC_RUN_TASK_URL" )
523
+ if runTaskURL == "" {
524
+ t .Skip ("Cannot create a notification configuration with an empty URL. You must set TFC_RUN_TASK_URL for run task related tests." )
525
+ }
526
+
527
+ options := & NotificationConfigurationCreateOptions {
528
+ DestinationType : NotificationDestination (NotificationDestinationTypeGeneric ),
529
+ Enabled : Bool (true ),
530
+ Name : String (randomString (t )),
531
+ Token : String (randomString (t )),
532
+ URL : String (runTaskURL ),
533
+ Triggers : []NotificationTriggerType {NotificationTriggerCreated },
534
+ }
535
+
536
+ t .Run ("with notification configuration create" , func (t * testing.T ) {
537
+ ncTest , ncTestCleanup := createNotificationConfiguration (t , client , nil , options )
538
+ defer ncTestCleanup ()
539
+
540
+ assert .Equal (t , 1 , len (ncTest .DeliveryResponses ))
541
+ assert .NotNil (t , ncTest .DeliveryResponses [0 ])
542
+ assert .NotEmpty (t , ncTest .DeliveryResponses [0 ].Code )
543
+ })
544
+
545
+ t .Run ("with notification configuration list" , func (t * testing.T ) {
546
+ wTest , wTestCleanup := createWorkspace (t , client , nil )
547
+ defer wTestCleanup ()
548
+
549
+ ncTest1 , ncTestCleanup1 := createNotificationConfiguration (t , client , wTest , options )
550
+ defer ncTestCleanup1 ()
551
+ ncTest2 , ncTestCleanup2 := createNotificationConfiguration (t , client , wTest , options )
552
+ defer ncTestCleanup2 ()
553
+
554
+ ncl , err := client .NotificationConfigurations .List (
555
+ ctx ,
556
+ wTest .ID ,
557
+ nil ,
558
+ )
559
+ require .NoError (t , err )
560
+ assert .Contains (t , ncl .Items , ncTest1 )
561
+ assert .Contains (t , ncl .Items , ncTest2 )
562
+
563
+ assert .NotNil (t , ncl .Items [0 ].DeliveryResponses )
564
+ assert .NotEmpty (t , ncl .Items [0 ].DeliveryResponses )
565
+ assert .NotNil (t , ncl .Items [1 ].DeliveryResponses )
566
+ assert .NotEmpty (t , ncl .Items [1 ].DeliveryResponses )
567
+ })
568
+
569
+ t .Run ("with notification configuration read" , func (t * testing.T ) {
570
+ ncTest , ncTestCleanup := createNotificationConfiguration (t , client , nil , options )
571
+ defer ncTestCleanup ()
572
+
573
+ nc , err := client .NotificationConfigurations .Read (ctx , ncTest .ID )
574
+ require .NoError (t , err )
575
+ assert .Equal (t , ncTest .ID , nc .ID )
576
+ assert .Equal (t , 1 , len (nc .DeliveryResponses ))
577
+ assert .NotNil (t , nc .DeliveryResponses [0 ])
578
+ assert .NotEmpty (t , nc .DeliveryResponses [0 ].Code )
579
+ })
580
+
581
+ t .Run ("with notification configuration update" , func (t * testing.T ) {
582
+ ncTest , ncTestCleanup := createNotificationConfiguration (t , client , nil , options )
583
+ defer ncTestCleanup ()
584
+
585
+ optionsUpdate := NotificationConfigurationUpdateOptions {
586
+ Enabled : Bool (true ),
587
+ Name : String ("newName" ),
588
+ }
589
+
590
+ nc , err := client .NotificationConfigurations .Update (ctx , ncTest .ID , optionsUpdate )
591
+ require .NoError (t , err )
592
+
593
+ assert .Equal (t , nc .Name , "newName" )
594
+ assert .Equal (t , ncTest .ID , nc .ID )
595
+ assert .Equal (t , 1 , len (nc .DeliveryResponses ))
596
+ assert .NotNil (t , nc .DeliveryResponses [0 ])
597
+ assert .NotEmpty (t , nc .DeliveryResponses [0 ].Code )
598
+ })
599
+
600
+ t .Run ("with notification configuration verify" , func (t * testing.T ) {
601
+ ncTest , ncTestCleanup := createNotificationConfiguration (t , client , nil , options )
602
+ defer ncTestCleanup ()
603
+
604
+ ncVerifyTest , err := client .NotificationConfigurations .Verify (ctx , ncTest .ID )
605
+ require .NoError (t , err )
606
+
607
+ assert .Equal (t , ncTest .ID , ncVerifyTest .ID )
608
+ assert .Equal (t , 1 , len (ncVerifyTest .DeliveryResponses ))
609
+ assert .NotNil (t , ncVerifyTest .DeliveryResponses [0 ])
610
+ assert .NotEmpty (t , ncVerifyTest .DeliveryResponses [0 ].Code )
611
+ })
612
+
613
+ t .Run ("with notification configuration disabled" , func (t * testing.T ) {
614
+ ncTest , ncTestCleanup := createNotificationConfiguration (t , client , nil , nil )
615
+ defer ncTestCleanup ()
616
+
617
+ nc , err := client .NotificationConfigurations .Read (ctx , ncTest .ID )
618
+ require .NoError (t , err )
619
+ assert .Equal (t , ncTest .ID , nc .ID )
620
+ assert .Equal (t , 0 , len (nc .DeliveryResponses ))
621
+ })
622
+ }
623
+
517
624
func TestNotificationConfigurationUpdate_forTeams (t * testing.T ) {
518
625
skipUnlessBeta (t )
519
626
client := testClient (t )
0 commit comments