Add test for CoalesceTables with empty destination table

Signed-off-by: Siew Kam Onn <kosiew@gmail.com>
Siew Kam Onn 19 hours ago
parent fa7cabb3eb
commit 22f8be360f

@ -436,6 +436,36 @@ func TestMergeValues(t *testing.T) {
} }
func TestCoalesceTables(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{}{ dst := map[string]interface{}{
"name": "Ishmael", "name": "Ishmael",
"address": map[string]interface{}{ "address": map[string]interface{}{

Loading…
Cancel
Save