Skip to content

Commit

Permalink
Merge pull request #37668 from hashicorp/td-generate-tagtests-cloudwa…
Browse files Browse the repository at this point in the history
…tch-core

Generate tagging tests for CloudWatch and CloudWatch Logs
  • Loading branch information
gdavison authored Jun 4, 2024
2 parents 6ba37b0 + bdeba92 commit 48694a7
Show file tree
Hide file tree
Showing 49 changed files with 10,890 additions and 528 deletions.
3 changes: 3 additions & 0 deletions .changelog/37668.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_cloudwatch_log_group: Correctly handles tag updates with empty string tags
```
19 changes: 19 additions & 0 deletions internal/generate/tagstests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ type ResourceDatum struct {
PackageProviderNameUpper string
Name string
TypeName string
DestroyTakesT bool
ExistsTypeName string
ExistsTakesT bool
FileName string
Generator string
NoImport bool
Expand Down Expand Up @@ -395,6 +397,15 @@ func (v *visitor) processFuncDecl(funcDecl *ast.FuncDecl) {
d.AlternateRegionProvider = b
}
}

if attr, ok := args.Keyword["destroyTakesT"]; ok {
if b, err := strconv.ParseBool(attr); err != nil {
v.errs = append(v.errs, fmt.Errorf("invalid destroyTakesT value: %q at %s. Should be boolean value.", attr, fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
continue
} else {
d.DestroyTakesT = b
}
}
if attr, ok := args.Keyword["existsType"]; ok {
if typeName, importSpec, err := parseIdentifierSpec(attr); err != nil {
v.errs = append(v.errs, fmt.Errorf("%s: %w", attr, fmt.Sprintf("%s.%s", v.packageName, v.functionName), err))
Expand All @@ -406,6 +417,14 @@ func (v *visitor) processFuncDecl(funcDecl *ast.FuncDecl) {
}
}
}
if attr, ok := args.Keyword["existsTakesT"]; ok {
if b, err := strconv.ParseBool(attr); err != nil {
v.errs = append(v.errs, fmt.Errorf("invalid existsTakesT value: %q at %s. Should be boolean value.", attr, fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
continue
} else {
d.ExistsTakesT = b
}
}
if attr, ok := args.Keyword["generator"]; ok {
if attr == "false" {
generatorSeen = true
Expand Down
4 changes: 2 additions & 2 deletions internal/generate/tagstests/test.go.gtpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{ define "TestCaseSetupNoProviders" -}}
PreCheck: func() { acctest.PreCheck(ctx, t){{ if .PreCheck }}; testAccPreCheck(ctx, t){{ end }} },
ErrorCheck: acctest.ErrorCheck(t, names.{{ .PackageProviderNameUpper }}ServiceID),
CheckDestroy: testAccCheck{{ .Name }}Destroy(ctx),
CheckDestroy: testAccCheck{{ .Name }}Destroy(ctx{{ if .DestroyTakesT }}, t{{ end }}),
{{- end }}

{{ define "TagsKnownValueForNull" -}}
Expand Down Expand Up @@ -68,7 +68,7 @@ plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), know
{{- end }}

{{ define "ExistsCheck" }}
testAccCheck{{ .Name }}Exists(ctx, resourceName{{ if .ExistsTypeName}}, &v{{ end }}),
testAccCheck{{ .Name }}Exists(ctx, {{ if .ExistsTakesT }}t,{{ end }} resourceName{{ if .ExistsTypeName}}, &v{{ end }}),
{{ end }}

{{ define "AdditionalTfVars" -}}
Expand Down
Loading

0 comments on commit 48694a7

Please sign in to comment.