From bd06a77b1f97b1d0facc0240fe693a5fe0029e79 Mon Sep 17 00:00:00 2001 From: abhay1999 Date: Sat, 28 Mar 2026 15:59:28 +0530 Subject: [PATCH] test(values): use require for fatal guards in null erasure tests Use require.True/require.NoError instead of assert.True/assert.NoError for type assertion guards before map indexing, so the test stops immediately on failure rather than panicking. Signed-off-by: Abhay Chaurasiya Signed-off-by: abhay1999 --- pkg/chart/common/util/coalesce_test.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/chart/common/util/coalesce_test.go b/pkg/chart/common/util/coalesce_test.go index 1a4acc72c..87610930f 100644 --- a/pkg/chart/common/util/coalesce_test.go +++ b/pkg/chart/common/util/coalesce_test.go @@ -25,6 +25,7 @@ import ( "text/template" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "helm.sh/helm/v4/pkg/chart/common" chart "helm.sh/helm/v4/pkg/chart/v2" @@ -737,8 +738,6 @@ func TestConcatPrefix(t *testing.T) { // even when that key has no default in the subchart's own values.yaml. // Regression test for https://github.com/helm/helm/issues/31919 func TestCoalesceValuesNullErasureInSubchart(t *testing.T) { - is := assert.New(t) - // Parent chart defines "key" for subchart in its own values.yaml. // The subchart itself does NOT define "key" in its values.yaml. subchart := &chart.Chart{ @@ -764,24 +763,22 @@ func TestCoalesceValuesNullErasureInSubchart(t *testing.T) { } v, err := CoalesceValues(parent, vals) - is.NoError(err) + require.NoError(t, err) sub, ok := v["mysubchart"].(map[string]any) - is.True(ok, "mysubchart is not a map") + require.True(t, ok, "mysubchart is not a map") // "other" should still be present (subchart default) - is.Equal("subchart_default", sub["other"]) + assert.Equal(t, "subchart_default", sub["other"]) // "key" should be removed — user explicitly set it to null to erase the parent default _, present := sub["key"] - is.False(present, "Expected mysubchart.key to be erased by user null, but it is still present") + assert.False(t, present, "Expected mysubchart.key to be erased by user null, but it is still present") } // TestCoalesceValuesNullErasurePreservesUserValues ensures that when a parent chart // defines a null for a subchart key, the user's non-nil value is still preserved. func TestCoalesceValuesNullErasurePreservesUserValues(t *testing.T) { - is := assert.New(t) - subchart := &chart.Chart{ Metadata: &chart.Metadata{Name: "mysubchart"}, Values: map[string]any{}, @@ -803,12 +800,12 @@ func TestCoalesceValuesNullErasurePreservesUserValues(t *testing.T) { } v, err := CoalesceValues(parent, vals) - is.NoError(err) + require.NoError(t, err) sub, ok := v["mysubchart"].(map[string]any) - is.True(ok, "mysubchart is not a map") + require.True(t, ok, "mysubchart is not a map") - is.Equal("user_value", sub["key"], "user value should not be overwritten by parent null default") + assert.Equal(t, "user_value", sub["key"], "user value should not be overwritten by parent null default") } // TestCoalesceValuesEmptyMapWithNils tests the full CoalesceValues scenario