From b10a0f8abe2d13b3024279a22401160dd4c182ad Mon Sep 17 00:00:00 2001 From: Jaime Date: Fri, 15 Nov 2024 08:26:13 +0100 Subject: [PATCH] F #485: fix sort on field Signed-off-by: Jaime --- .../data_opennebula_virtual_machines.go | 4 +- .../data_opennebula_virtual_machines_test.go | 42 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/opennebula/data_opennebula_virtual_machines.go b/opennebula/data_opennebula_virtual_machines.go index f54c55de..5918f0e2 100644 --- a/opennebula/data_opennebula_virtual_machines.go +++ b/opennebula/data_opennebula_virtual_machines.go @@ -314,7 +314,7 @@ func datasourceOpennebulaVirtualMachinesRead(ctx context.Context, d *schema.Reso ordering = d.Get("order").(string) var orderingFn func(int, int) bool switch ordering { - case "ASC": + case "DESC": switch vmsMaps[0][sortOnAttr].(type) { case int: orderingFn = func(i, j int) bool { @@ -336,7 +336,7 @@ func datasourceOpennebulaVirtualMachinesRead(ctx context.Context, d *schema.Reso }) return diags } - case "DESC": + case "ASC": switch vmsMaps[0][sortOnAttr].(type) { case int: orderingFn = func(i, j int) bool { diff --git a/opennebula/data_opennebula_virtual_machines_test.go b/opennebula/data_opennebula_virtual_machines_test.go index 4c80cdff..4969bdfd 100644 --- a/opennebula/data_opennebula_virtual_machines_test.go +++ b/opennebula/data_opennebula_virtual_machines_test.go @@ -77,8 +77,8 @@ func TestAccVirtualMachineDataSource(t *testing.T) { ), resource.TestCheckResourceAttr( "data.opennebula_virtual_machines.basic", - "virtual_machines.0.tags.%", - "1", + "virtual_machines.0.tags.SCHED_REQUIREMENTS", + "CLUSTER_ID!=\"123\"", ), ), }, @@ -88,52 +88,52 @@ func TestAccVirtualMachineDataSource(t *testing.T) { resource.TestCheckResourceAttr( "data.opennebula_virtual_machines.id_asc", "virtual_machines.0.name", - "vm-1", + "vm-0", ), resource.TestCheckResourceAttr( "data.opennebula_virtual_machines.id_asc", "virtual_machines.1.name", - "vm-0", + "vm-1", ), resource.TestCheckResourceAttr( "data.opennebula_virtual_machines.cpu_desc", "virtual_machines.0.name", - "vm-0", + "vm-1", ), resource.TestCheckResourceAttr( "data.opennebula_virtual_machines.cpu_desc", "virtual_machines.1.name", - "vm-1", + "vm-0", ), resource.TestCheckResourceAttr( "data.opennebula_virtual_machines.mem_asc", "virtual_machines.0.name", - "vm-0", + "vm-1", ), resource.TestCheckResourceAttr( "data.opennebula_virtual_machines.mem_asc", "virtual_machines.1.name", - "vm-1", + "vm-0", ), resource.TestCheckResourceAttr( - "data.opennebula_virtual_machines.vcpu_asc", + "data.opennebula_virtual_machines.vcpu_desc", "virtual_machines.0.name", - "vm-1", + "vm-0", ), resource.TestCheckResourceAttr( - "data.opennebula_virtual_machines.vcpu_asc", + "data.opennebula_virtual_machines.vcpu_desc", "virtual_machines.1.name", - "vm-0", + "vm-1", ), resource.TestCheckResourceAttr( "data.opennebula_virtual_machines.name_desc", "virtual_machines.0.name", - "vm-0", + "vm-1", ), resource.TestCheckResourceAttr( "data.opennebula_virtual_machines.name_desc", "virtual_machines.1.name", - "vm-1", + "vm-0", ), resource.TestCheckResourceAttr( "data.opennebula_virtual_machines.id_desc_cpu", @@ -177,7 +177,7 @@ func TestAccVirtualMachineDataSource(t *testing.T) { } var testAccVirtualMachinesDataSourceInvalidCPU = ` -data "opennebula_virtual_machines" "test" { +data "opennebula_virtual_machines" "test_invalid_id" { name_regex = "test.*" sort_on = "id" order = "ASC" @@ -185,7 +185,7 @@ data "opennebula_virtual_machines" "test" { } ` var testAccVirtualMachinesDataSourceInvalidVCPU = ` -data "opennebula_virtual_machines" "test" { +data "opennebula_virtual_machines" "test_invalid_vcpu" { name_regex = "test.*" sort_on = "id" order = "ASC" @@ -193,7 +193,7 @@ data "opennebula_virtual_machines" "test" { } ` var testAccVirtualMachinesDataSourceInvalidMemory = ` -data "opennebula_virtual_machines" "test" { +data "opennebula_virtual_machines" "test_invalid_memory" { name_regex = "test.*" sort_on = "id" order = "ASC" @@ -201,21 +201,21 @@ data "opennebula_virtual_machines" "test" { } ` var testAccVirtualMachinesDataSourceInvalidSort = ` -data "opennebula_virtual_machines" "test" { +data "opennebula_virtual_machines" "test_invalid_sort" { name_regex = "test.*" sort_on = "unsupported_field" order = "ASC" } ` var testAccVirtualMachinesDataSourceInvalidOrder = ` -data "opennebula_virtual_machines" "test" { +data "opennebula_virtual_machines" "test_invalid_order" { name_regex = "test.*" sort_on = "id" order = "unsupported_order" } ` var testAccVirtualMachinesDataSourceNoMatchingVMs = ` -data "opennebula_virtual_machines" "test" { +data "opennebula_virtual_machines" "test_no_matching" { name_regex = "noMatchingVM.*" } ` @@ -293,7 +293,7 @@ data "opennebula_virtual_machines" "mem_asc" { ] } -data "opennebula_virtual_machines" "vcpu_asc" { +data "opennebula_virtual_machines" "vcpu_desc" { name_regex = "vm.*" sort_on = "vcpu" order = "DESC"