Skip to content

Commit

Permalink
use enum package for objects which have moved
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Sep 16, 2024
1 parent 4e73645 commit 2ed614e
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 160 deletions.
3 changes: 2 additions & 1 deletion apstra/data_source_datacenter_blueprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/apstra-go-sdk/apstra/enum"
testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -51,7 +52,7 @@ func TestDatasourceDatacenterBlueprint(t *testing.T) {
},
// DefaultSviL3Mtu: nil,
EsiMacMsb: utils.ToPtr(uint8(4)),
EvpnGenerateType5HostRoutes: &apstra.FeatureSwitchEnumEnabled,
EvpnGenerateType5HostRoutes: &enum.FeatureSwitchEnumEnabled,
ExternalRouterMtu: utils.ToPtr(uint16(9002)),
// FabricL3Mtu: nil,
Ipv6Enabled: utils.ToPtr(true),
Expand Down
12 changes: 7 additions & 5 deletions apstra/data_source_datacenter_external_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package tfapstra_test
import (
"context"
"fmt"
"math/rand"
"testing"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/apstra-go-sdk/apstra/enum"
testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"math/rand"
"testing"
)

const (
Expand Down Expand Up @@ -47,7 +49,7 @@ func TestDatacenterExternalGateway(t *testing.T) {

rgConfigs := []apstra.RemoteGatewayData{
{
RouteTypes: apstra.RemoteGatewayRouteTypesAll,
RouteTypes: enum.RemoteGatewayRouteTypesAll,
LocalGwNodes: leafIds,
GwAsn: rand.Uint32(),
GwIp: randIpvAddressMust(t, "10.0.0.0/8"),
Expand All @@ -58,7 +60,7 @@ func TestDatacenterExternalGateway(t *testing.T) {
Password: &password,
},
{
RouteTypes: apstra.RemoteGatewayRouteTypesFiveOnly,
RouteTypes: enum.RemoteGatewayRouteTypesFiveOnly,
LocalGwNodes: leafIds,
GwAsn: rand.Uint32(),
GwIp: randIpvAddressMust(t, "10.0.0.0/8"),
Expand Down Expand Up @@ -137,7 +139,7 @@ func TestDatacenterExternalGateway(t *testing.T) {

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
//Steps: stepsById,
// Steps: stepsById,
Steps: append(stepsById, stepsByName...),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ package tfapstra_test
import (
"context"
"fmt"
testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils"
"math/rand/v2"
"net"
"strconv"
"strings"
"testing"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/apstra-go-sdk/apstra/enum"
tfapstra "github.com/Juniper/terraform-provider-apstra/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/constants"
testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -798,7 +799,7 @@ func randomRoutingZoneConstraints(t testing.TB, ctx context.Context, count int,
for i := range result {
policyId, err := client.CreateRoutingZoneConstraint(ctx, &apstra.RoutingZoneConstraintData{
Label: acctest.RandString(6),
Mode: oneOf(apstra.RoutingZoneConstraintModeAllow, apstra.RoutingZoneConstraintModeDeny, apstra.RoutingZoneConstraintModeNone),
Mode: oneOf(enum.RoutingZoneConstraintModeAllow, enum.RoutingZoneConstraintModeDeny, enum.RoutingZoneConstraintModeNone),
MaxRoutingZones: oneOf(nil, utils.ToPtr(0), utils.ToPtr(1), utils.ToPtr(2)),
RoutingZoneIds: nil,
})
Expand Down
95 changes: 48 additions & 47 deletions apstra/resource_datacenter_device_allocation_test.go

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions apstra/resource_datacenter_external_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ package tfapstra_test
import (
"context"
"fmt"
"github.com/Juniper/apstra-go-sdk/apstra"
testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"net"
"strconv"
"strings"
"testing"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/apstra-go-sdk/apstra/enum"
testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const (
Expand All @@ -35,7 +37,7 @@ type testCaseResourceExternalGateway struct {
name string
ipAddress net.IP
asn uint32
routeTypes apstra.RemoteGatewayRouteTypes
routeTypes enum.RemoteGatewayRouteTypes
nodes string
ttl *uint8
keepaliveTime *uint16
Expand Down Expand Up @@ -74,15 +76,15 @@ func TestResourceDatacenterExternalGateway(t *testing.T) {
name: "name1",
ipAddress: net.IP{1, 1, 1, 1},
asn: 1,
routeTypes: apstra.RemoteGatewayRouteTypesAll,
routeTypes: enum.RemoteGatewayRouteTypesAll,
nodes: leafIds[0],
testCheckFunc: resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{
resource.TestCheckResourceAttrSet("apstra_datacenter_external_gateway.test", "id"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "blueprint_id", bp.Id().String()),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "name", "name1"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "ip_address", "1.1.1.1"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "asn", "1"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "evpn_route_types", apstra.RemoteGatewayRouteTypesAll.Value),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "evpn_route_types", enum.RemoteGatewayRouteTypesAll.Value),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "local_gateway_nodes.#", "1"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "local_gateway_nodes.0", leafIds[0]),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "ttl", "30"), // default
Expand All @@ -94,15 +96,15 @@ func TestResourceDatacenterExternalGateway(t *testing.T) {
name: "name2",
ipAddress: net.IP{1, 1, 1, 2},
asn: 2,
routeTypes: apstra.RemoteGatewayRouteTypesFiveOnly,
routeTypes: enum.RemoteGatewayRouteTypesFiveOnly,
nodes: strings.Join(leafIds[1:], `","`),
testCheckFunc: resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{
resource.TestCheckResourceAttrSet("apstra_datacenter_external_gateway.test", "id"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "blueprint_id", bp.Id().String()),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "name", "name2"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "ip_address", "1.1.1.2"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "asn", "2"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "evpn_route_types", apstra.RemoteGatewayRouteTypesFiveOnly.Value),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "evpn_route_types", enum.RemoteGatewayRouteTypesFiveOnly.Value),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "local_gateway_nodes.#", strconv.Itoa(len(leafIds)-1)),
resource.TestCheckTypeSetElemAttr("apstra_datacenter_external_gateway.test", "local_gateway_nodes.*", leafIds[1]),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "ttl", "30"), // default
Expand All @@ -114,7 +116,7 @@ func TestResourceDatacenterExternalGateway(t *testing.T) {
name: "name3",
ipAddress: net.IP{1, 1, 1, 3},
asn: 3,
routeTypes: apstra.RemoteGatewayRouteTypesAll,
routeTypes: enum.RemoteGatewayRouteTypesAll,
nodes: leafIds[0],
ttl: &uint8Val3,
keepaliveTime: &uint16Val1,
Expand All @@ -126,7 +128,7 @@ func TestResourceDatacenterExternalGateway(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "name", "name3"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "ip_address", "1.1.1.3"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "asn", "3"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "evpn_route_types", apstra.RemoteGatewayRouteTypesAll.Value),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "evpn_route_types", enum.RemoteGatewayRouteTypesAll.Value),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "local_gateway_nodes.#", "1"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "local_gateway_nodes.0", leafIds[0]),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "ttl", "3"),
Expand All @@ -139,15 +141,15 @@ func TestResourceDatacenterExternalGateway(t *testing.T) {
name: "name1",
ipAddress: net.IP{1, 1, 1, 1},
asn: 1,
routeTypes: apstra.RemoteGatewayRouteTypesAll,
routeTypes: enum.RemoteGatewayRouteTypesAll,
nodes: leafIds[0],
testCheckFunc: resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{
resource.TestCheckResourceAttrSet("apstra_datacenter_external_gateway.test", "id"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "blueprint_id", bp.Id().String()),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "name", "name1"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "ip_address", "1.1.1.1"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "asn", "1"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "evpn_route_types", apstra.RemoteGatewayRouteTypesAll.Value),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "evpn_route_types", enum.RemoteGatewayRouteTypesAll.Value),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "local_gateway_nodes.#", "1"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "local_gateway_nodes.0", leafIds[0]),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "ttl", "30"), // default
Expand All @@ -159,7 +161,7 @@ func TestResourceDatacenterExternalGateway(t *testing.T) {
name: "name2",
ipAddress: net.IP{1, 1, 1, 2},
asn: 2,
routeTypes: apstra.RemoteGatewayRouteTypesFiveOnly,
routeTypes: enum.RemoteGatewayRouteTypesFiveOnly,
nodes: strings.Join(leafIds[1:], `","`),
password: "big secret2",
testCheckFunc: resource.ComposeAggregateTestCheckFunc([]resource.TestCheckFunc{
Expand All @@ -168,7 +170,7 @@ func TestResourceDatacenterExternalGateway(t *testing.T) {
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "name", "name2"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "ip_address", "1.1.1.2"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "asn", "2"),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "evpn_route_types", apstra.RemoteGatewayRouteTypesFiveOnly.Value),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "evpn_route_types", enum.RemoteGatewayRouteTypesFiveOnly.Value),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "local_gateway_nodes.#", strconv.Itoa(len(leafIds)-1)),
resource.TestCheckTypeSetElemAttr("apstra_datacenter_external_gateway.test", "local_gateway_nodes.*", leafIds[1]),
resource.TestCheckResourceAttr("apstra_datacenter_external_gateway.test", "ttl", "30"), // default
Expand Down
48 changes: 25 additions & 23 deletions apstra/resource_datacenter_security_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ package tfapstra_test
import (
"context"
"fmt"
"strconv"
"strings"
"testing"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/apstra-go-sdk/apstra/enum"
apiversions "github.com/Juniper/terraform-provider-apstra/apstra/api_versions"
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"
"strconv"
"strings"
"testing"
)

const (
Expand Down Expand Up @@ -75,12 +77,12 @@ func (o testCaseResourceSecurityPolicy) renderConfig(bpId apstra.ObjectId) strin
return sb.String()
}

renderEstablished := func(tsq *apstra.TcpStateQualifier) string {
renderEstablished := func(tsq *enum.TcpStateQualifier) string {
if tsq == nil {
return "null"
}

return strconv.FormatBool(*tsq == apstra.TcpStateQualifierEstablished)
return strconv.FormatBool(*tsq == enum.TcpStateQualifierEstablished)
}

renderRule := func(rule apstra.PolicyRule) string {
Expand Down Expand Up @@ -238,8 +240,8 @@ func TestResourceDatacenterSecurityPolicy(t *testing.T) {
Data: &apstra.PolicyRuleData{
Label: "60",
Description: "",
Protocol: apstra.PolicyRuleProtocolIcmp,
Action: apstra.PolicyRuleActionDeny,
Protocol: enum.PolicyRuleProtocolIcmp,
Action: enum.PolicyRuleActionDeny,
},
},
},
Expand All @@ -263,8 +265,8 @@ func TestResourceDatacenterSecurityPolicy(t *testing.T) {
Data: &apstra.PolicyRuleData{
Label: "70",
Description: "seventy",
Protocol: apstra.PolicyRuleProtocolIp,
Action: apstra.PolicyRuleActionDenyLog,
Protocol: enum.PolicyRuleProtocolIp,
Action: enum.PolicyRuleActionDenyLog,
},
},
},
Expand All @@ -291,25 +293,25 @@ func TestResourceDatacenterSecurityPolicy(t *testing.T) {
Data: &apstra.PolicyRuleData{
Label: "80",
Description: "eighty",
Protocol: apstra.PolicyRuleProtocolUdp,
Action: apstra.PolicyRuleActionPermit,
Protocol: enum.PolicyRuleProtocolUdp,
Action: enum.PolicyRuleActionPermit,
},
},
{
Data: &apstra.PolicyRuleData{
Label: "81",
Description: "eightyone",
Protocol: apstra.PolicyRuleProtocolTcp,
Action: apstra.PolicyRuleActionPermitLog,
Protocol: enum.PolicyRuleProtocolTcp,
Action: enum.PolicyRuleActionPermitLog,
},
},
{
Data: &apstra.PolicyRuleData{
Label: "82",
Description: "eightytwo",
Protocol: apstra.PolicyRuleProtocolTcp,
Action: apstra.PolicyRuleActionPermit,
TcpStateQualifier: &apstra.TcpStateQualifierEstablished,
Protocol: enum.PolicyRuleProtocolTcp,
Action: enum.PolicyRuleActionPermit,
TcpStateQualifier: &enum.TcpStateQualifierEstablished,
SrcPort: apstra.PortRanges{
{First: 1, Last: 1},
{First: 3, Last: 5},
Expand Down Expand Up @@ -360,25 +362,25 @@ func TestResourceDatacenterSecurityPolicy(t *testing.T) {
Data: &apstra.PolicyRuleData{
Label: "90",
Description: "ninety",
Protocol: apstra.PolicyRuleProtocolUdp,
Action: apstra.PolicyRuleActionPermit,
Protocol: enum.PolicyRuleProtocolUdp,
Action: enum.PolicyRuleActionPermit,
},
},
{
Data: &apstra.PolicyRuleData{
Label: "91",
Description: "ninetyone",
Protocol: apstra.PolicyRuleProtocolTcp,
Action: apstra.PolicyRuleActionPermitLog,
Protocol: enum.PolicyRuleProtocolTcp,
Action: enum.PolicyRuleActionPermitLog,
},
},
{
Data: &apstra.PolicyRuleData{
Label: "92",
Description: "ninetytwo",
Protocol: apstra.PolicyRuleProtocolTcp,
Action: apstra.PolicyRuleActionPermit,
TcpStateQualifier: &apstra.TcpStateQualifierEstablished,
Protocol: enum.PolicyRuleProtocolTcp,
Action: enum.PolicyRuleActionPermit,
TcpStateQualifier: &enum.TcpStateQualifierEstablished,
SrcPort: apstra.PortRanges{
{First: 1, Last: 1},
{First: 7, Last: 9},
Expand Down
Loading

0 comments on commit 2ed614e

Please sign in to comment.