Files
fn_registry/functions/infra/config_merge_test.go
T
egutierrez c3b007a4e7 feat(infra): tipos ConfigError y ConfigValidation + funciones puras Go (validate, merge, dump)
- ConfigError y ConfigValidation como tipos producto con sus .md en types/infra/
- config_validate: validacion con tags required/format/min/max/oneof via reflection
- config_merge: merge no-mutante de map[string]string con precedencia de override
- config_dump: serializacion de structs a map con mascara *** para campos secret
- 17 tests unitarios, todos PASS

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 02:01:43 +02:00

54 lines
1.4 KiB
Go

package infra
import (
"testing"
)
func TestConfigMerge(t *testing.T) {
t.Run("override gana sobre base en claves comunes", func(t *testing.T) {
base := map[string]string{"host": "localhost", "port": "5432"}
over := map[string]string{"port": "9999"}
got := ConfigMerge(base, over)
if got["port"] != "9999" {
t.Errorf("expected port=9999, got %q", got["port"])
}
if got["host"] != "localhost" {
t.Errorf("expected host=localhost, got %q", got["host"])
}
})
t.Run("claves solo en base se mantienen", func(t *testing.T) {
base := map[string]string{"a": "1", "b": "2"}
over := map[string]string{}
got := ConfigMerge(base, over)
if got["a"] != "1" || got["b"] != "2" {
t.Errorf("unexpected result: %v", got)
}
})
t.Run("claves solo en override se agregan", func(t *testing.T) {
base := map[string]string{}
over := map[string]string{"x": "new"}
got := ConfigMerge(base, over)
if got["x"] != "new" {
t.Errorf("expected x=new, got %q", got["x"])
}
})
t.Run("no muta el map base", func(t *testing.T) {
base := map[string]string{"key": "original"}
over := map[string]string{"key": "changed"}
_ = ConfigMerge(base, over)
if base["key"] != "original" {
t.Errorf("base was mutated: got %q", base["key"])
}
})
t.Run("merge con maps vacios retorna mapa vacio", func(t *testing.T) {
got := ConfigMerge(map[string]string{}, map[string]string{})
if len(got) != 0 {
t.Errorf("expected empty map, got %v", got)
}
})
}