Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurVerrept committed Mar 14, 2024
1 parent 74fabb2 commit cf4f092
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
10 changes: 5 additions & 5 deletions internal/provider/storage_disk_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ func TestAcc_StorageDiskDataSource(t *testing.T) {
ctx, cancel = context.WithDeadline(ctx, deadline)
defer cancel()
}
name := "tf-ds-test-" + testRunID
name := "storage-disk-data-source" + testRunID

resourcesConfig := fmt.Sprintf(`
resource "cudo_storage_disk" "disk" {
resource "cudo_storage_disk" "disk_ds" {
data_center_id = "black-mesa"
id = "%s"
size_gib = 15
}`, name)

testAccStorageDiskDataSourceConfig := fmt.Sprintf(`
data "cudo_storage_disk" "test" {
data "cudo_storage_disk" "storage_disk_datasource" {
id = "%s"
}`, name)

Expand Down Expand Up @@ -62,8 +62,8 @@ data "cudo_storage_disk" "test" {
{
Config: getProviderConfig() + resourcesConfig + testAccStorageDiskDataSourceConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.cudo_storage_disk.test", "id", name),
resource.TestCheckResourceAttr("data.cudo_storage_disk.test", "size_gib", "15"),
resource.TestCheckResourceAttr("data.cudo_storage_disk.storage_disk_datasource", "id", name),
resource.TestCheckResourceAttr("data.cudo_storage_disk.storage_disk_datasource", "size_gib", "15"),
),
},
},
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/storage_disk_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAcc_StorageDiskResource(t *testing.T) {
name := "disk-resource-" + testRunID

diskConf := fmt.Sprintf(`
resource "cudo_storage_disk" "disk" {
resource "cudo_storage_disk" "storage_disk_resource" {
data_center_id = "black-mesa"
id = "%s"
size_gib = 15
Expand Down Expand Up @@ -53,9 +53,9 @@ resource "cudo_storage_disk" "disk" {
{
Config: getProviderConfig() + diskConf,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("cudo_storage_disk.disk", "data_center_id", "black-mesa"),
resource.TestCheckResourceAttr("cudo_storage_disk.disk", "size_gib", "15"),
resource.TestCheckResourceAttr("cudo_storage_disk.disk", "id", name),
resource.TestCheckResourceAttr("cudo_storage_disk.storage_disk_resource", "data_center_id", "black-mesa"),
resource.TestCheckResourceAttr("cudo_storage_disk.storage_disk_resource", "size_gib", "15"),
resource.TestCheckResourceAttr("cudo_storage_disk.storage_disk_resource", "id", name),
),
},
},
Expand Down
51 changes: 26 additions & 25 deletions internal/provider/vm_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,26 +271,27 @@ func TestAcc_VMStorageDiskResource(t *testing.T) {
ctx, cancel = context.WithDeadline(ctx, deadline)
defer cancel()
}
name := "vm-resource-" + testRunID
name := "vm-storage-disk-resource-" + testRunID
// important that the disks are in ascending order as that is how the api returns them
diskName1 := "vm-resource-disk1"
diskName2 := "vm-resource-disk2"
diskName1 := "vm-resource-disk1" + testRunID
diskName2 := "vm-resource-disk2" + testRunID

vmConfig := fmt.Sprintf(`
resource "cudo_storage_disk" "my-storage-disk" {
diskConfig := fmt.Sprintf(`
resource "cudo_storage_disk" "vm_resource_disk1" {
data_center_id = "black-mesa"
id = "%s"
size_gib = 10
}
resource "cudo_storage_disk" "my-storage-disk2" {
resource "cudo_storage_disk" "vm_resource_disk2" {
data_center_id = "black-mesa"
id = "%s"
size_gib = 20
}
}`, diskName1, diskName2)

resource "cudo_vm" "vm" {
depends_on = [cudo_storage_disk.my-storage-disk, cudo_storage_disk.my-storage-disk2]
vmConfig := fmt.Sprintf(`
resource "cudo_vm" "vm_disk_resource" {
depends_on = [cudo_storage_disk.vm_resource_disk1, cudo_storage_disk.vm_resource_disk2]
machine_type = "standard"
data_center_id = "black-mesa"
vcpus = 1
Expand All @@ -313,7 +314,7 @@ resource "cudo_vm" "vm" {
disk_id = "%s"
}
]
}`, diskName1, diskName2, name, diskName1, diskName2)
}`, name, diskName1, diskName2)

resource.ParallelTest(t, resource.TestCase{
CheckDestroy: func(state *terraform.State) error {
Expand Down Expand Up @@ -342,22 +343,22 @@ resource "cudo_vm" "vm" {
Steps: []resource.TestStep{
// Create and Read testing
{
Config: getProviderConfig() + vmConfig,
Config: getProviderConfig() + diskConfig + vmConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("cudo_vm.vm", "boot_disk.image_id", "alpine-linux-317"),
resource.TestCheckResourceAttr("cudo_vm.vm", "boot_disk.size_gib", "1"),
resource.TestCheckResourceAttr("cudo_vm.vm", "machine_type", "standard"),
resource.TestCheckResourceAttr("cudo_vm.vm", "cpu_model", "Haswell-noTSX-IBRS"),
resource.TestCheckResourceAttr("cudo_vm.vm", "data_center_id", "black-mesa"),
resource.TestCheckResourceAttr("cudo_vm.vm", "gpu_model", ""),
resource.TestCheckResourceAttr("cudo_vm.vm", "memory_gib", "2"),
resource.TestCheckResourceAttr("cudo_vm.vm", "storage_disks.0.disk_id", diskName1),
resource.TestCheckResourceAttr("cudo_vm.vm", "storage_disks.1.disk_id", diskName2),
resource.TestCheckResourceAttrSet("cudo_vm.vm", "price_hr"),
resource.TestCheckResourceAttrSet("cudo_vm.vm", "internal_ip_address"),
resource.TestCheckResourceAttr("cudo_vm.vm", "renewable_energy", "true"),
resource.TestCheckResourceAttr("cudo_vm.vm", "vcpus", "1"),
resource.TestCheckResourceAttr("cudo_vm.vm", "id", name),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "boot_disk.image_id", "alpine-linux-317"),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "boot_disk.size_gib", "1"),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "machine_type", "standard"),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "cpu_model", "Haswell-noTSX-IBRS"),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "data_center_id", "black-mesa"),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "gpu_model", ""),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "memory_gib", "2"),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "storage_disks.0.disk_id", diskName1),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "storage_disks.1.disk_id", diskName2),
resource.TestCheckResourceAttrSet("cudo_vm.vm_disk_resource", "price_hr"),
resource.TestCheckResourceAttrSet("cudo_vm.vm_disk_resource", "internal_ip_address"),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "renewable_energy", "true"),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "vcpus", "1"),
resource.TestCheckResourceAttr("cudo_vm.vm_disk_resource", "id", name),
),
},
},
Expand Down

0 comments on commit cf4f092

Please sign in to comment.