Skip to content

Commit

Permalink
Testing Update and create
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushrangwala committed Aug 30, 2023
1 parent 0f76dd9 commit 9ed778f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 14 deletions.
4 changes: 2 additions & 2 deletions equinix/resource_metal_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,8 @@ func doReinstall(ctx context.Context, client *packngo.Client, d *schema.Resource
return friendlyError(err)
}

deleteTimeout := d.Timeout(schema.TimeoutUpdate) - 30*time.Second - time.Since(start)
if err := waitForActiveDevice(ctx, d, meta, deleteTimeout); err != nil {
updateTimeout := d.Timeout(schema.TimeoutUpdate) - 30*time.Second - time.Since(start)
if err := waitForActiveDevice(ctx, d, meta, updateTimeout); err != nil {
return err
}
}
Expand Down
95 changes: 83 additions & 12 deletions equinix/resource_metal_device_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,28 +916,74 @@ resource "equinix_metal_device" "test_ipxe_missing" {
always_pxe = true
}`

func testAccMetalDeviceConfig_timeout(projSuffix string) string {
func testAccMetalDeviceConfig_timeout(projSuffix, createTimeout, updateTimeout, deleteTimeout string) string {
if createTimeout == "" {
createTimeout = "20m"
}
if updateTimeout == "" {
updateTimeout = "20m"
}
if deleteTimeout == "" {
deleteTimeout = "20m"
}

return fmt.Sprintf(`
%s
resource "equinix_metal_project" "test" {
name = "tfacc-device-%s"
}
resource "equinix_metal_device" "test" {
hostname = "tfacc-test-device"
plan = local.plan
metro = local.metro
operating_system = local.os
billing_cycle = "hourly"
project_id = "${equinix_metal_project.test.id}"
termination_time = "%s"
timeouts {
create = "%s"
update = "%s"
delete = "%s"
}
}
`, confAccMetalDevice_base(preferable_plans, preferable_metros, preferable_os), projSuffix, testDeviceTerminationTime(), createTimeout, updateTimeout, deleteTimeout)
}

func testAccMetalDeviceConfig_reinstall_timeout(projSuffix, updateTimeout string) string {
if updateTimeout == "" {
updateTimeout = "20m"
}

return fmt.Sprintf(`
%s
resource "equinix_metal_project" "test" {
name = "tfacc-device-%s"
}
resource "equinix_metal_device" "test" {
hostname = "tfacc-test-device"
description = "test-desc"
plan = "c3.small.x86"
metro = "DA"
operating_system = "ubuntu_20_04"
plan = local.plan
metro = local.metro
operating_system = local.os
billing_cycle = "hourly"
project_id = "${equinix_metal_project.test.id}"
user_data = "#!/usr/bin/env sh\necho Reinstall\n"
termination_time = "%s"
depends_on = [equinix_metal_project.test]
reinstall {
enabled = true
deprovision_fast = true
}
timeouts {
create = "10s"
update = "10s"
update = "%s"
}
}
`, projSuffix, testDeviceTerminationTime())
`, confAccMetalDevice_base(preferable_plans, preferable_metros, preferable_os), projSuffix, testDeviceTerminationTime(), updateTimeout)
}

type mockDeviceService struct {
Expand Down Expand Up @@ -1162,7 +1208,7 @@ func testAccWaitForMetalDeviceActive(project, deviceHostName string) resource.Im
}
}

func TestAccMetalDevice_importBasicTimeout(t *testing.T) {
func TestAccMetalDeviceCreate_timeout(t *testing.T) {
rs := acctest.RandString(10)
r := "equinix_metal_device.test"
hostname := "tfacc-test-device"
Expand All @@ -1175,7 +1221,7 @@ func TestAccMetalDevice_importBasicTimeout(t *testing.T) {
CheckDestroy: testAccMetalDeviceCheckDestroyed,
Steps: []resource.TestStep{
{
Config: testAccMetalDeviceConfig_timeout(rs),
Config: testAccMetalDeviceConfig_timeout(rs, "10s", "", ""),
ExpectError: matchErrDeviceReadyTimeout,
},
{
Expand All @@ -1188,9 +1234,34 @@ func TestAccMetalDevice_importBasicTimeout(t *testing.T) {
ImportStatePersist: true,
},
{
Config: testAccMetalDeviceConfig_timeout(rs),
Config: testAccMetalDeviceConfig_timeout(rs, "", "", ""),
Destroy: true,
},
},
})
}

func TestAccMetalDeviceUpdate_timeout(t *testing.T) {
var d1 packngo.Device
rs := acctest.RandString(10)
r := "equinix_metal_device.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: testExternalProviders,
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccMetalDeviceCheckDestroyed,
Steps: []resource.TestStep{
{
Config: testAccMetalDeviceConfig_timeout(rs, "", "", ""),
Check: resource.ComposeTestCheckFunc(
testAccMetalDeviceExists(r, &d1),
),
},
{
Config: testAccMetalDeviceConfig_reinstall_timeout(rs, "10s"),
ExpectError: matchErrDeviceReadyTimeout,
},
},
})
}

0 comments on commit 9ed778f

Please sign in to comment.