@@ -11,6 +11,7 @@ import (
1111 "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1212 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
1313 "github.com/hashicorp/terraform-plugin-testing/knownvalue"
14+ "github.com/hashicorp/terraform-plugin-testing/plancheck"
1415 "github.com/hashicorp/terraform-plugin-testing/statecheck"
1516 "github.com/hashicorp/terraform-plugin-testing/terraform"
1617 "github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
@@ -373,10 +374,10 @@ func TestAccGithubTeamSettings(t *testing.T) {
373374
374375 resource "github_team_settings" "test" {
375376 team_id = github_team.test.id
377+ notify = true
376378 review_request_delegation {
377379 algorithm = "ROUND_ROBIN"
378380 member_count = 2
379- notify = true
380381 }
381382 }
382383 ` , teamName )
@@ -397,13 +398,22 @@ func TestAccGithubTeamSettings(t *testing.T) {
397398 knownvalue .Int64Exact (2 )),
398399 statecheck .ExpectKnownValue ("github_team_settings.test" ,
399400 tfjsonpath .New ("review_request_delegation" ).AtSliceIndex (0 ).AtMapKey ("notify" ),
401+ knownvalue .Bool (false )),
402+ statecheck .ExpectKnownValue ("github_team_settings.test" ,
403+ tfjsonpath .New ("notify" ),
400404 knownvalue .Bool (true )),
401405 },
402406 },
403407 {
404- ResourceName : "github_team_settings.test" ,
405- ImportState : true ,
406- ImportStateVerify : true ,
408+ ResourceName : "github_team_settings.test" ,
409+ ImportStateKind : resource .ImportBlockWithID ,
410+ ImportState : true ,
411+ ImportPlanChecks : resource.ImportPlanChecks {
412+ PreApply : []plancheck.PlanCheck {
413+ plancheck .ExpectKnownValue ("github_team_settings.test" , tfjsonpath .New ("review_request_delegation" ).AtSliceIndex (0 ).AtMapKey ("notify" ), knownvalue .Bool (false )),
414+ plancheck .ExpectKnownValue ("github_team_settings.test" , tfjsonpath .New ("notify" ), knownvalue .Bool (true )),
415+ },
416+ },
407417 ImportStateIdFunc : func (s * terraform.State ) (string , error ) {
408418 rs , ok := s .RootModule ().Resources ["github_team.test" ]
409419 if ! ok {
@@ -478,6 +488,149 @@ func TestAccGithubTeamSettings(t *testing.T) {
478488 })
479489 })
480490
491+ t .Run ("manages top-level notify without delegation" , func (t * testing.T ) {
492+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
493+ teamName := fmt .Sprintf ("%steam-settings-%s" , testResourcePrefix , randomID )
494+
495+ config := `
496+ resource "github_team" "test" {
497+ name = "%s"
498+ description = "generated by terraform provider automated testing"
499+ }
500+
501+ resource "github_team_settings" "test" {
502+ team_id = "${github_team.test.id}"
503+ notify = %t
504+ }
505+ `
506+
507+ resource .ParallelTest (t , resource.TestCase {
508+ PreCheck : func () { skipUnlessHasOrgs (t ) },
509+ ProviderFactories : providerFactories ,
510+ CheckDestroy : testAccCheckGithubTeamSettingsDestroy ,
511+ Steps : []resource.TestStep {
512+ {
513+ Config : fmt .Sprintf (config , teamName , true ),
514+ ConfigStateChecks : []statecheck.StateCheck {
515+ statecheck .ExpectKnownValue ("github_team_settings.test" ,
516+ tfjsonpath .New ("notify" ),
517+ knownvalue .Bool (true )),
518+ statecheck .ExpectKnownValue ("github_team_settings.test" ,
519+ tfjsonpath .New ("review_request_delegation" ),
520+ knownvalue .ListExact ([]knownvalue.Check {})),
521+ },
522+ },
523+ {
524+ Config : fmt .Sprintf (config , teamName , false ),
525+ ConfigStateChecks : []statecheck.StateCheck {
526+ statecheck .ExpectKnownValue ("github_team_settings.test" ,
527+ tfjsonpath .New ("notify" ),
528+ knownvalue .Bool (false )),
529+ statecheck .ExpectKnownValue ("github_team_settings.test" ,
530+ tfjsonpath .New ("review_request_delegation" ),
531+ knownvalue .ListExact ([]knownvalue.Check {})),
532+ },
533+ },
534+ },
535+ })
536+ })
537+
538+ t .Run ("manages top-level notify with delegation" , func (t * testing.T ) {
539+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
540+ teamName := fmt .Sprintf ("%steam-settings-%s" , testResourcePrefix , randomID )
541+
542+ config := `
543+ resource "github_team" "test" {
544+ name = "%s"
545+ description = "generated by terraform provider automated testing"
546+ }
547+
548+ resource "github_team_settings" "test" {
549+ team_id = "${github_team.test.id}"
550+ notify = %t
551+ review_request_delegation {
552+ algorithm = "ROUND_ROBIN"
553+ member_count = 2
554+ }
555+ }
556+ `
557+
558+ resource .ParallelTest (t , resource.TestCase {
559+ PreCheck : func () { skipUnlessHasOrgs (t ) },
560+ ProviderFactories : providerFactories ,
561+ CheckDestroy : testAccCheckGithubTeamSettingsDestroy ,
562+ Steps : []resource.TestStep {
563+ {
564+ Config : fmt .Sprintf (config , teamName , true ),
565+ ConfigStateChecks : []statecheck.StateCheck {
566+ statecheck .ExpectKnownValue ("github_team_settings.test" ,
567+ tfjsonpath .New ("notify" ),
568+ knownvalue .Bool (true )),
569+ statecheck .ExpectKnownValue ("github_team_settings.test" ,
570+ tfjsonpath .New ("review_request_delegation" ).AtSliceIndex (0 ).AtMapKey ("algorithm" ),
571+ knownvalue .StringExact ("ROUND_ROBIN" )),
572+ statecheck .ExpectKnownValue ("github_team_settings.test" ,
573+ tfjsonpath .New ("review_request_delegation" ).AtSliceIndex (0 ).AtMapKey ("member_count" ),
574+ knownvalue .Int64Exact (2 )),
575+ },
576+ },
577+ {
578+ Config : fmt .Sprintf (config , teamName , false ),
579+ ConfigStateChecks : []statecheck.StateCheck {
580+ statecheck .ExpectKnownValue ("github_team_settings.test" ,
581+ tfjsonpath .New ("notify" ),
582+ knownvalue .Bool (false )),
583+ },
584+ },
585+ },
586+ })
587+ })
588+
589+ t .Run ("imports team settings with top-level notify" , func (t * testing.T ) {
590+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
591+ teamName := fmt .Sprintf ("%steam-settings-%s" , testResourcePrefix , randomID )
592+
593+ config := fmt .Sprintf (`
594+ resource "github_team" "test" {
595+ name = "%s"
596+ description = "generated by terraform provider automated testing"
597+ }
598+
599+ resource "github_team_settings" "test" {
600+ team_id = github_team.test.id
601+ notify = true
602+ }
603+ ` , teamName )
604+
605+ resource .ParallelTest (t , resource.TestCase {
606+ PreCheck : func () { skipUnlessHasOrgs (t ) },
607+ ProviderFactories : providerFactories ,
608+ CheckDestroy : testAccCheckGithubTeamSettingsDestroy ,
609+ Steps : []resource.TestStep {
610+ {
611+ Config : config ,
612+ ConfigStateChecks : []statecheck.StateCheck {
613+ statecheck .ExpectKnownValue ("github_team_settings.test" ,
614+ tfjsonpath .New ("notify" ),
615+ knownvalue .Bool (true )),
616+ },
617+ },
618+ {
619+ ResourceName : "github_team_settings.test" ,
620+ ImportState : true ,
621+ ImportStateVerify : true ,
622+ ImportStateIdFunc : func (s * terraform.State ) (string , error ) {
623+ rs , ok := s .RootModule ().Resources ["github_team.test" ]
624+ if ! ok {
625+ return "" , fmt .Errorf ("not found: github_team.test" )
626+ }
627+ return rs .Primary .Attributes ["id" ], nil
628+ },
629+ },
630+ },
631+ })
632+ })
633+
481634 t .Run ("manages updating only notify field" , func (t * testing.T ) {
482635 randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
483636 teamName := fmt .Sprintf ("%steam-settings-%s" , testResourcePrefix , randomID )
0 commit comments