66
77 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
88 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+ "github.com/hashicorp/terraform-plugin-testing/knownvalue"
10+ "github.com/hashicorp/terraform-plugin-testing/statecheck"
11+ "github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
912)
1013
1114func TestAccGithubOrganizationSecurityConfiguration (t * testing.T ) {
@@ -34,12 +37,16 @@ func TestAccGithubOrganizationSecurityConfiguration(t *testing.T) {
3437 Steps : []resource.TestStep {
3538 {
3639 Config : config ,
37- Check : resource .ComposeTestCheckFunc (
38- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "name" , configName ),
39- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "description" , "Test configuration" ),
40- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "advanced_security" , "enabled" ),
41- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "enforcement" , "enforced" ),
42- ),
40+ ConfigStateChecks : []statecheck.StateCheck {
41+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
42+ tfjsonpath .New ("name" ), knownvalue .StringExact (configName )),
43+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
44+ tfjsonpath .New ("description" ), knownvalue .StringExact ("Test configuration" )),
45+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
46+ tfjsonpath .New ("advanced_security" ), knownvalue .StringExact ("enabled" )),
47+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
48+ tfjsonpath .New ("enforcement" ), knownvalue .StringExact ("enforced" )),
49+ },
4350 },
4451 {
4552 ResourceName : "github_organization_security_configuration.test" ,
@@ -70,17 +77,21 @@ func TestAccGithubOrganizationSecurityConfiguration(t *testing.T) {
7077 Steps : []resource.TestStep {
7178 {
7279 Config : configBefore ,
73- Check : resource .ComposeTestCheckFunc (
74- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "name" , configName ),
75- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "advanced_security" , "disabled" ),
76- ),
80+ ConfigStateChecks : []statecheck.StateCheck {
81+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
82+ tfjsonpath .New ("name" ), knownvalue .StringExact (configName )),
83+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
84+ tfjsonpath .New ("advanced_security" ), knownvalue .StringExact ("disabled" )),
85+ },
7786 },
7887 {
7988 Config : configAfter ,
80- Check : resource .ComposeTestCheckFunc (
81- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "name" , configNameUpdated ),
82- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "advanced_security" , "enabled" ),
83- ),
89+ ConfigStateChecks : []statecheck.StateCheck {
90+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
91+ tfjsonpath .New ("name" ), knownvalue .StringExact (configNameUpdated )),
92+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
93+ tfjsonpath .New ("advanced_security" ), knownvalue .StringExact ("enabled" )),
94+ },
8495 },
8596 },
8697 })
@@ -115,12 +126,16 @@ func TestAccGithubOrganizationSecurityConfiguration(t *testing.T) {
115126 Steps : []resource.TestStep {
116127 {
117128 Config : config ,
118- Check : resource .ComposeTestCheckFunc (
119- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "name" , configName ),
120- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "dependency_graph_autosubmit_action_options.0.labeled_runners" , "true" ),
121- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "code_scanning_default_setup_options.0.runner_type" , "labeled" ),
122- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "code_scanning_default_setup_options.0.runner_label" , "code-scanning" ),
123- ),
129+ ConfigStateChecks : []statecheck.StateCheck {
130+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
131+ tfjsonpath .New ("name" ), knownvalue .StringExact (configName )),
132+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
133+ tfjsonpath .New ("dependency_graph_autosubmit_action_options" ).AtSliceIndex (0 ).AtMapKey ("labeled_runners" ), knownvalue .Bool (true )),
134+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
135+ tfjsonpath .New ("code_scanning_default_setup_options" ).AtSliceIndex (0 ).AtMapKey ("runner_type" ), knownvalue .StringExact ("labeled" )),
136+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
137+ tfjsonpath .New ("code_scanning_default_setup_options" ).AtSliceIndex (0 ).AtMapKey ("runner_label" ), knownvalue .StringExact ("code-scanning" )),
138+ },
124139 },
125140 {
126141 ResourceName : "github_organization_security_configuration.test" ,
@@ -147,10 +162,12 @@ func TestAccGithubOrganizationSecurityConfiguration(t *testing.T) {
147162 Steps : []resource.TestStep {
148163 {
149164 Config : config ,
150- Check : resource .ComposeTestCheckFunc (
151- resource .TestCheckResourceAttr ("github_organization_security_configuration.test" , "name" , configName ),
152- resource .TestCheckResourceAttrSet ("github_organization_security_configuration.test" , "target_type" ),
153- ),
165+ ConfigStateChecks : []statecheck.StateCheck {
166+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
167+ tfjsonpath .New ("name" ), knownvalue .StringExact (configName )),
168+ statecheck .ExpectKnownValue ("github_organization_security_configuration.test" ,
169+ tfjsonpath .New ("target_type" ), knownvalue .NotNull ()),
170+ },
154171 },
155172 },
156173 })
0 commit comments