Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate tagging tests for CloudWatch and CloudWatch Logs #37668

Merged
merged 9 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -394,6 +396,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 @@ -405,6 +416,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 "ImportBody" }}
Expand All @@ -48,7 +48,7 @@
{{- 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
Loading