fix(coalesce): suppress false warning when value is an empty map

Signed-off-by: SunilKotte <sunilkotte0909@gmail.com>
pull/32176/head
SunilKotte 4 months ago
parent 59b57c5c31
commit 91845fea2a

@ -350,9 +350,12 @@ func coalesceTablesFullKey(printf printFn, dst, src map[string]any, prefix strin
printf("warning: cannot overwrite table with non table for %s (%v)", fullkey, val) printf("warning: cannot overwrite table with non table for %s (%v)", fullkey, val)
} }
} else if istable(dv) && val != nil { } else if istable(dv) && val != nil {
// Only warn if the value is a non‑empty map, otherwise skip silently
if m, ok := val.(map[string]any); !ok || len(m) > 0 {
printf("warning: destination for %s is a table. Ignoring non-table value (%v)", fullkey, val) printf("warning: destination for %s is a table. Ignoring non-table value (%v)", fullkey, val)
} }
} }
}
return dst return dst
} }

@ -926,3 +926,34 @@ func TestCoalesceValuesSubchartNilCleanedWhenUserPartiallyOverrides(t *testing.T
_, ok = keyMapping["password"] _, ok = keyMapping["password"]
is.False(ok, "Expected keyMapping.password (nil from chart defaults) to be removed even when user partially overrides the map") is.False(ok, "Expected keyMapping.password (nil from chart defaults) to be removed even when user partially overrides the map")
} }
func TestCoalesceValuesEmptyMapNoWarning(t *testing.T) {
warnings := make([]string, 0)
printf := func(format string, v ...any) {
t.Logf(format, v...)
warnings = append(warnings, fmt.Sprintf(format, v...))
}
// Chart default has a map key "data"
c := &chart.Chart{
Metadata: &chart.Metadata{Name: "test"},
Values: map[string]any{
"data": map[string]any{
"existing": "value",
},
},
}
// User supplies an empty map for "data" – should NOT trigger a warning
vals := map[string]any{
"data": map[string]any{},
}
_, err := coalesce(printf, c, vals, "", false)
if err != nil {
t.Fatal(err)
}
if len(warnings) > 0 {
t.Errorf("expected no warnings, but got: %v", warnings)
}
}

Loading…
Cancel
Save