diff --git a/internal/chart/v3/util/dependencies.go b/internal/chart/v3/util/dependencies.go index 8b84ef428..49486826b 100644 --- a/internal/chart/v3/util/dependencies.go +++ b/internal/chart/v3/util/dependencies.go @@ -53,10 +53,10 @@ func processDependencyConditions(reqs []*chart.Dependency, cvals common.Values, break } slog.Warn("returned non-bool value", "path", c, "chart", r.Name) - } else if _, ok := errors.AsType[common.ErrNoValue](err); ok { - // this is a real error - slog.Warn("the method PathValue returned error", slog.Any("error", err)) - } + } else if _, ok := errors.AsType[common.ErrNoValue](err); !ok { + // this is a real error + slog.Warn("the method PathValue returned error", slog.Any("error", err)) + } } } } diff --git a/internal/chart/v3/util/dependencies_test.go b/internal/chart/v3/util/dependencies_test.go index 45693ef46..4f62898b5 100644 --- a/internal/chart/v3/util/dependencies_test.go +++ b/internal/chart/v3/util/dependencies_test.go @@ -15,6 +15,8 @@ limitations under the License. package util import ( + "bytes" + "log/slog" "os" "path/filepath" "sort" @@ -55,6 +57,29 @@ func TestLoadDependency(t *testing.T) { check(c.Lock.Dependencies) } +// An absent condition path is the normal case for every unset condition and +// must not be reported as a PathValue error, matching the v2 implementation. +func TestProcessDependencyConditionsAbsentPathNoWarning(t *testing.T) { + prev := slog.Default() + t.Cleanup(func() { slog.SetDefault(prev) }) + + var logBuf bytes.Buffer + slog.SetDefault(slog.New(slog.NewJSONHandler(&logBuf, nil))) + + reqs := []*chart.Dependency{ + {Name: "subchart1", Condition: "subchart1.enabled"}, + {Name: "subchart2", Condition: "not.in.values"}, + } + v := common.Values{"subchart1": map[string]any{"enabled": true}} + + processDependencyConditions(reqs, v, "") + + assert.True(t, reqs[0].Enabled, "expected the present condition to be applied") + assert.False(t, reqs[1].Enabled, "expected the absent condition to leave the dependency disabled") + assert.NotContains(t, logBuf.String(), "PathValue returned error", + "an absent condition path is not a PathValue error and must not be warned about") +} + func TestDependencyEnabled(t *testing.T) { type M = map[string]any tests := []struct {