From 2904cbcc03e55cdff731e63fc9df26055f7a13c5 Mon Sep 17 00:00:00 2001 From: akinross Date: Wed, 13 Nov 2024 12:03:43 +0100 Subject: [PATCH] [ignore] Generator template fix for datasource to not include default for required attributes when key is the same --- gen/templates/datasource_test.go.tmpl | 48 ++++++++++--------- ...urce_aci_l3out_redistribute_policy_test.go | 1 - ...e_domain_to_netflow_monitor_policy_test.go | 1 - ...mer_label_to_route_control_profile_test.go | 1 - 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/gen/templates/datasource_test.go.tmpl b/gen/templates/datasource_test.go.tmpl index 8ad774bd8..16321a765 100644 --- a/gen/templates/datasource_test.go.tmpl +++ b/gen/templates/datasource_test.go.tmpl @@ -27,40 +27,42 @@ func TestAccDataSource{{$.resourceClassName}}{{if .class_name}}With{{capitalize {{- range $key, $value := $.datasource_required}} {{- if eq $key "target_dn" }} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"), - {{- else }} - {{- if not (definedInList $.exclude_attributes $key) }} + {{- else }} + {{- if not (definedInList $.exclude_attributes $key) }} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), - {{- end }} - {{- end}} + {{- end }} + {{- end}} {{- end}} {{- range $key, $value := $.default}} - {{- if eq $key "version_mismatch" }} - {{- range $version, $attributes := $value }} + {{- if not (definedInMap $key $.datasource_required)}} + {{- if eq $key "version_mismatch" }} + {{- range $version, $attributes := $value }} composeAggregateTestCheckFuncWithVersion(t, "{{$version}}", ">",{{- range $attributeName, $attributeValue := $attributes}} - {{- if not (definedInList $.exclude_attributes $attributeName) }} - {{- if (isInterfaceSlice $attributeValue)}} + {{- if not (definedInList $.exclude_attributes $attributeName) }} + {{- if (isInterfaceSlice $attributeValue)}} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.#", "{{len $attributeValue}}"), - {{- range $index, $subvalue := $attributeValue}} + {{- range $index, $subvalue := $attributeValue}} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}.{{$index}}", "{{$subvalue}}"), - {{- end}} - {{- else}} + {{- end}} + {{- else}} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$attributeName}}", "{{$attributeValue}}"), - {{- end}} - {{- end}} - {{- end}}), - {{- end}} - {{- else}} - {{- if not (definedInList $.exclude_attributes $key) }} - {{- if (isInterfaceSlice $value)}} + {{- end}} + {{- end}} + {{- end}}), + {{- end}} + {{- else}} + {{- if not (definedInList $.exclude_attributes $key) }} + {{- if (isInterfaceSlice $value)}} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.#", "{{len $value}}"), - {{- range $index, $subvalue := $value}} + {{- range $index, $subvalue := $value}} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}.{{$index}}", "{{$subvalue}}"), - {{- end}} - {{- else}} + {{- end}} + {{- else}} resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"), + {{- end}} + {{- end}} + {{- end}} {{- end}} - {{- end}} - {{- end}} {{- end}} {{- range $index, $key := $.read_only}} resource.TestCheckResourceAttrSet("data.aci_{{$.resourceName}}.test", "{{$key}}"), diff --git a/internal/provider/data_source_aci_l3out_redistribute_policy_test.go b/internal/provider/data_source_aci_l3out_redistribute_policy_test.go index d21f88373..d84c65494 100644 --- a/internal/provider/data_source_aci_l3out_redistribute_policy_test.go +++ b/internal/provider/data_source_aci_l3out_redistribute_policy_test.go @@ -24,7 +24,6 @@ func TestAccDataSourceL3extRsRedistributePolWithL3extOut(t *testing.T) { resource.TestCheckResourceAttr("data.aci_l3out_redistribute_policy.test", "route_control_profile_name", "test_tn_rtctrl_profile_name"), resource.TestCheckResourceAttr("data.aci_l3out_redistribute_policy.test", "source", "direct"), resource.TestCheckResourceAttr("data.aci_l3out_redistribute_policy.test", "annotation", "orchestrator:terraform"), - resource.TestCheckResourceAttr("data.aci_l3out_redistribute_policy.test", "source", "direct"), ), }, { diff --git a/internal/provider/data_source_aci_relation_from_bridge_domain_to_netflow_monitor_policy_test.go b/internal/provider/data_source_aci_relation_from_bridge_domain_to_netflow_monitor_policy_test.go index 2ba9a71dd..8cbd2925e 100644 --- a/internal/provider/data_source_aci_relation_from_bridge_domain_to_netflow_monitor_policy_test.go +++ b/internal/provider/data_source_aci_relation_from_bridge_domain_to_netflow_monitor_policy_test.go @@ -24,7 +24,6 @@ func TestAccDataSourceFvRsBDToNetflowMonitorPolWithFvBD(t *testing.T) { resource.TestCheckResourceAttr("data.aci_relation_from_bridge_domain_to_netflow_monitor_policy.test", "filter_type", "ipv4"), resource.TestCheckResourceAttr("data.aci_relation_from_bridge_domain_to_netflow_monitor_policy.test", "netflow_monitor_policy_name", "test_tn_netflow_monitor_pol_name"), resource.TestCheckResourceAttr("data.aci_relation_from_bridge_domain_to_netflow_monitor_policy.test", "annotation", "orchestrator:terraform"), - resource.TestCheckResourceAttr("data.aci_relation_from_bridge_domain_to_netflow_monitor_policy.test", "filter_type", "ipv4"), ), }, { diff --git a/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go b/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go index a3b3edb1a..882759339 100644 --- a/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go +++ b/internal/provider/data_source_aci_relation_from_l3out_consumer_label_to_route_control_profile_test.go @@ -24,7 +24,6 @@ func TestAccDataSourceL3extRsLblToProfileWithL3extConsLbl(t *testing.T) { resource.TestCheckResourceAttr("data.aci_relation_from_l3out_consumer_label_to_route_control_profile.test", "direction", "import"), resource.TestCheckResourceAttr("data.aci_relation_from_l3out_consumer_label_to_route_control_profile.test", "target_dn", "uni/tn-test_tenant/prof-rt_ctrl_profile_1"), resource.TestCheckResourceAttr("data.aci_relation_from_l3out_consumer_label_to_route_control_profile.test", "annotation", "orchestrator:terraform"), - resource.TestCheckResourceAttr("data.aci_relation_from_l3out_consumer_label_to_route_control_profile.test", "direction", "import"), ), }, {