mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 18:42:58 +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)
|
||||
|
||||
orderedList := make([]interface{}, itemCount)
|
||||
for i, k := range keyList {
|
||||
orderedList[i] = inputMap[k]
|
||||
}
|
||||
|
||||
return orderedList
|
||||
return OrderedListFromMapByKeyValues(inputMap, keyList)
|
||||
}
|
||||
|
||||
// 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))
|
||||
|
||||
for _, resource := range resourceList {
|
||||
if resource == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
r := resource.(map[string]interface{})
|
||||
key := r[attrName].(string)
|
||||
m[key] = r
|
||||
|
@ -5,12 +5,35 @@ import (
|
||||
"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) {
|
||||
t.Parallel()
|
||||
|
||||
resourceList := []interface{}{
|
||||
map[string]interface{}{"name": "resource1", "attr": "value1"},
|
||||
map[string]interface{}{"name": "resource2", "attr": "value2"},
|
||||
nil,
|
||||
map[string]interface{}{"name": "resource3", "attr": "value3"},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user