|
8 | 8 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
9 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
10 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/knownvalue" |
| 12 | + "github.com/hashicorp/terraform-plugin-testing/statecheck" |
| 13 | + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" |
11 | 14 | ) |
12 | 15 |
|
13 | 16 | func TestAccGithubOrganizationRuleset(t *testing.T) { |
@@ -231,16 +234,14 @@ resource "github_organization_ruleset" "test" { |
231 | 234 | Steps: []resource.TestStep{ |
232 | 235 | { |
233 | 236 | Config: config, |
234 | | - Check: resource.ComposeTestCheckFunc( |
235 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "name", rulesetName), |
236 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "target", "branch"), |
237 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "enforcement", "active"), |
238 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.#", "1"), |
239 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.name", propName), |
240 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.source", "custom"), |
241 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.#", "1"), |
242 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.0", "blue"), |
243 | | - ), |
| 237 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 238 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("name"), knownvalue.StringExact(rulesetName)), |
| 239 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("target"), knownvalue.StringExact("branch")), |
| 240 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("enforcement"), knownvalue.StringExact("active")), |
| 241 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("name"), knownvalue.StringExact(propName)), |
| 242 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("source"), knownvalue.StringExact("custom")), |
| 243 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("property_values").AtSliceIndex(0), knownvalue.StringExact("blue")), |
| 244 | + }, |
244 | 245 | }, |
245 | 246 | }, |
246 | 247 | }) |
@@ -292,14 +293,12 @@ resource "github_organization_ruleset" "test" { |
292 | 293 | Steps: []resource.TestStep{ |
293 | 294 | { |
294 | 295 | Config: config, |
295 | | - Check: resource.ComposeTestCheckFunc( |
296 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "name", rulesetName), |
297 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.#", "0"), |
298 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.exclude.#", "1"), |
299 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.exclude.0.name", propName), |
300 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.exclude.0.source", "custom"), |
301 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.exclude.0.property_values.0", "red"), |
302 | | - ), |
| 296 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 297 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("name"), knownvalue.StringExact(rulesetName)), |
| 298 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("exclude").AtSliceIndex(0).AtMapKey("name"), knownvalue.StringExact(propName)), |
| 299 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("exclude").AtSliceIndex(0).AtMapKey("source"), knownvalue.StringExact("custom")), |
| 300 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("exclude").AtSliceIndex(0).AtMapKey("property_values").AtSliceIndex(0), knownvalue.StringExact("red")), |
| 301 | + }, |
303 | 302 | }, |
304 | 303 | }, |
305 | 304 | }) |
@@ -366,19 +365,16 @@ resource "github_organization_ruleset" "test" { |
366 | 365 | Steps: []resource.TestStep{ |
367 | 366 | { |
368 | 367 | Config: config, |
369 | | - Check: resource.ComposeTestCheckFunc( |
370 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "name", rulesetName), |
371 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.#", "2"), |
372 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.name", propEnvironmentName), |
373 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.source", "custom"), |
374 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.#", "1"), |
375 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.0", "production"), |
376 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.1.name", propTierName), |
377 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.1.source", "custom"), |
378 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.1.property_values.#", "2"), |
379 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.1.property_values.0", "premium"), |
380 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.1.property_values.1", "enterprise"), |
381 | | - ), |
| 368 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 369 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("name"), knownvalue.StringExact(rulesetName)), |
| 370 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("name"), knownvalue.StringExact(propEnvironmentName)), |
| 371 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("source"), knownvalue.StringExact("custom")), |
| 372 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("property_values").AtSliceIndex(0), knownvalue.StringExact("production")), |
| 373 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(1).AtMapKey("name"), knownvalue.StringExact(propTierName)), |
| 374 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(1).AtMapKey("source"), knownvalue.StringExact("custom")), |
| 375 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(1).AtMapKey("property_values").AtSliceIndex(0), knownvalue.StringExact("premium")), |
| 376 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(1).AtMapKey("property_values").AtSliceIndex(1), knownvalue.StringExact("enterprise")), |
| 377 | + }, |
382 | 378 | }, |
383 | 379 | }, |
384 | 380 | }) |
@@ -466,22 +462,18 @@ resource "github_organization_ruleset" "test" { |
466 | 462 | Steps: []resource.TestStep{ |
467 | 463 | { |
468 | 464 | Config: config, |
469 | | - Check: resource.ComposeTestCheckFunc( |
470 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "name", rulesetName), |
471 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.#", "1"), |
472 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.0", "blue"), |
473 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.exclude.#", "0"), |
474 | | - ), |
| 465 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 466 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("name"), knownvalue.StringExact(rulesetName)), |
| 467 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("property_values").AtSliceIndex(0), knownvalue.StringExact("blue")), |
| 468 | + }, |
475 | 469 | }, |
476 | 470 | { |
477 | 471 | Config: configUpdated, |
478 | | - Check: resource.ComposeTestCheckFunc( |
479 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "name", rulesetName), |
480 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.#", "2"), |
481 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.0", "backend"), |
482 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.1", "platform"), |
483 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.exclude.#", "0"), |
484 | | - ), |
| 472 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 473 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("name"), knownvalue.StringExact(rulesetName)), |
| 474 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("property_values").AtSliceIndex(0), knownvalue.StringExact("backend")), |
| 475 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("property_values").AtSliceIndex(1), knownvalue.StringExact("platform")), |
| 476 | + }, |
485 | 477 | }, |
486 | 478 | }, |
487 | 479 | }) |
@@ -1063,7 +1055,7 @@ resource "github_organization_ruleset" "test" { |
1063 | 1055 | t.Run("validates_repository_property_works_as_single_targeting_option", func(t *testing.T) { |
1064 | 1056 | randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) |
1065 | 1057 | rulesetName := fmt.Sprintf("%s-repo-prop-only-%s", testResourcePrefix, randomID) |
1066 | | - propName := fmt.Sprintf("e2e_test_environment_%s", randomID) |
| 1058 | + propName := fmt.Sprintf("%s_environment_%s", testResourcePrefix, randomID) |
1067 | 1059 |
|
1068 | 1060 | config := fmt.Sprintf(` |
1069 | 1061 | resource "github_organization_custom_properties" "environment" { |
@@ -1109,17 +1101,15 @@ resource "github_organization_ruleset" "test" { |
1109 | 1101 | Steps: []resource.TestStep{ |
1110 | 1102 | { |
1111 | 1103 | Config: config, |
1112 | | - Check: resource.ComposeTestCheckFunc( |
1113 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "name", rulesetName), |
1114 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "target", "branch"), |
1115 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "enforcement", "active"), |
1116 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.#", "1"), |
1117 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.name", propName), |
1118 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.source", "custom"), |
1119 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.#", "2"), |
1120 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.0", "production"), |
1121 | | - resource.TestCheckResourceAttr("github_organization_ruleset.test", "conditions.0.repository_property.0.include.0.property_values.1", "staging"), |
1122 | | - ), |
| 1104 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 1105 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("name"), knownvalue.StringExact(rulesetName)), |
| 1106 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("target"), knownvalue.StringExact("branch")), |
| 1107 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("enforcement"), knownvalue.StringExact("active")), |
| 1108 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("name"), knownvalue.StringExact(propName)), |
| 1109 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("source"), knownvalue.StringExact("custom")), |
| 1110 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("property_values").AtSliceIndex(0), knownvalue.StringExact("production")), |
| 1111 | + statecheck.ExpectKnownValue("github_organization_ruleset.test", tfjsonpath.New("conditions").AtSliceIndex(0).AtMapKey("repository_property").AtSliceIndex(0).AtMapKey("include").AtSliceIndex(0).AtMapKey("property_values").AtSliceIndex(1), knownvalue.StringExact("staging")), |
| 1112 | + }, |
1123 | 1113 | }, |
1124 | 1114 | }, |
1125 | 1115 | }) |
|
0 commit comments