Skip to content

Commit

Permalink
Merge pull request #39279 from hashicorp/b-framework-tags-empty
Browse files Browse the repository at this point in the history
tagging: Adds tests for empty `tags` map
  • Loading branch information
gdavison authored Sep 12, 2024
2 parents d5d5eb8 + 9c715a4 commit aad6a61
Show file tree
Hide file tree
Showing 129 changed files with 10,695 additions and 194 deletions.
3 changes: 3 additions & 0 deletions .changelog/39279.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_networkmonitor_monitor: Fixes error when optional attribute `aggregation_period` not set.
```
76 changes: 76 additions & 0 deletions internal/generate/tagstests/resource_test.go.gtpl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func {{ template "testname" . }}_tagsSerial(t *testing.T) {
testCases := map[string]func(t *testing.T){
acctest.CtBasic: {{ template "testname" . }}_tags,
"null": {{ template "testname" . }}_tags_null,
"EmptyMap": {{ template "testname" . }}_tags_EmptyMap,
"AddOnUpdate": {{ template "testname" . }}_tags_AddOnUpdate,
"EmptyTag_OnCreate": {{ template "testname" . }}_tags_EmptyTag_OnCreate,
"EmptyTag_OnUpdate_Add": {{ template "testname" . }}_tags_EmptyTag_OnUpdate_Add,
Expand Down Expand Up @@ -472,6 +473,81 @@ func {{ template "testname" . }}_tags_null(t *testing.T) {
})
}

func {{ template "testname" . }}_tags_EmptyMap(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
{{ if .AlternateRegionProvider -}}
ProtoV5ProviderFactories: acctest.ProtoV5FactoriesAlternate(ctx, t),
{{ end -}}
ConfigDirectory: config.StaticDirectory("testdata/{{ .Name }}/tags/"),
ConfigVariables: config.Variables{ {{ if .Generator }}
acctest.CtRName: config.StringVariable(rName),{{ end }}
acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}),
{{ template "AdditionalTfVars" . }}
},
Check: resource.ComposeAggregateTestCheckFunc(
{{- template "ExistsCheck" . -}}
),
ConfigStateChecks: []statecheck.StateCheck{
{{ if eq .Implementation "framework" -}}
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})),
{{- else -}}
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})),
{{- end }}
},
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
{{ if eq .Implementation "framework" -}}
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})),
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})),
{{- else -}}
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()),
// TODO: Should be known
plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)),
{{- end }}
},
},
},
{{ if not .NoImport -}}
{
{{ if .AlternateRegionProvider -}}
ProtoV5ProviderFactories: acctest.ProtoV5FactoriesAlternate(ctx, t),
{{ end -}}
ConfigDirectory: config.StaticDirectory("testdata/{{ .Name }}/tags/"),
ConfigVariables: config.Variables{ {{ if .Generator }}
acctest.CtRName: config.StringVariable(rName),{{ end }}
acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}),
{{ template "AdditionalTfVars" . }}
},
{{- template "ImportBodyIgnoreKey1" . -}}
},
{{- end }}
{{ if eq .Implementation "sdk" -}}
{
{{ if .AlternateRegionProvider -}}
ProtoV5ProviderFactories: acctest.ProtoV5FactoriesAlternate(ctx, t),
{{ end -}}
ConfigDirectory: config.StaticDirectory("testdata/{{ .Name }}/tags/"),
ConfigVariables: config.Variables{ {{ if .Generator }}
acctest.CtRName: config.StringVariable(rName),{{ end }}
acctest.CtResourceTags: nil,
{{ template "AdditionalTfVars" . }}
},
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
{{- end }}
},
})
}

func {{ template "testname" . }}_tags_AddOnUpdate(t *testing.T) {
{{- template "Init" . }}

Expand Down
58 changes: 58 additions & 0 deletions internal/service/accessanalyzer/analyzer_tags_gen_test.go

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

64 changes: 64 additions & 0 deletions internal/service/acm/certificate_tags_gen_test.go

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

60 changes: 60 additions & 0 deletions internal/service/acmpca/certificate_authority_tags_gen_test.go

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

50 changes: 50 additions & 0 deletions internal/service/amp/scraper_tags_gen_test.go

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

Loading

0 comments on commit aad6a61

Please sign in to comment.