Refactor tests in coalesce_test.go to use require and assert for better error handling and readability

Signed-off-by: Siew Kam Onn <kosiew@gmail.com>
pull/31331/head
Siew Kam Onn 1 day ago
parent 55606f057d
commit 3468a10cbf

@ -25,6 +25,7 @@ import (
"text/template" "text/template"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"helm.sh/helm/v4/pkg/chart/common" "helm.sh/helm/v4/pkg/chart/common"
chart "helm.sh/helm/v4/pkg/chart/v2" chart "helm.sh/helm/v4/pkg/chart/v2"
@ -256,24 +257,14 @@ func TestCoalesceValuesEmptyMapOverride(t *testing.T) {
} }
result, err := CoalesceValues(c, overrides) result, err := CoalesceValues(c, overrides)
if err != nil { require.NoError(t, err)
t.Fatal(err)
}
config, ok := result["config"].(map[string]interface{}) config, ok := result["config"].(map[string]interface{})
if !ok { require.Truef(t, ok, "expected config to remain a map, got %T", result["config"])
t.Fatalf("expected config to remain a map, got %T", result["config"]) assert.Empty(t, config, "expected config map to be empty")
} assert.NotContains(t, config, "foo", "expected config override to drop default key")
if len(config) != 0 {
t.Fatalf("expected config map to be empty, got %v", config)
}
if _, exists := config["foo"]; exists {
t.Fatalf("expected config override to drop default key, still found foo in %v", config)
}
if _, exists := result["toDelete"]; exists { assert.NotContains(t, result, "toDelete", "expected toDelete key to be removed when set to nil override")
t.Fatalf("expected toDelete key to be removed when set to nil override")
}
} }
func ttpl(tpl string, v map[string]interface{}) (string, error) { func ttpl(tpl string, v map[string]interface{}) (string, error) {
@ -452,18 +443,10 @@ func TestCoalesceTables(t *testing.T) {
CoalesceTables(dst, src) CoalesceTables(dst, src)
config, ok := dst["config"].(map[string]interface{}) config, ok := dst["config"].(map[string]interface{})
if !ok { require.Truef(t, ok, "config should remain a map, got %T", dst["config"])
t.Fatalf("config should remain a map, got %T", dst["config"]) assert.Empty(t, config, "expected empty config map")
} assert.NotContains(t, config, "enabled", "expected default \"enabled\" key to be absent")
if len(config) != 0 { assert.NotContains(t, config, "port", "expected default \"port\" key to be absent")
t.Fatalf("expected empty config map, got %v", config)
}
if _, exists := config["enabled"]; exists {
t.Fatal("expected default \"enabled\" key to be absent")
}
if _, exists := config["port"]; exists {
t.Fatal("expected default \"port\" key to be absent")
}
}) })
dst := map[string]interface{}{ dst := map[string]interface{}{

Loading…
Cancel
Save