Skip to content

Commit

Permalink
Tests: Parseable size Parameter
Browse files Browse the repository at this point in the history
Add test to ensure that a non-parseable `size` parameter in a `disk`
subresource of a `virtualmachine` resource generates an appropriate
error message.
The `size` parameter is not mandatory in all configurations, but when it
is, it must be a parseable `resource.Quantity`, otherwise a panic and
crash would ensue.

Signed-off-by: Moritz Röhrich <[email protected]>
  • Loading branch information
m-ildefons committed Dec 17, 2024
1 parent 6cd9216 commit 4412fb5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ RUN wget --quiet https://github.com/docker/buildx/releases/download/v0.13.1/buil
mv buildx-v0.13.1.linux-${ARCH} /usr/local/bin/buildx && \
mv terraform /usr/local/bin/terraform

ENV DAPPER_RUN_ARGS="--network host -v /run/containerd/containerd.sock:/run/containerd/containerd.sock"
ENV DAPPER_ENV REPO TAG DRONE_TAG
ENV DAPPER_SOURCE /go/src/github.com/harvester/terraform-provider-harvester
ENV DAPPER_OUTPUT ./bin ./dist
Expand Down
62 changes: 62 additions & 0 deletions internal/tests/resource_virtualmachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"context"
"fmt"
"regexp"
"testing"

"github.com/google/uuid"
Expand Down Expand Up @@ -137,6 +138,67 @@ func TestAccVirtualMachine_input(t *testing.T) {
})
}

func TestAccVirtualMachine_disk_size(t *testing.T) {
var (
testAccImageName = "test-acc-image-leap-" + uuid.New().String()[:6]
testAccImageResourceName = constants.ResourceTypeImage + "." + testAccImageName
ctx = context.Background()
)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVirtualMachineDestroy(ctx),
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource harvester_image "%s" {
name = "leap-15.6"
namespace = "default"
display_name = "openSUSE-Leap-15.6"
source_type = "download"
url = "https://download.opensuse.org/repositories/Cloud:/Images:/Leap_15.6/images/openSUSE-Leap-15.6.x86_64-NoCloud.qcow2"
}
`,
testAccImageName,
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testAccImageResourceName, constants.FieldCommonName, "leap-15.6"),
resource.TestCheckResourceAttr(testAccImageResourceName, constants.FieldCommonNamespace, "default"),
),
},
{
Config: `
resource harvester_virtualmachine "disk_test" {
name = "disk-test"
cpu = 1
memory = "1Gi"
run_strategy = "RerunOnFailure"
machine_type = "q35"
network_interface {
name = "default"
}
disk {
name = "cdrom-disk"
type = "cd-rom"
bus = "sata"
boot_order = 1
size = "foobar"
image = "default/leap-15.6"
}
}
`,
ExpectError: regexp.MustCompile(".*is not a parsable quantity.*"),
Check: resource.ComposeTestCheckFunc(),
},
},
})
}

func testAccVirtualMachineExists(ctx context.Context, n string, vm *kubevirtv1.VirtualMachine) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down

0 comments on commit 4412fb5

Please sign in to comment.