diff --git a/proxmox/nodes/vms/vms_types.go b/proxmox/nodes/vms/vms_types.go index cd5086cf..5dafd9ae 100644 --- a/proxmox/nodes/vms/vms_types.go +++ b/proxmox/nodes/vms/vms_types.go @@ -1606,7 +1606,7 @@ func (r *CustomPCIDevice) UnmarshalJSON(b []byte) error { for _, p := range pairs { v := strings.Split(strings.TrimSpace(p), "=") if len(v) == 1 { - r.DeviceIDs = strings.Split(v[1], ";") + r.DeviceIDs = strings.Split(v[0], ";") } else if len(v) == 2 { switch v[0] { case "host": diff --git a/proxmox/nodes/vms/vms_types_test.go b/proxmox/nodes/vms/vms_types_test.go index 72fd923c..7807d4e7 100644 --- a/proxmox/nodes/vms/vms_types_test.go +++ b/proxmox/nodes/vms/vms_types_test.go @@ -15,6 +15,8 @@ import ( ) func TestCustomStorageDevice_UnmarshalJSON(t *testing.T) { + t.Parallel() + ds8gig := types.DiskSizeFromGigabytes(8) tests := []struct { name string @@ -49,8 +51,11 @@ func TestCustomStorageDevice_UnmarshalJSON(t *testing.T) { }, }, } + for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { + t.Parallel() r := &CustomStorageDevice{} if err := r.UnmarshalJSON([]byte(tt.line)); (err != nil) != tt.wantErr { t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) @@ -59,3 +64,50 @@ func TestCustomStorageDevice_UnmarshalJSON(t *testing.T) { }) } } + +func TestCustomPCIDevice_UnmarshalJSON(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + line string + want *CustomPCIDevice + wantErr bool + }{ + { + name: "id only pci device", + line: `"0000:81:00.2"`, + want: &CustomPCIDevice{ + DeviceIDs: []string{"0000:81:00.2"}, + MDev: nil, + PCIExpress: types.BoolPtr(false), + ROMBAR: types.BoolPtr(true), + ROMFile: nil, + XVGA: types.BoolPtr(false), + }, + }, + { + name: "pci device with more details", + line: `"host=81:00.4,pcie=0,rombar=1,x-vga=0"`, + want: &CustomPCIDevice{ + DeviceIDs: []string{"81:00.4"}, + MDev: nil, + PCIExpress: types.BoolPtr(false), + ROMBAR: types.BoolPtr(true), + ROMFile: nil, + XVGA: types.BoolPtr(false), + }, + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + r := &CustomPCIDevice{} + if err := r.UnmarshalJSON([]byte(tt.line)); (err != nil) != tt.wantErr { + t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +}