Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Dec 19, 2024
1 parent d1047df commit 20904ce
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package tfapstra_test
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"math/rand/v2"
"strconv"
"strings"
Expand All @@ -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"
)

Expand Down
16 changes: 4 additions & 12 deletions apstra/resource_datacenter_connectivity_template_svi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package tfapstra_test
import (
"context"
"fmt"
"math/rand/v2"
"strconv"
"strings"
"testing"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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:]...)
}
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 20904ce

Please sign in to comment.