Skip to content

Commit 9180202

Browse files
committed
Acceptance test setup
1 parent f086cba commit 9180202

7 files changed

+252
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package acceptance
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
)
12+
13+
func TestAccHypercoreDiskResource(t *testing.T) {
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccHypercoreDiskResourceConfig(),
20+
Check: resource.ComposeAggregateTestCheckFunc(
21+
resource.TestCheckResourceAttr("hypercore_disk.test", "size", "3"),
22+
resource.TestCheckResourceAttr("hypercore_disk.test", "type", "IDE_DISK"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
func testAccHypercoreDiskResourceConfig() string {
30+
return fmt.Sprintf(`
31+
data "hypercore_vm" "diskvm" {
32+
name = %[1]q
33+
}
34+
35+
resource "hypercore_disk" "test" {
36+
vm_uuid = data.hypercore_vm.diskvm.vms.0.uuid
37+
type = "IDE_DISK"
38+
size = 3
39+
}
40+
41+
output "vm_id" {
42+
value = data.hypercore_vm.diskvm.vms.0.uuid
43+
}
44+
`, source_vm_name)
45+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package acceptance
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
)
12+
13+
func TestAccHypercoreISOResource(t *testing.T) {
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccHypercoreISOResourceConfig("testtf-iso.iso"),
20+
Check: resource.ComposeAggregateTestCheckFunc(
21+
resource.TestCheckResourceAttr("hypercore_iso.test", "name", "testtf-iso.iso"),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
func testAccHypercoreISOResourceConfig(iso_name string) string {
29+
return fmt.Sprintf(`
30+
resource "hypercore_iso" "test" {
31+
name = "%s"
32+
source_url = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-virt-3.21.3-aarch64.iso"
33+
}
34+
`, iso_name)
35+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package acceptance
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
)
12+
13+
func TestAccHypercoreNicResource(t *testing.T) {
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccHypercoreSourceVMRConfig(),
20+
Check: resource.ComposeAggregateTestCheckFunc(
21+
resource.TestCheckResourceAttr("hypercore_nic.test", "vlan", "11"),
22+
resource.TestCheckResourceAttr("hypercore_nic.test", "type", "VIRTIO"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
func testAccHypercoreSourceVMRConfig() string {
30+
return fmt.Sprintf(`
31+
data "hypercore_vm" "nicvm" {
32+
name = %[1]q
33+
}
34+
35+
resource "hypercore_nic" "test" {
36+
vm_uuid = data.hypercore_vm.nicvm.vms.0.uuid
37+
vlan = 11
38+
type = "VIRTIO"
39+
}
40+
41+
output "vm_id" {
42+
value = data.hypercore_vm.nicvm.vms.0.uuid
43+
}
44+
`, source_vm_name)
45+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package acceptance
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
)
12+
13+
func TestAccHypercoreVirtualDiskResource(t *testing.T) {
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccHypercoreVirtualDiskResourceConfig(),
20+
Check: resource.ComposeAggregateTestCheckFunc(
21+
resource.TestCheckResourceAttr("hypercore_disk.attach_vd_test", "size", "3.4"),
22+
resource.TestCheckResourceAttr("hypercore_disk.attach_vd_test", "type", "VIRTIO_DISK"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
func testAccHypercoreVirtualDiskResourceConfig() string {
30+
return fmt.Sprintf(`
31+
data "hypercore_vm" "integrationvm" {
32+
name = %[1]q
33+
}
34+
35+
resource "hypercore_disk" "attach_vd_test" {
36+
vm_uuid = data.hypercore_vm.integrationvm.vms.0.uuid
37+
type = "VIRTIO_DISK"
38+
size = 3.4
39+
source_virtual_disk_id = %[2]q
40+
}
41+
42+
`, source_vm_name, existing_vdisk_uuid)
43+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package acceptance
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
)
12+
13+
func TestAccHypercoreBootOrderResource(t *testing.T) {
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccHypercoreBootOrderResourceConfig(),
20+
Check: resource.ComposeAggregateTestCheckFunc(
21+
resource.TestCheckResourceAttr("hypercore_vm_boot_order.test", "boot_devices.#", "2"),
22+
resource.TestCheckResourceAttr("hypercore_vm_boot_order.test", "boot_devices.0", source_nic_uuid),
23+
resource.TestCheckResourceAttr("hypercore_vm_boot_order.test", "boot_devices.1", source_disk_uuid),
24+
),
25+
},
26+
},
27+
})
28+
}
29+
30+
func testAccHypercoreBootOrderResourceConfig() string {
31+
return fmt.Sprintf(`
32+
data "hypercore_vm" "bootvm" {
33+
name = %[1]q
34+
}
35+
36+
resource "hypercore_vm_boot_order" "test" {
37+
vm_uuid = data.hypercore_vm.bootvm.vms.0.uuid
38+
boot_devices = [
39+
%[2]q,
40+
%[3]q,
41+
]
42+
}
43+
`, source_vm_name, source_nic_uuid, source_disk_uuid)
44+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package acceptance
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
)
12+
13+
func TestAccHypercorePowerStateResource(t *testing.T) {
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccHypercorePowerStateResourceConfig(),
20+
Check: resource.ComposeAggregateTestCheckFunc(
21+
resource.TestCheckResourceAttr("hypercore_vm_power_state.power_state_test", "state", "RUNNING"),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
func testAccHypercorePowerStateResourceConfig() string {
29+
return fmt.Sprintf(`
30+
data "hypercore_vm" "integrationvm" {
31+
name = %[1]q
32+
}
33+
34+
resource "hypercore_vm_power_state" "power_state_test" {
35+
vm_uuid = data.hypercore_vm.integrationvm.vms.0.uuid
36+
state = "RUNNING"
37+
}
38+
`, source_vm_name)
39+
}

internal/provider/tests/acceptance/provider_acc_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@
44
package acceptance
55

66
import (
7+
"os"
78
"testing"
89

910
"github.com/hashicorp/terraform-plugin-framework/providerserver"
1011
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
1112
"github.com/hashicorp/terraform-provider-hypercore/internal/provider"
1213
)
1314

14-
/*
1515
var source_vm_name = os.Getenv("SOURCE_VM_NAME")
1616
var existing_vdisk_uuid = os.Getenv("EXISTING_VDISK_UUID")
1717
var source_nic_uuid = os.Getenv("SOURCE_NIC_UUID")
1818
var source_disk_uuid = os.Getenv("SOURCE_DISK_UUID")
19-
*/
2019

2120
// testAccProtoV6ProviderFactories are used to instantiate a provider during
2221
// acceptance testing. The factory function will be invoked for every Terraform

0 commit comments

Comments
 (0)