Skip to content

Commit

Permalink
Only run tests when ENV returns valid data
Browse files Browse the repository at this point in the history
  • Loading branch information
thogarty committed Jan 31, 2024
1 parent 8642f77 commit ac4ddbf
Show file tree
Hide file tree
Showing 3 changed files with 285 additions and 272 deletions.
83 changes: 42 additions & 41 deletions equinix/data_source_fabric_connection_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,54 @@ package equinix_test
import (
"fmt"
"github.com/equinix/terraform-provider-equinix/internal/acceptance"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"testing"
)

func TestAccFabricDataSourceConnection_PFCR(t *testing.T) {
ports := GetFabricEnvPorts(t)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
Providers: acceptance.TestAccProviders,
CheckDestroy: CheckConnectionDelete,
Steps: []resource.TestStep{
{
Config: testAccFabricDataSourceConnectionConfig(50, ports["pfcr"]["dot1q"][0].Uuid, ports["pfcr"]["dot1q"][1].Uuid),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.equinix_fabric_connection.test", "id"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "name", "ds_con_test_PFCR"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "bandwidth", "50"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "type", "EVPL_VC"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "redundancy.0.priority", "PRIMARY"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "order.0.purchase_order_number", "1-129105284100"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "a_side.0.access_point.0.type", "COLO"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "a_side.0.access_point.0.link_protocol.0.type", "DOT1Q"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "a_side.0.access_point.0.link_protocol.0.vlan_tag", "2444"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "a_side.0.access_point.0.location.0.metro_code", "DC"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "z_side.0.access_point.0.type", "COLO"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "z_side.0.access_point.0.link_protocol.0.type", "DOT1Q"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "z_side.0.access_point.0.link_protocol.0.vlan_tag", "2555"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "z_side.0.access_point.0.location.0.metro_code", "SV"),
),
ExpectNonEmptyPlan: true,
if len(ports) > 0 {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
Providers: acceptance.TestAccProviders,
CheckDestroy: CheckConnectionDelete,
Steps: []resource.TestStep{
{
Config: testAccFabricDataSourceConnectionConfig(50, ports["pfcr"]["dot1q"][0].Uuid, ports["pfcr"]["dot1q"][1].Uuid),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.equinix_fabric_connection.test", "id"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "name", "ds_con_test_PFCR"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "bandwidth", "50"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "type", "EVPL_VC"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "redundancy.0.priority", "PRIMARY"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "order.0.purchase_order_number", "1-129105284100"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "a_side.0.access_point.0.type", "COLO"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "a_side.0.access_point.0.link_protocol.0.type", "DOT1Q"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "a_side.0.access_point.0.link_protocol.0.vlan_tag", "2444"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "a_side.0.access_point.0.location.0.metro_code", "DC"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "z_side.0.access_point.0.type", "COLO"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "z_side.0.access_point.0.link_protocol.0.type", "DOT1Q"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "z_side.0.access_point.0.link_protocol.0.vlan_tag", "2555"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_connection.test", "z_side.0.access_point.0.location.0.metro_code", "SV"),
),
ExpectNonEmptyPlan: true,
},
},
},
})
})
}
}

func testAccFabricDataSourceConnectionConfig(bandwidth int32, aSidePortUuid, zSidePortUuid string) string {
Expand Down
130 changes: 67 additions & 63 deletions equinix/data_source_fabric_port_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,46 @@ type EnvPorts map[string]map[string][]v4.Port
func GetFabricEnvPorts(t *testing.T) EnvPorts {
var ports EnvPorts
portJson := os.Getenv(FabricDedicatedPortEnvVar)
if err := json.Unmarshal([]byte(portJson), &ports); err != nil {
if err := json.Unmarshal([]byte(portJson), &ports); portJson != "" && err != nil {
t.Fatalf("Failed reading port data from environment: %v, %s", err, portJson)
}
return ports
}

func TestAccDataSourceFabricPort_PNFV(t *testing.T) {
port := GetFabricEnvPorts(t)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
Providers: acceptance.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testDataSourceFabricPort(port["pnfv"]["dot1q"][0].Uuid),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "id", port["pnfv"]["dot1q"][0].Uuid),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "name", port["pnfv"]["dot1q"][0].Name),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_port.test", "bandwidth"),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_port.test", "used_bandwidth"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "type", string(*port["pnfv"]["dot1q"][0].Type_)),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "encapsulation.0.type", port["pnfv"]["dot1q"][0].Encapsulation.Type_),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "state", string(*port["pnfv"]["dot1q"][0].State)),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "redundancy.0.priority", string(*port["pnfv"]["dot1q"][0].Redundancy.Priority)),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_port.test", "lag_enabled"),
),
ports := GetFabricEnvPorts(t)
if len(ports) > 0 {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
Providers: acceptance.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testDataSourceFabricPort(ports["pnfv"]["dot1q"][0].Uuid),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "id", ports["pnfv"]["dot1q"][0].Uuid),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "name", ports["pnfv"]["dot1q"][0].Name),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_port.test", "bandwidth"),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_port.test", "used_bandwidth"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "type", string(*ports["pnfv"]["dot1q"][0].Type_)),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "encapsulation.0.type", ports["pnfv"]["dot1q"][0].Encapsulation.Type_),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "state", string(*ports["pnfv"]["dot1q"][0].State)),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "redundancy.0.priority", string(*ports["pnfv"]["dot1q"][0].Redundancy.Priority)),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_port.test", "lag_enabled"),
),
},
},
},
})
})
}
}

func testDataSourceFabricPort(port_uuid string) string {
Expand All @@ -69,39 +71,41 @@ func testDataSourceFabricPort(port_uuid string) string {
}

func TestAccDataSourceFabricPorts_PNFV(t *testing.T) {
port := GetFabricEnvPorts(t)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
Providers: acceptance.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testDataSourceFabricPorts(port["pnfv"]["dot1q"][0].Name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "id", port["pnfv"]["dot1q"][0].Uuid),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.name", port["pnfv"]["dot1q"][0].Name),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_ports.test", "data.0.bandwidth"),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_ports.test", "data.0.used_bandwidth"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.type", string(*port["pnfv"]["dot1q"][0].Type_)),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.state", string(*port["pnfv"]["dot1q"][0].State)),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.encapsulation.0.type", port["pnfv"]["dot1q"][0].Encapsulation.Type_),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.redundancy.0.priority", string(*port["pnfv"]["dot1q"][0].Redundancy.Priority)),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_ports.test", "data.0.lag_enabled"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.type", string(*port["pnfv"]["dot1q"][0].Type_)),
),
ports := GetFabricEnvPorts(t)
if len(ports) > 0 {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
Providers: acceptance.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testDataSourceFabricPorts(ports["pnfv"]["dot1q"][0].Name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "id", ports["pnfv"]["dot1q"][0].Uuid),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.name", ports["pnfv"]["dot1q"][0].Name),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_ports.test", "data.0.bandwidth"),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_ports.test", "data.0.used_bandwidth"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.type", string(*ports["pnfv"]["dot1q"][0].Type_)),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.state", string(*ports["pnfv"]["dot1q"][0].State)),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.encapsulation.0.type", ports["pnfv"]["dot1q"][0].Encapsulation.Type_),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.redundancy.0.priority", string(*ports["pnfv"]["dot1q"][0].Redundancy.Priority)),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_ports.test", "data.0.lag_enabled"),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.type", string(*ports["pnfv"]["dot1q"][0].Type_)),
),
},
},
},
})
})
}
}

func testDataSourceFabricPorts(port_name string) string {
Expand Down
Loading

0 comments on commit ac4ddbf

Please sign in to comment.