Skip to content

Commit

Permalink
Merge pull request #774 from Juniper/resource-generator-test-update
Browse files Browse the repository at this point in the history
Add `subnet_prefix_len` attribute to resource generator test
  • Loading branch information
chrismarget-j authored Aug 9, 2024
2 parents 9b2036e + 1127b21 commit 7714c95
Showing 1 changed file with 51 additions and 36 deletions.
87 changes: 51 additions & 36 deletions apstra/resource_freeform_resource_generator_integraion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"fmt"
"net"
"strconv"
"testing"

"github.com/Juniper/apstra-go-sdk/apstra"
Expand All @@ -21,23 +22,25 @@ import (
const (
resourceFreeformResourceGeneratorHcl = `
resource %q %q {
blueprint_id = %q
name = %q
type = %q
scope = %q
allocated_from = %s
container_id = %q
blueprint_id = %q
name = %q
type = %q
scope = %q
allocated_from = %s
container_id = %q
subnet_prefix_len = %s
}
`
)

type resourceFreeformResourceGenerator struct {
blueprintId string
name string
resourceType apstra.FFResourceType
scope string
allocatedFrom string
containerId string
blueprintId string
name string
resourceType apstra.FFResourceType
scope string
allocatedFrom string
containerId string
subnetPrefixLen *int
}

func (o resourceFreeformResourceGenerator) render(rType, rName string) string {
Expand All @@ -49,6 +52,7 @@ func (o resourceFreeformResourceGenerator) render(rType, rName string) string {
o.scope,
stringOrNull(o.allocatedFrom),
o.containerId,
intPtrOrNull(o.subnetPrefixLen),
)
}

Expand All @@ -67,6 +71,11 @@ func (o resourceFreeformResourceGenerator) testChecks(t testing.TB, rType, rName
} else {
result.append(t, "TestCheckResourceAttr", "allocated_from", o.allocatedFrom)
}
if o.subnetPrefixLen == nil {
result.append(t, "TestCheckNoResourceAttr", "subnet_prefix_len")
} else {
result.append(t, "TestCheckResourceAttr", "subnet_prefix_len", strconv.Itoa(*o.subnetPrefixLen))
}

return result
}
Expand Down Expand Up @@ -180,6 +189,7 @@ func TestResourceFreeformResourceGenerator(t *testing.T) {
require.NoError(t, err)
return allocGroup
}

newIntAllocationGroup := func(t testing.TB) apstra.ObjectId {
t.Helper()

Expand Down Expand Up @@ -208,6 +218,7 @@ func TestResourceFreeformResourceGenerator(t *testing.T) {
type testStep struct {
config resourceFreeformResourceGenerator
}

type testCase struct {
apiVersionConstraints version.Constraints
steps []testStep
Expand Down Expand Up @@ -278,22 +289,24 @@ func TestResourceFreeformResourceGenerator(t *testing.T) {
steps: []testStep{
{
config: resourceFreeformResourceGenerator{
blueprintId: bp.Id().String(),
name: acctest.RandString(6),
scope: "node('system', name='target')",
containerId: string(groupId),
resourceType: apstra.FFResourceTypeIpv4,
allocatedFrom: string(newIpv4AllocationGroup(t)),
blueprintId: bp.Id().String(),
name: acctest.RandString(6),
scope: "node('system', name='target')",
containerId: string(groupId),
resourceType: apstra.FFResourceTypeIpv4,
allocatedFrom: string(newIpv4AllocationGroup(t)),
subnetPrefixLen: utils.ToPtr(27),
},
},
{
config: resourceFreeformResourceGenerator{
blueprintId: bp.Id().String(),
name: acctest.RandString(6),
scope: "node('system', deploy_mode='deploy', name='target')",
containerId: string(groupId),
resourceType: apstra.FFResourceTypeIpv4,
allocatedFrom: string(newIpv4AllocationGroup(t)),
blueprintId: bp.Id().String(),
name: acctest.RandString(6),
scope: "node('system', deploy_mode='deploy', name='target')",
containerId: string(groupId),
resourceType: apstra.FFResourceTypeIpv4,
allocatedFrom: string(newIpv4AllocationGroup(t)),
subnetPrefixLen: utils.ToPtr(28),
},
},
},
Expand All @@ -302,22 +315,24 @@ func TestResourceFreeformResourceGenerator(t *testing.T) {
steps: []testStep{
{
config: resourceFreeformResourceGenerator{
blueprintId: bp.Id().String(),
name: acctest.RandString(6),
scope: "node('system', name='target')",
containerId: string(groupId),
resourceType: apstra.FFResourceTypeIpv6,
allocatedFrom: string(newIpv6AllocationGroup(t)),
blueprintId: bp.Id().String(),
name: acctest.RandString(6),
scope: "node('system', name='target')",
containerId: string(groupId),
resourceType: apstra.FFResourceTypeIpv6,
allocatedFrom: string(newIpv6AllocationGroup(t)),
subnetPrefixLen: utils.ToPtr(127),
},
},
{
config: resourceFreeformResourceGenerator{
blueprintId: bp.Id().String(),
name: acctest.RandString(6),
scope: "node('system', deploy_mode='deploy', name='target')",
containerId: string(groupId),
resourceType: apstra.FFResourceTypeIpv6,
allocatedFrom: string(newIpv6AllocationGroup(t)),
blueprintId: bp.Id().String(),
name: acctest.RandString(6),
scope: "node('system', deploy_mode='deploy', name='target')",
containerId: string(groupId),
resourceType: apstra.FFResourceTypeIpv6,
allocatedFrom: string(newIpv6AllocationGroup(t)),
subnetPrefixLen: utils.ToPtr(126),
},
},
},
Expand Down

0 comments on commit 7714c95

Please sign in to comment.