From 20904ce2bf5436077909ac82c98f35ab90f4d92d Mon Sep 17 00:00:00 2001 From: Chris Marget Date: Thu, 19 Dec 2024 10:43:36 -0500 Subject: [PATCH] update tests --- ...ity_template_interface_integration_test.go | 2 +- ...vity_template_loopback_integration_test.go | 2 +- ...ce_datacenter_connectivity_template_svi.go | 16 +- ...nectivity_template_svi_integration_test.go | 120 ++++++------ ...tivity_template_system_integration_test.go | 172 +++++++++--------- 5 files changed, 154 insertions(+), 158 deletions(-) diff --git a/apstra/resource_datacenter_connectivity_template_interface_integration_test.go b/apstra/resource_datacenter_connectivity_template_interface_integration_test.go index a77586c9..1ab6e213 100644 --- a/apstra/resource_datacenter_connectivity_template_interface_integration_test.go +++ b/apstra/resource_datacenter_connectivity_template_interface_integration_test.go @@ -5,11 +5,11 @@ package tfapstra_test import ( "context" "fmt" - "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "strconv" "strings" "testing" + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/Juniper/apstra-go-sdk/apstra" tfapstra "github.com/Juniper/terraform-provider-apstra/apstra" testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils" diff --git a/apstra/resource_datacenter_connectivity_template_loopback_integration_test.go b/apstra/resource_datacenter_connectivity_template_loopback_integration_test.go index 1f834ab9..527054f8 100644 --- a/apstra/resource_datacenter_connectivity_template_loopback_integration_test.go +++ b/apstra/resource_datacenter_connectivity_template_loopback_integration_test.go @@ -5,7 +5,6 @@ package tfapstra_test import ( "context" "fmt" - "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "math/rand/v2" "strconv" "strings" @@ -15,6 +14,7 @@ import ( tfapstra "github.com/Juniper/terraform-provider-apstra/apstra" testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils" "github.com/hashicorp/go-version" + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) diff --git a/apstra/resource_datacenter_connectivity_template_svi.go b/apstra/resource_datacenter_connectivity_template_svi.go index fc2f5074..a3ef5951 100644 --- a/apstra/resource_datacenter_connectivity_template_svi.go +++ b/apstra/resource_datacenter_connectivity_template_svi.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/types" ) var ( @@ -68,22 +67,15 @@ func (o *resourceDatacenterConnectivityTemplateSvi) ValidateConfig(ctx context.C } // extract DynamicBgpPeerings - var dynamicBgpPeerings []primitives.DynamicBgpPeering + var dynamicBgpPeerings map[string]primitives.DynamicBgpPeering resp.Diagnostics.Append(config.DynamicBgpPeerings.ElementsAs(ctx, &dynamicBgpPeerings, false)...) if resp.Diagnostics.HasError() { return } - for _, dynamicBgpPeering := range dynamicBgpPeerings { - // extract set value for use in error pathing. - // Note this doesn't currently work. https://github.com/hashicorp/terraform/issues/33491 - setVal, d := types.ObjectValueFrom(ctx, dynamicBgpPeering.AttrTypes(), &dynamicBgpPeering) - resp.Diagnostics.Append(d...) - if resp.Diagnostics.HasError() { - return - } - - dynamicBgpPeering.ValidateConfig(ctx, path.Root("dynamic_bgp_peerings").AtSetValue(setVal), &resp.Diagnostics) + // Validate each dynamic BGP peering object + for k, v := range dynamicBgpPeerings { + v.ValidateConfig(ctx, path.Root("dynamic_bgp_peerings").AtMapKey(k), &resp.Diagnostics) } } diff --git a/apstra/resource_datacenter_connectivity_template_svi_integration_test.go b/apstra/resource_datacenter_connectivity_template_svi_integration_test.go index ee708c61..1d06f4c6 100644 --- a/apstra/resource_datacenter_connectivity_template_svi_integration_test.go +++ b/apstra/resource_datacenter_connectivity_template_svi_integration_test.go @@ -5,6 +5,7 @@ package tfapstra_test import ( "context" "fmt" + "math/rand/v2" "strconv" "strings" "testing" @@ -14,6 +15,7 @@ import ( testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils" "github.com/Juniper/terraform-provider-apstra/apstra/utils" "github.com/hashicorp/go-version" + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/require" ) @@ -91,13 +93,13 @@ func (o resourceDataCenterConnectivityTemplateSvi) testChecks(t testing.TB, bpId result.append(t, "TestCheckResourceAttr", "bgp_peering_ip_endpoints.%", strconv.Itoa(len(o.bgpPeeringIpEndoints))) for k, v := range o.bgpPeeringIpEndoints { - for _, check := range v.testChecks("bgp_peering_ip_endpoints[" + k + "]") { + for _, check := range v.testChecks("bgp_peering_ip_endpoints." + k) { result.append(t, check[0], check[1:]...) } } - result.append(t, "TestCheckResourceAttr", "dynamic_bgp_peerings.%", strconv.Itoa(len(o.bgpPeeringIpEndoints))) - for k, v := range o.bgpPeeringIpEndoints { + result.append(t, "TestCheckResourceAttr", "dynamic_bgp_peerings.%", strconv.Itoa(len(o.dynamicBgpPeerings))) + for k, v := range o.dynamicBgpPeerings { for _, check := range v.testChecks("dynamic_bgp_peerings." + k) { result.append(t, check[0], check[1:]...) } @@ -130,62 +132,62 @@ func TestResourceDatacenteConnectivityTemplateSvi(t *testing.T) { } testCases := map[string]testCase{ - //"start_minimal": { - // steps: []testStep{ - // { - // config: resourceDataCenterConnectivityTemplateSvi{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSvi{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // description: acctest.RandString(6), - // tags: randomStrings(rand.IntN(5)+2, 6), - // bgpPeeringIpEndoints: randomBgpPeeringIpEndpointPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), - // dynamicBgpPeerings: randomDynamicBgpPeeringPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSvi{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // }, - // }, - // }, - //}, - //"start_maximal": { - // steps: []testStep{ - // { - // config: resourceDataCenterConnectivityTemplateSvi{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // description: acctest.RandString(6), - // tags: randomStrings(rand.IntN(5)+2, 6), - // bgpPeeringIpEndoints: randomBgpPeeringIpEndpointPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), - // dynamicBgpPeerings: randomDynamicBgpPeeringPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSvi{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSvi{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // description: acctest.RandString(6), - // tags: randomStrings(rand.IntN(5)+2, 6), - // bgpPeeringIpEndoints: randomBgpPeeringIpEndpointPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), - // dynamicBgpPeerings: randomDynamicBgpPeeringPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), - // }, - // }, - // }, - //}, + "start_minimal": { + steps: []testStep{ + { + config: resourceDataCenterConnectivityTemplateSvi{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSvi{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + description: acctest.RandString(6), + tags: randomStrings(rand.IntN(5)+2, 6), + bgpPeeringIpEndoints: randomBgpPeeringIpEndpointPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), + dynamicBgpPeerings: randomDynamicBgpPeeringPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSvi{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + }, + }, + }, + }, + "start_maximal": { + steps: []testStep{ + { + config: resourceDataCenterConnectivityTemplateSvi{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + description: acctest.RandString(6), + tags: randomStrings(rand.IntN(5)+2, 6), + bgpPeeringIpEndoints: randomBgpPeeringIpEndpointPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), + dynamicBgpPeerings: randomDynamicBgpPeeringPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSvi{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSvi{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + description: acctest.RandString(6), + tags: randomStrings(rand.IntN(5)+2, 6), + bgpPeeringIpEndoints: randomBgpPeeringIpEndpointPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), + dynamicBgpPeerings: randomDynamicBgpPeeringPrimitives(t, ctx, rand.IntN(3)+2, bp, cleanup), + }, + }, + }, + }, } resourceType := tfapstra.ResourceName(ctx, &tfapstra.ResourceDatacenterConnectivityTemplateSvi) diff --git a/apstra/resource_datacenter_connectivity_template_system_integration_test.go b/apstra/resource_datacenter_connectivity_template_system_integration_test.go index 3a52addf..bb2009d1 100644 --- a/apstra/resource_datacenter_connectivity_template_system_integration_test.go +++ b/apstra/resource_datacenter_connectivity_template_system_integration_test.go @@ -5,6 +5,7 @@ package tfapstra_test import ( "context" "fmt" + "math/rand/v2" "strconv" "strings" "testing" @@ -13,6 +14,7 @@ import ( tfapstra "github.com/Juniper/terraform-provider-apstra/apstra" testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils" "github.com/hashicorp/go-version" + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -100,91 +102,91 @@ func TestResourceDatacenteConnectivityTemplateSystem(t *testing.T) { } testCases := map[string]testCase{ - //"start_minimal": { - // steps: []testStep{ - // { - // config: resourceDataCenterConnectivityTemplateSystem{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSystem{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // description: acctest.RandString(6), - // tags: randomStrings(rand.IntN(5)+2, 6), - // customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSystem{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // }, - // }, - // }, - //}, - //"start_maximal": { - // steps: []testStep{ - // { - // config: resourceDataCenterConnectivityTemplateSystem{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // description: acctest.RandString(6), - // tags: randomStrings(rand.IntN(5)+2, 6), - // customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSystem{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSystem{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // description: acctest.RandString(6), - // tags: randomStrings(rand.IntN(5)+2, 6), - // customStaticRoutes: randomCustomStaticRoutes(t, ctx, 3, 3, bp, cleanup), - // }, - // }, - // }, - //}, - //"change_labels": { - // steps: []testStep{ - // { - // config: resourceDataCenterConnectivityTemplateSystem{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSystem{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSystem{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), - // }, - // }, - // { - // config: resourceDataCenterConnectivityTemplateSystem{ - // blueprintId: bp.Id().String(), - // name: acctest.RandString(6), - // customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), - // }, - // }, - // }, - //}, + "start_minimal": { + steps: []testStep{ + { + config: resourceDataCenterConnectivityTemplateSystem{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSystem{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + description: acctest.RandString(6), + tags: randomStrings(rand.IntN(5)+2, 6), + customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSystem{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + }, + }, + }, + }, + "start_maximal": { + steps: []testStep{ + { + config: resourceDataCenterConnectivityTemplateSystem{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + description: acctest.RandString(6), + tags: randomStrings(rand.IntN(5)+2, 6), + customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSystem{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSystem{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + description: acctest.RandString(6), + tags: randomStrings(rand.IntN(5)+2, 6), + customStaticRoutes: randomCustomStaticRoutes(t, ctx, 3, 3, bp, cleanup), + }, + }, + }, + }, + "change_labels": { + steps: []testStep{ + { + config: resourceDataCenterConnectivityTemplateSystem{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSystem{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSystem{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), + }, + }, + { + config: resourceDataCenterConnectivityTemplateSystem{ + blueprintId: bp.Id().String(), + name: acctest.RandString(6), + customStaticRoutes: randomCustomStaticRoutes(t, ctx, 2, 2, bp, cleanup), + }, + }, + }, + }, } resourceType := tfapstra.ResourceName(ctx, &tfapstra.ResourceDatacenterConnectivityTemplateSystem)