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": interfaceSlice(hwResults.PhysicalMemoryResult.Body.PullResponse.MemoryItems),
},
}, nil
}

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

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

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

return result
Comment on lines +539 to +551
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interfaceSlice is named as if it were a generic helper, but it only accepts []physical.PhysicalMemory. Consider renaming it to reflect the specific type/purpose (or making it generic if that’s the intent) to avoid confusion for future callers.

Copilot uses AI. Check for mistakes.
}

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 TestInterfaceSlice(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 := interfaceSlice(tc.input)
require.Equal(t, tc.expected, result)
Comment on lines +11 to +81
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description mentions updating/testing parseCIMResponse (and using reflection for typed slices), but this change instead introduces interfaceSlice in wsman/message.go and tests that helper. Please update the PR description (or include the missing parseCIMResponse changes/tests) so the intent and scope match what’s actually being merged.

Copilot uses AI. Check for mistakes.
})
}
}
Loading