Skip to content

Commit

Permalink
test(Instance/Volume): fix "Error: only block volume can be resized" (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeansebastienh authored May 14, 2021
1 parent a10addc commit 30e2489
Show file tree
Hide file tree
Showing 4 changed files with 576 additions and 6,866 deletions.
40 changes: 2 additions & 38 deletions scaleway/resource_instance_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scaleway

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -113,12 +114,7 @@ func TestAccScalewayInstanceServer_RootVolume1(t *testing.T) {
CheckDestroy: testAccCheckScalewayInstanceServerDestroy(tt),
Steps: []resource.TestStep{
{
// 10 Gb
Config: `
resource "scaleway_instance_volume" "local" {
size_in_gb = 10
type = "l_ssd"
}
resource "scaleway_instance_server" "base" {
image = "ubuntu_focal"
type = "DEV1-S"
Expand All @@ -127,40 +123,8 @@ func TestAccScalewayInstanceServer_RootVolume1(t *testing.T) {
delete_on_termination = true
}
tags = [ "terraform-test", "scaleway_instance_server", "root_volume" ]
additional_volume_ids = [scaleway_instance_volume.local.id]
}`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayInstanceServerExists(tt, "scaleway_instance_server.base"),
resource.TestCheckResourceAttr("scaleway_instance_server.base", "root_volume.0.delete_on_termination", "true"),
resource.TestCheckResourceAttr("scaleway_instance_server.base", "root_volume.0.size_in_gb", "10"),
resource.TestCheckResourceAttrSet("scaleway_instance_server.base", "root_volume.0.volume_id"),
resource.TestCheckResourceAttr("scaleway_instance_server.base", "tags.2", "root_volume"),
),
},
{
// 11 Gb
Config: `
resource "scaleway_instance_volume" "local" {
size_in_gb = 9
type = "l_ssd"
}
resource "scaleway_instance_server" "base" {
image = "ubuntu_focal"
type = "DEV1-S"
root_volume {
size_in_gb = 11
delete_on_termination = true
}
tags = [ "terraform-test", "scaleway_instance_server", "root_volume" ]
additional_volume_ids = [scaleway_instance_volume.local.id]
}`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayInstanceServerExists(tt, "scaleway_instance_server.base"),
resource.TestCheckResourceAttr("scaleway_instance_server.base", "root_volume.0.delete_on_termination", "true"),
resource.TestCheckResourceAttr("scaleway_instance_server.base", "root_volume.0.size_in_gb", "11"),
resource.TestCheckResourceAttrSet("scaleway_instance_server.base", "root_volume.0.volume_id"),
resource.TestCheckResourceAttr("scaleway_instance_server.base", "tags.2", "root_volume"),
),
ExpectError: regexp.MustCompile("total local volume size must be equal to 20 GB"),
},
},
})
Expand Down
31 changes: 31 additions & 0 deletions scaleway/resource_instance_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,37 @@ func TestAccScalewayInstanceVolume_ResizeBlock(t *testing.T) {
})
}

func TestAccScalewayInstanceVolume_ResizeNotBlock(t *testing.T) {
tt := NewTestTools(t)
defer tt.Cleanup()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: testAccCheckScalewayInstanceVolumeDestroy(tt),
Steps: []resource.TestStep{
{
Config: `
resource "scaleway_instance_volume" "main" {
type = "l_ssd"
size_in_gb = 20
}`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayInstanceVolumeExists(tt, "scaleway_instance_volume.main"),
resource.TestCheckResourceAttr("scaleway_instance_volume.main", "size_in_gb", "20"),
),
},
{
Config: `
resource "scaleway_instance_volume" "main" {
type = "l_ssd"
size_in_gb = 30
}`,
ExpectError: regexp.MustCompile("only block volume can be resized"),
},
},
})
}

func TestAccScalewayInstanceVolume_CannotResizeBlockDown(t *testing.T) {
tt := NewTestTools(t)
defer tt.Cleanup()
Expand Down
Loading

0 comments on commit 30e2489

Please sign in to comment.