Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion internal/usecase/devices/wsman/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,26 @@ func createMapInterfaceForHWInfo(hwResults HWResults) (interface{}, error) {
}, "CIM_Processor": map[string]interface{}{
"responses": []interface{}{hwResults.ProcessorResult.Body.PackageResponse},
}, "CIM_PhysicalMemory": map[string]interface{}{
"responses": hwResults.PhysicalMemoryResult.Body.PullResponse.MemoryItems,
"responses": convertPhysicalMemorySlice(hwResults.PhysicalMemoryResult.Body.PullResponse.MemoryItems),
},
}, nil
}

// convertPhysicalMemorySlice converts []physical.PhysicalMemory to []interface{} for consistent handling.
func convertPhysicalMemorySlice(items []physical.PhysicalMemory) []interface{} {
if items == nil {
return []interface{}{}
}

result := make([]interface{}, len(items))

for i := range items {
result[i] = items[i]
}

return result
}

func createMapInterfaceForDiskInfo(diskResults DiskResults) (interface{}, error) {
return map[string]interface{}{
"CIM_MediaAccessDevice": map[string]interface{}{
Expand Down
84 changes: 84 additions & 0 deletions internal/usecase/devices/wsman/message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package wsman

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/device-management-toolkit/go-wsman-messages/v2/pkg/wsman/cim/physical"
)

func TestConvertPhysicalMemorySlice(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input []physical.PhysicalMemory
expected []interface{}
}{
{
name: "empty slice",
input: []physical.PhysicalMemory{},
expected: []interface{}{},
},
{
name: "single item",
input: []physical.PhysicalMemory{
{
Capacity: 17179869184, // 16 GB
Manufacturer: "Kingston",
PartNumber: "9905700-101.A00G",
},
},
expected: []interface{}{
physical.PhysicalMemory{
Capacity: 17179869184,
Manufacturer: "Kingston",
PartNumber: "9905700-101.A00G",
},
},
},
{
name: "multiple items",
input: []physical.PhysicalMemory{
{
Capacity: 8589934592, // 8 GB
Manufacturer: "Samsung",
PartNumber: "M471A1K43CB1-CRC",
},
{
Capacity: 8589934592, // 8 GB
Manufacturer: "Samsung",
PartNumber: "M471A1K43CB1-CRC",
},
},
expected: []interface{}{
physical.PhysicalMemory{
Capacity: 8589934592,
Manufacturer: "Samsung",
PartNumber: "M471A1K43CB1-CRC",
},
physical.PhysicalMemory{
Capacity: 8589934592,
Manufacturer: "Samsung",
PartNumber: "M471A1K43CB1-CRC",
},
},
},
{
name: "nil slice",
input: nil,
expected: []interface{}{},
},
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

result := convertPhysicalMemorySlice(tc.input)
require.Equal(t, tc.expected, result)
})
}
}
Loading