From 726c11ac2d9376e99722bd44c2cfbea5ae93eed0 Mon Sep 17 00:00:00 2001 From: Siew Kam Onn Date: Thu, 25 Sep 2025 11:23:19 +0800 Subject: [PATCH] Add test for CoalesceTables with empty destination table Signed-off-by: Siew Kam Onn --- pkg/chart/common/util/coalesce_test.go | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pkg/chart/common/util/coalesce_test.go b/pkg/chart/common/util/coalesce_test.go index 5109167cc..c1ac66922 100644 --- a/pkg/chart/common/util/coalesce_test.go +++ b/pkg/chart/common/util/coalesce_test.go @@ -436,6 +436,36 @@ func TestMergeValues(t *testing.T) { } func TestCoalesceTables(t *testing.T) { + t.Run("empty destination table overrides defaults", func(t *testing.T) { + t.Helper() + + dst := map[string]interface{}{ + "config": map[string]interface{}{}, + } + src := map[string]interface{}{ + "config": map[string]interface{}{ + "enabled": true, + "port": 8080, + }, + } + + CoalesceTables(dst, src) + + config, ok := dst["config"].(map[string]interface{}) + if !ok { + t.Fatalf("config should remain a map, got %T", dst["config"]) + } + if len(config) != 0 { + 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{}{ "name": "Ishmael", "address": map[string]interface{}{