0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-30 02:31:10 +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:
Pavel Boldyrev 2024-04-08 22:35:25 -04:00 committed by GitHub
parent c772fb3cf6
commit c27311183a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 6 deletions

View File

@ -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

View File

@ -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"},
}