fix(v3): restore the error check inverted in processDependencyConditions

When converting the type assertion to errors.AsType in 025418291, the
negation was dropped, so the "real error" warning fired for the normal
missing-condition case (ErrNoValue) and genuine PathValue errors were
silenced instead. This diverges from the v2 implementation the code was
based on. Restore the negation and add a regression test.

Signed-off-by: zjncs <18910855655@163.com>
pull/32622/head
zjncs 4 weeks ago
parent fa11636b01
commit 3d794a5db4

@ -53,7 +53,7 @@ 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 {
} 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))
}

@ -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 {

Loading…
Cancel
Save