Skip to content

Commit

Permalink
Merge pull request hashicorp#40122 from hashicorp/td-apigateway-stuff
Browse files Browse the repository at this point in the history
API Gateway: clean up tests to remove unneeded serialization
  • Loading branch information
gdavison authored Nov 14, 2024
2 parents 4421780 + 5ea7984 commit f412f37
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 291 deletions.
19 changes: 13 additions & 6 deletions internal/generate/tagstests/data_source_test.go.gtpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
{{- end }}
{{ end }}

{{ define "Test" -}}
resource.{{ if and .Serialize (not .SerializeParallelTests) }}Test{{ else }}ParallelTest{{ end }}
{{- end }}

{{ define "TestCaseSetup" -}}
{{ template "TestCaseSetupNoProviders" . -}}
{{ if not .AlternateRegionProvider }}
Expand Down Expand Up @@ -104,6 +108,9 @@ import (
{{ if .Serialize }}
func {{ template "testname" . }}_tagsSerial(t *testing.T) {
t.Helper()
{{ if .SerializeParallelTests -}}
t.Parallel()
{{- end }}

testCases := map[string]func(t *testing.T){
acctest.CtBasic: {{ template "testname" . }}_tags,
Expand All @@ -121,7 +128,7 @@ func {{ template "testname" . }}_tagsSerial(t *testing.T) {
func {{ template "testname" . }}_tags(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -149,7 +156,7 @@ func {{ template "testname" . }}_tags(t *testing.T) {
func {{ template "testname" . }}_tags_NullMap(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
Expand All @@ -173,7 +180,7 @@ func {{ template "testname" . }}_tags_NullMap(t *testing.T) {
func {{ template "testname" . }}_tags_EmptyMap(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
Expand All @@ -197,7 +204,7 @@ func {{ template "testname" . }}_tags_EmptyMap(t *testing.T) {
func {{ template "testname" . }}_tags_DefaultTags_nonOverlapping(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -231,7 +238,7 @@ func {{ template "testname" . }}_tags_DefaultTags_nonOverlapping(t *testing.T) {
func {{ template "testname" . }}_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -271,7 +278,7 @@ func {{ template "testname" . }}_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T
func {{ template "testname" . }}_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down
9 changes: 9 additions & 0 deletions internal/generate/tagstests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ type ResourceDatum struct {
Implementation implementation
Serialize bool
SerializeDelay bool
SerializeParallelTests bool
PreCheck bool
SkipEmptyTags bool // TODO: Remove when we have a strategy for resources that have a minimum tag value length of 1
SkipNullTags bool
Expand Down Expand Up @@ -685,6 +686,14 @@ func (v *visitor) processFuncDecl(funcDecl *ast.FuncDecl) {
d.Serialize = b
}
}
if attr, ok := args.Keyword["serializeParallelTests"]; ok {
if b, err := strconv.ParseBool(attr); err != nil {
v.errs = append(v.errs, fmt.Errorf("invalid serializeParallelTests value: %q at %s. Should be boolean value.", attr, fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
continue
} else {
d.SerializeParallelTests = b
}
}
if attr, ok := args.Keyword["serializeDelay"]; ok {
if b, err := strconv.ParseBool(attr); err != nil {
v.errs = append(v.errs, fmt.Errorf("invalid serializeDelay value: %q at %s. Should be duration value.", attr, fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
Expand Down
49 changes: 28 additions & 21 deletions internal/generate/tagstests/resource_test.go.gtpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
{{- end }}
{{ end }}

{{ define "Test" -}}
resource.{{ if and .Serialize (not .SerializeParallelTests) }}Test{{ else }}ParallelTest{{ end }}
{{- end }}

{{ define "TestCaseSetup" -}}
{{ template "TestCaseSetupNoProviders" . -}}
{{ if not .AlternateRegionProvider }}
Expand Down Expand Up @@ -150,6 +154,9 @@ import (
{{ if .Serialize }}
func {{ template "testname" . }}_tagsSerial(t *testing.T) {
t.Helper()
{{ if .SerializeParallelTests -}}
t.Parallel()
{{- end }}

testCases := map[string]func(t *testing.T){
acctest.CtBasic: {{ template "testname" . }}_tags,
Expand Down Expand Up @@ -181,7 +188,7 @@ func {{ template "testname" . }}_tagsSerial(t *testing.T) {
func {{ template "testname" . }}_tags(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -404,7 +411,7 @@ func {{ template "testname" . }}_tags_null(t *testing.T) {
{{ end }}
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -491,7 +498,7 @@ 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 "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -566,7 +573,7 @@ func {{ template "testname" . }}_tags_EmptyMap(t *testing.T) {
func {{ template "testname" . }}_tags_AddOnUpdate(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -660,7 +667,7 @@ func {{ template "testname" . }}_tags_EmptyTag_OnCreate(t *testing.T) {
{{ end }}
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -768,7 +775,7 @@ func {{ template "testname" . }}_tags_EmptyTag_OnUpdate_Add(t *testing.T) {
{{ end }}
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -929,7 +936,7 @@ func {{ template "testname" . }}_tags_EmptyTag_OnUpdate_Replace(t *testing.T) {
{{ end }}
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetup" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -1030,7 +1037,7 @@ func {{ template "testname" . }}_tags_EmptyTag_OnUpdate_Replace(t *testing.T) {
func {{ template "testname" . }}_tags_DefaultTags_providerOnly(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -1258,7 +1265,7 @@ func {{ template "testname" . }}_tags_DefaultTags_providerOnly(t *testing.T) {
func {{ template "testname" . }}_tags_DefaultTags_nonOverlapping(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -1449,7 +1456,7 @@ func {{ template "testname" . }}_tags_DefaultTags_nonOverlapping(t *testing.T) {
func {{ template "testname" . }}_tags_DefaultTags_overlapping(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -1650,7 +1657,7 @@ func {{ template "testname" . }}_tags_DefaultTags_overlapping(t *testing.T) {
func {{ template "testname" . }}_tags_DefaultTags_updateToProviderOnly(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -1750,7 +1757,7 @@ func {{ template "testname" . }}_tags_DefaultTags_updateToProviderOnly(t *testin
func {{ template "testname" . }}_tags_DefaultTags_updateToResourceOnly(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -1852,7 +1859,7 @@ func {{ template "testname" . }}_tags_DefaultTags_emptyResourceTag(t *testing.T)
{{ end }}
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -1931,7 +1938,7 @@ func {{ template "testname" . }}_tags_DefaultTags_emptyProviderOnlyTag(t *testin
{{ end }}
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -2002,7 +2009,7 @@ func {{ template "testname" . }}_tags_DefaultTags_nullOverlappingResourceTag(t *
{{ end }}
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -2090,7 +2097,7 @@ func {{ template "testname" . }}_tags_DefaultTags_nullNonOverlappingResourceTag(
{{ end }}
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -2177,7 +2184,7 @@ func {{ template "testname" . }}_tags_DefaultTags_nullNonOverlappingResourceTag(
func {{ template "testname" . }}_tags_ComputedTag_OnCreate(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -2237,7 +2244,7 @@ func {{ template "testname" . }}_tags_ComputedTag_OnCreate(t *testing.T) {
func {{ template "testname" . }}_tags_ComputedTag_OnUpdate_Add(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -2344,7 +2351,7 @@ func {{ template "testname" . }}_tags_ComputedTag_OnUpdate_Add(t *testing.T) {
func {{ template "testname" . }}_tags_ComputedTag_OnUpdate_Replace(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -2441,7 +2448,7 @@ func {{ template "testname" . }}_tags_ComputedTag_OnUpdate_Replace(t *testing.T)
func {{ template "testname" . }}_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
// 1: Create
Expand Down Expand Up @@ -2613,7 +2620,7 @@ func {{ template "testname" . }}_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T
func {{ template "testname" . }}_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) {
{{- template "Init" . }}

resource.{{ if .Serialize }}Test{{ else }}ParallelTest{{ end }}(t, resource.TestCase{
{{ template "Test" . }}(t, resource.TestCase{
{{ template "TestCaseSetupNoProviders" . }}
Steps: []resource.TestStep{
// 1: Create
Expand Down
Loading

0 comments on commit f412f37

Please sign in to comment.