mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-08-22 19:38:35 +00:00
fix(vm): panic if numa
block is empty (#1196)
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
c772fb3cf6
commit
c27311183a
@ -15,12 +15,7 @@ func OrderedListFromMap(inputMap map[string]interface{}) []interface{} {
|
|||||||
|
|
||||||
sort.Strings(keyList)
|
sort.Strings(keyList)
|
||||||
|
|
||||||
orderedList := make([]interface{}, itemCount)
|
return OrderedListFromMapByKeyValues(inputMap, keyList)
|
||||||
for i, k := range keyList {
|
|
||||||
orderedList[i] = inputMap[k]
|
|
||||||
}
|
|
||||||
|
|
||||||
return orderedList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MapResourceList generates a list of strings from a Terraform resource list (list of maps).
|
// MapResourceList generates a list of strings from a Terraform resource list (list of maps).
|
||||||
@ -32,6 +27,10 @@ func MapResourceList(resourceList []interface{}, attrName string) map[string]int
|
|||||||
m := make(map[string]interface{}, len(resourceList))
|
m := make(map[string]interface{}, len(resourceList))
|
||||||
|
|
||||||
for _, resource := range resourceList {
|
for _, resource := range resourceList {
|
||||||
|
if resource == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
r := resource.(map[string]interface{})
|
r := resource.(map[string]interface{})
|
||||||
key := r[attrName].(string)
|
key := r[attrName].(string)
|
||||||
m[key] = r
|
m[key] = r
|
||||||
|
@ -5,12 +5,35 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestOrderedListFromMap(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
inputMap := map[string]interface{}{
|
||||||
|
"value1": map[string]interface{}{"name": "resource1", "attr": "value1"},
|
||||||
|
"value3": map[string]interface{}{"name": "resource3", "attr": "value3"},
|
||||||
|
"value2": map[string]interface{}{"name": "resource2", "attr": "value2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := []interface{}{
|
||||||
|
map[string]interface{}{"name": "resource1", "attr": "value1"},
|
||||||
|
map[string]interface{}{"name": "resource2", "attr": "value2"},
|
||||||
|
map[string]interface{}{"name": "resource3", "attr": "value3"},
|
||||||
|
}
|
||||||
|
|
||||||
|
result := OrderedListFromMap(inputMap)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(result, expected) {
|
||||||
|
t.Errorf("MapResourceList() = %v, want %v", result, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMapResourceList(t *testing.T) {
|
func TestMapResourceList(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
resourceList := []interface{}{
|
resourceList := []interface{}{
|
||||||
map[string]interface{}{"name": "resource1", "attr": "value1"},
|
map[string]interface{}{"name": "resource1", "attr": "value1"},
|
||||||
map[string]interface{}{"name": "resource2", "attr": "value2"},
|
map[string]interface{}{"name": "resource2", "attr": "value2"},
|
||||||
|
nil,
|
||||||
map[string]interface{}{"name": "resource3", "attr": "value3"},
|
map[string]interface{}{"name": "resource3", "attr": "value3"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user