From c4710c87a5a5269a64dcbb884889f382062749ca Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Thu, 10 Apr 2025 10:01:40 +0000 Subject: [PATCH] Acceptance test setup --- .../hypercore_disk_resource_acc_test.go | 45 +++++++++++++++++++ .../hypercore_iso_resource_acc_test.go | 35 +++++++++++++++ .../hypercore_nic_resource_acc_test.go | 45 +++++++++++++++++++ ...ypercore_virtual_disk_resource_acc_test.go | 43 ++++++++++++++++++ ...percore_vm_boot_order_resource_acc_test.go | 44 ++++++++++++++++++ ...ercore_vm_power_state_resource_acc_test.go | 39 ++++++++++++++++ .../tests/acceptance/provider_acc_test.go | 3 +- 7 files changed, 252 insertions(+), 2 deletions(-) create mode 100644 internal/provider/tests/acceptance/hypercore_disk_resource_acc_test.go create mode 100644 internal/provider/tests/acceptance/hypercore_iso_resource_acc_test.go create mode 100644 internal/provider/tests/acceptance/hypercore_nic_resource_acc_test.go create mode 100644 internal/provider/tests/acceptance/hypercore_virtual_disk_resource_acc_test.go create mode 100644 internal/provider/tests/acceptance/hypercore_vm_boot_order_resource_acc_test.go create mode 100644 internal/provider/tests/acceptance/hypercore_vm_power_state_resource_acc_test.go diff --git a/internal/provider/tests/acceptance/hypercore_disk_resource_acc_test.go b/internal/provider/tests/acceptance/hypercore_disk_resource_acc_test.go new file mode 100644 index 0000000..f6aada5 --- /dev/null +++ b/internal/provider/tests/acceptance/hypercore_disk_resource_acc_test.go @@ -0,0 +1,45 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccHypercoreDiskResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccHypercoreDiskResourceConfig(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("hypercore_disk.test", "size", "3"), + resource.TestCheckResourceAttr("hypercore_disk.test", "type", "IDE_DISK"), + ), + }, + }, + }) +} + +func testAccHypercoreDiskResourceConfig() string { + return fmt.Sprintf(` +data "hypercore_vm" "diskvm" { + name = %[1]q +} + +resource "hypercore_disk" "test" { + vm_uuid = data.hypercore_vm.diskvm.vms.0.uuid + type = "IDE_DISK" + size = 3 +} + +output "vm_id" { + value = data.hypercore_vm.diskvm.vms.0.uuid +} +`, source_vm_name) +} diff --git a/internal/provider/tests/acceptance/hypercore_iso_resource_acc_test.go b/internal/provider/tests/acceptance/hypercore_iso_resource_acc_test.go new file mode 100644 index 0000000..004f7a1 --- /dev/null +++ b/internal/provider/tests/acceptance/hypercore_iso_resource_acc_test.go @@ -0,0 +1,35 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccHypercoreISOResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccHypercoreISOResourceConfig("testtf-iso.iso"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("hypercore_iso.test", "name", "testtf-iso.iso"), + ), + }, + }, + }) +} + +func testAccHypercoreISOResourceConfig(iso_name string) string { + return fmt.Sprintf(` +resource "hypercore_iso" "test" { + name = "%s" + source_url = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-virt-3.21.3-aarch64.iso" +} +`, iso_name) +} diff --git a/internal/provider/tests/acceptance/hypercore_nic_resource_acc_test.go b/internal/provider/tests/acceptance/hypercore_nic_resource_acc_test.go new file mode 100644 index 0000000..2e848bc --- /dev/null +++ b/internal/provider/tests/acceptance/hypercore_nic_resource_acc_test.go @@ -0,0 +1,45 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccHypercoreNicResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccHypercoreSourceVMRConfig(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("hypercore_nic.test", "vlan", "11"), + resource.TestCheckResourceAttr("hypercore_nic.test", "type", "VIRTIO"), + ), + }, + }, + }) +} + +func testAccHypercoreSourceVMRConfig() string { + return fmt.Sprintf(` +data "hypercore_vm" "nicvm" { + name = %[1]q +} + +resource "hypercore_nic" "test" { + vm_uuid = data.hypercore_vm.nicvm.vms.0.uuid + vlan = 11 + type = "VIRTIO" +} + +output "vm_id" { + value = data.hypercore_vm.nicvm.vms.0.uuid +} +`, source_vm_name) +} diff --git a/internal/provider/tests/acceptance/hypercore_virtual_disk_resource_acc_test.go b/internal/provider/tests/acceptance/hypercore_virtual_disk_resource_acc_test.go new file mode 100644 index 0000000..3cb90c5 --- /dev/null +++ b/internal/provider/tests/acceptance/hypercore_virtual_disk_resource_acc_test.go @@ -0,0 +1,43 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccHypercoreVirtualDiskResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccHypercoreVirtualDiskResourceConfig(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("hypercore_disk.attach_vd_test", "size", "3.4"), + resource.TestCheckResourceAttr("hypercore_disk.attach_vd_test", "type", "VIRTIO_DISK"), + ), + }, + }, + }) +} + +func testAccHypercoreVirtualDiskResourceConfig() string { + return fmt.Sprintf(` +data "hypercore_vm" "integrationvm" { + name = %[1]q +} + +resource "hypercore_disk" "attach_vd_test" { + vm_uuid = data.hypercore_vm.integrationvm.vms.0.uuid + type = "VIRTIO_DISK" + size = 3.4 + source_virtual_disk_id = %[2]q +} + +`, source_vm_name, existing_vdisk_uuid) +} diff --git a/internal/provider/tests/acceptance/hypercore_vm_boot_order_resource_acc_test.go b/internal/provider/tests/acceptance/hypercore_vm_boot_order_resource_acc_test.go new file mode 100644 index 0000000..f0efce7 --- /dev/null +++ b/internal/provider/tests/acceptance/hypercore_vm_boot_order_resource_acc_test.go @@ -0,0 +1,44 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccHypercoreBootOrderResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccHypercoreBootOrderResourceConfig(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("hypercore_vm_boot_order.test", "boot_devices.#", "2"), + resource.TestCheckResourceAttr("hypercore_vm_boot_order.test", "boot_devices.0", source_nic_uuid), + resource.TestCheckResourceAttr("hypercore_vm_boot_order.test", "boot_devices.1", source_disk_uuid), + ), + }, + }, + }) +} + +func testAccHypercoreBootOrderResourceConfig() string { + return fmt.Sprintf(` +data "hypercore_vm" "bootvm" { + name = %[1]q +} + +resource "hypercore_vm_boot_order" "test" { + vm_uuid = data.hypercore_vm.bootvm.vms.0.uuid + boot_devices = [ + %[2]q, + %[3]q, + ] +} +`, source_vm_name, source_nic_uuid, source_disk_uuid) +} diff --git a/internal/provider/tests/acceptance/hypercore_vm_power_state_resource_acc_test.go b/internal/provider/tests/acceptance/hypercore_vm_power_state_resource_acc_test.go new file mode 100644 index 0000000..ea6f63b --- /dev/null +++ b/internal/provider/tests/acceptance/hypercore_vm_power_state_resource_acc_test.go @@ -0,0 +1,39 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccHypercorePowerStateResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccHypercorePowerStateResourceConfig(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("hypercore_vm_power_state.power_state_test", "state", "RUNNING"), + ), + }, + }, + }) +} + +func testAccHypercorePowerStateResourceConfig() string { + return fmt.Sprintf(` +data "hypercore_vm" "integrationvm" { + name = %[1]q +} + +resource "hypercore_vm_power_state" "power_state_test" { + vm_uuid = data.hypercore_vm.integrationvm.vms.0.uuid + state = "RUNNING" +} +`, source_vm_name) +} diff --git a/internal/provider/tests/acceptance/provider_acc_test.go b/internal/provider/tests/acceptance/provider_acc_test.go index 71d2b36..00f4887 100644 --- a/internal/provider/tests/acceptance/provider_acc_test.go +++ b/internal/provider/tests/acceptance/provider_acc_test.go @@ -4,6 +4,7 @@ package acceptance import ( + "os" "testing" "github.com/hashicorp/terraform-plugin-framework/providerserver" @@ -11,12 +12,10 @@ import ( "github.com/hashicorp/terraform-provider-hypercore/internal/provider" ) -/* var source_vm_name = os.Getenv("SOURCE_VM_NAME") var existing_vdisk_uuid = os.Getenv("EXISTING_VDISK_UUID") var source_nic_uuid = os.Getenv("SOURCE_NIC_UUID") var source_disk_uuid = os.Getenv("SOURCE_DISK_UUID") -*/ // testAccProtoV6ProviderFactories are used to instantiate a provider during // acceptance testing. The factory function will be invoked for every Terraform