Skip to content

Acceptance tests #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 1 addition & 2 deletions internal/provider/tests/acceptance/provider_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
package acceptance

import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"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
Expand Down
Loading