Skip to content

Commit

Permalink
Merge pull request #37676 from hashicorp/t-acctest-literal-true-false…
Browse files Browse the repository at this point in the history
…-string-constant

ci: Prefer constants for test string literals
  • Loading branch information
YakDriver committed May 24, 2024
2 parents e43c3ed + 07cb90c commit aad4d5d
Show file tree
Hide file tree
Showing 464 changed files with 4,588 additions and 4,598 deletions.
18 changes: 18 additions & 0 deletions .ci/.semgrep-test-constants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ rules:
pattern: '"basic"'
severity: ERROR
fix: "acctest.CtBasic"
- id: literal-False-string-test-constant
languages: [go]
message: Use the constant `acctest.CtFalse` for the string literal "false" in test files
paths:
include:
- "internal/service/**/*_test.go"
pattern: '"false"'
severity: ERROR
fix: "acctest.CtFalse"
- id: literal-FalseCaps-string-test-constant
languages: [go]
message: Use the constant `acctest.CtFalseCaps` for the string literal "FALSE" in test files
Expand Down Expand Up @@ -192,6 +201,15 @@ rules:
pattern: '"tags.%"'
severity: ERROR
fix: "acctest.CtTagsPercent"
- id: literal-True-string-test-constant
languages: [go]
message: Use the constant `acctest.CtTrue` for the string literal "true" in test files
paths:
include:
- "internal/service/**/*_test.go"
pattern: '"true"'
severity: ERROR
fix: "acctest.CtTrue"
- id: literal-TrueCaps-string-test-constant
languages: [go]
message: Use the constant `acctest.CtTrueCaps` for the string literal "TRUE" in test files
Expand Down
2 changes: 2 additions & 0 deletions internal/acctest/consts.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
FALSE,FalseCaps
TRUE,TrueCaps
basic,Basic
false,False
key1,Key1
key2,Key2
provider_tags,ProviderTags
Expand All @@ -19,6 +20,7 @@ tags.%,TagsPercent
tags.key1,TagsKey1
tags.key2,TagsKey2
tags_all.%,TagsAllPercent
true,True
value1,Value1
value1updated,Value1Updated
value2,Value2
4 changes: 4 additions & 0 deletions internal/acctest/consts_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/service/accessanalyzer/archive_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ filter {
testAccCheckArchiveRuleExists(ctx, resourceName, &archiveRule),
resource.TestCheckResourceAttr(resourceName, "filter.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "filter.0.criteria", "error"),
resource.TestCheckResourceAttr(resourceName, "filter.0.exists", "true"),
resource.TestCheckResourceAttr(resourceName, "filter.0.exists", acctest.CtTrue),
),
},
{
Expand All @@ -105,9 +105,9 @@ filter {
testAccCheckArchiveRuleExists(ctx, resourceName, &archiveRule),
resource.TestCheckResourceAttr(resourceName, "filter.#", acctest.Ct2),
resource.TestCheckResourceAttr(resourceName, "filter.0.criteria", "error"),
resource.TestCheckResourceAttr(resourceName, "filter.0.exists", "true"),
resource.TestCheckResourceAttr(resourceName, "filter.0.exists", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "filter.1.criteria", "isPublic"),
resource.TestCheckResourceAttr(resourceName, "filter.1.eq.0", "false"),
resource.TestCheckResourceAttr(resourceName, "filter.1.eq.0", acctest.CtFalse),
),
},
{
Expand All @@ -116,7 +116,7 @@ filter {
testAccCheckArchiveRuleExists(ctx, resourceName, &archiveRule),
resource.TestCheckResourceAttr(resourceName, "filter.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "filter.0.criteria", "isPublic"),
resource.TestCheckResourceAttr(resourceName, "filter.0.eq.0", "true"),
resource.TestCheckResourceAttr(resourceName, "filter.0.eq.0", acctest.CtTrue),
),
},
},
Expand Down
8 changes: 4 additions & 4 deletions internal/service/account/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func testAccRegion_basic(t *testing.T) {
Config: testAccRegionConfig_basic(regionName, true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, names.AttrAccountID, ""),
resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, "true"),
resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "opt_status", "ENABLED"),
resource.TestCheckResourceAttr(resourceName, "region_name", regionName),
),
Expand All @@ -49,7 +49,7 @@ func testAccRegion_basic(t *testing.T) {
Config: testAccRegionConfig_basic(regionName, false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, names.AttrAccountID, ""),
resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, "false"),
resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, "opt_status", "DISABLED"),
resource.TestCheckResourceAttr(resourceName, "region_name", regionName),
),
Expand Down Expand Up @@ -78,7 +78,7 @@ func testAccRegion_accountID(t *testing.T) { // nosemgrep:ci.account-in-func-nam
Config: testAccRegionConfig_organization(regionName, true),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, names.AttrAccountID),
resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, "true"),
resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "opt_status", "ENABLED"),
resource.TestCheckResourceAttr(resourceName, "region_name", regionName),
),
Expand All @@ -92,7 +92,7 @@ func testAccRegion_accountID(t *testing.T) { // nosemgrep:ci.account-in-func-nam
Config: testAccRegionConfig_organization(regionName, false),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, names.AttrAccountID),
resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, "false"),
resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, "opt_status", "DISABLED"),
resource.TestCheckResourceAttr(resourceName, "region_name", regionName),
),
Expand Down
Loading

0 comments on commit aad4d5d

Please sign in to comment.