Skip to content

Commit

Permalink
F #485: fix sort on field
Browse files Browse the repository at this point in the history
Signed-off-by: Jaime <[email protected]>
  • Loading branch information
jaimecb committed Nov 15, 2024
1 parent 6d8819a commit b10a0f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions opennebula/data_opennebula_virtual_machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
42 changes: 21 additions & 21 deletions opennebula/data_opennebula_virtual_machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
),
),
},
Expand All @@ -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",
Expand Down Expand Up @@ -177,45 +177,45 @@ 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"
cpu = 0
}
`
var testAccVirtualMachinesDataSourceInvalidVCPU = `
data "opennebula_virtual_machines" "test" {
data "opennebula_virtual_machines" "test_invalid_vcpu" {
name_regex = "test.*"
sort_on = "id"
order = "ASC"
vcpu = 0
}
`
var testAccVirtualMachinesDataSourceInvalidMemory = `
data "opennebula_virtual_machines" "test" {
data "opennebula_virtual_machines" "test_invalid_memory" {
name_regex = "test.*"
sort_on = "id"
order = "ASC"
memory = 0
}
`
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.*"
}
`
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit b10a0f8

Please sign in to comment.