Skip to content

Commit

Permalink
remove workaround from test since we don't need it any more
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Oct 3, 2024
1 parent 2dfbe9f commit 25962b2
Showing 1 changed file with 2 additions and 47 deletions.
49 changes: 2 additions & 47 deletions internal/resources/metal/device/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http/httptest"
"regexp"
"testing"
"time"

"github.com/equinix/terraform-provider-equinix/internal/acceptance"
"github.com/equinix/terraform-provider-equinix/internal/config"
Expand Down Expand Up @@ -914,43 +913,8 @@ resource "equinix_metal_device" "test" {
`, acceptance.ConfAccMetalDevice_base(acceptance.Preferable_plans, acceptance.Preferable_metros, acceptance.Preferable_os), projSuffix, acceptance.TestDeviceTerminationTime(), updateTimeout)
}

func testAccWaitForMetalDeviceActive(project, deviceHostName string) resource.ImportStateIdFunc {
return func(state *terraform.State) (string, error) {
defaultTimeout := 20 * time.Minute

rs, ok := state.RootModule().Resources[project]
if !ok {
return "", fmt.Errorf("Project Not found in the state: %s", project)
}
if rs.Primary.ID == "" {
return "", fmt.Errorf("No Record ID is set")
}

meta := acceptance.TestAccProvider.Meta()
rd := new(schema.ResourceData)
client := meta.(*config.Config).NewMetalClientForTesting()
resp, _, err := client.DevicesApi.FindProjectDevices(context.TODO(), rs.Primary.ID).Search(deviceHostName).Execute()
if err != nil {
return "", fmt.Errorf("error while fetching devices for project [%s], error: %w", rs.Primary.ID, err)
}
devices := resp.Devices
if len(devices) == 0 {
return "", fmt.Errorf("Not able to find devices in project [%s]", rs.Primary.ID)
}
if len(devices) > 1 {
return "", fmt.Errorf("Found more than one device with the hostname in project [%s]", rs.Primary.ID)
}

rd.SetId(devices[0].GetId())
return devices[0].GetId(), device.WaitForActiveDevice(context.Background(), rd, acceptance.TestAccProvider.Meta(), defaultTimeout)
}
}

func TestAccMetalDeviceCreate_timeout(t *testing.T) {
rs := acctest.RandString(10)
r := "equinix_metal_device.test"
hostname := "tfacc-test-device"
project := "equinix_metal_project.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
Expand All @@ -963,17 +927,8 @@ func TestAccMetalDeviceCreate_timeout(t *testing.T) {
ExpectError: matchErrDeviceReadyTimeout,
},
{
/**
Step 1 errors out, state doesnt have device, need to import that in the state before deleting
*/
ResourceName: r,
ImportState: true,
ImportStateIdFunc: testAccWaitForMetalDeviceActive(project, hostname),
ImportStatePersist: true,
},
{
Config: testAccMetalDeviceConfig_timeout(rs, "", "", ""),
Destroy: true,
// Allow the device to reach ready state so it can be destroyed after test
Config: testAccMetalDeviceConfig_timeout(rs, "", "", ""),
},
},
})
Expand Down

0 comments on commit 25962b2

Please sign in to comment.