Skip to content

Commit e78e830

Browse files
committed
fix: download_filename map parsing
1 parent 587c0cb commit e78e830

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

platform/platform.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,26 @@ func NewPlatformMap[T any](input any) *PlatformMap[T] {
239239
}
240240
}
241241
return ParselatformMap(flat)
242+
case map[any]any:
243+
// Handle YAML unmarshaling which produces map[any]any
244+
flat := make(map[string]T)
245+
for k, val := range v {
246+
if keyStr, ok := k.(string); ok {
247+
if typedVal, ok := val.(T); ok {
248+
flat[keyStr] = typedVal
249+
}
250+
}
251+
}
252+
return ParselatformMap(flat)
253+
case map[string]any:
254+
// Handle JSON unmarshaling or mixed YAML which produces map[string]interface{}
255+
flat := make(map[string]T)
256+
for k, val := range v {
257+
if typedVal, ok := val.(T); ok {
258+
flat[k] = typedVal
259+
}
260+
}
261+
return ParselatformMap(flat)
242262
case T:
243263
return ParsePlatformSingleValue(v)
244264
default:

platform/platform_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,75 @@ func TestNewPlatformMap(t *testing.T) {
295295
assert.Equal(t, "mac", *pm.MacOS)
296296
assert.Nil(t, pm.Linux)
297297
})
298+
299+
t.Run("handles map[any]any from YAML unmarshaling", func(t *testing.T) {
300+
// Simulate what YAML unmarshaling produces for nested maps
301+
input := map[any]any{
302+
"macos": "mac-value",
303+
"linux": "linux-value",
304+
"windows": "windows-value",
305+
}
306+
pm := NewPlatformMap[string](input)
307+
assert.Equal(t, "mac-value", *pm.MacOS)
308+
assert.Equal(t, "linux-value", *pm.Linux)
309+
assert.Equal(t, "windows-value", *pm.Windows)
310+
})
311+
312+
t.Run("handles map[any]any with partial platforms", func(t *testing.T) {
313+
input := map[any]any{
314+
"macos": "mac-only",
315+
}
316+
pm := NewPlatformMap[string](input)
317+
assert.Equal(t, "mac-only", *pm.MacOS)
318+
assert.Nil(t, pm.Linux)
319+
assert.Nil(t, pm.Windows)
320+
})
321+
322+
t.Run("handles map[string]any from JSON unmarshaling", func(t *testing.T) {
323+
// Simulate what JSON unmarshaling or mixed YAML produces
324+
input := map[string]any{
325+
"macos": "mac-value",
326+
"linux": "linux-value",
327+
"windows": "windows-value",
328+
}
329+
pm := NewPlatformMap[string](input)
330+
assert.Equal(t, "mac-value", *pm.MacOS)
331+
assert.Equal(t, "linux-value", *pm.Linux)
332+
assert.Equal(t, "windows-value", *pm.Windows)
333+
})
334+
335+
t.Run("handles map[string]any with partial platforms", func(t *testing.T) {
336+
input := map[string]any{
337+
"linux": "linux-only",
338+
}
339+
pm := NewPlatformMap[string](input)
340+
assert.Nil(t, pm.MacOS)
341+
assert.Equal(t, "linux-only", *pm.Linux)
342+
assert.Nil(t, pm.Windows)
343+
})
344+
345+
t.Run("handles map[any]any with non-string keys gracefully", func(t *testing.T) {
346+
// Non-string keys should be ignored
347+
input := map[any]any{
348+
"macos": "mac-value",
349+
123: "ignored",
350+
}
351+
pm := NewPlatformMap[string](input)
352+
assert.Equal(t, "mac-value", *pm.MacOS)
353+
assert.Nil(t, pm.Linux)
354+
assert.Nil(t, pm.Windows)
355+
})
356+
357+
t.Run("handles map[any]any with wrong value type gracefully", func(t *testing.T) {
358+
// Wrong value types should be ignored
359+
input := map[any]any{
360+
"macos": "mac-value",
361+
"linux": 123, // wrong type, should be ignored
362+
}
363+
pm := NewPlatformMap[string](input)
364+
assert.Equal(t, "mac-value", *pm.MacOS)
365+
assert.Nil(t, pm.Linux)
366+
})
298367
}
299368

300369
func TestSetOSAndSetArch(t *testing.T) {

0 commit comments

Comments
 (0)