package infra import ( "testing" ) func TestConfigDump(t *testing.T) { t.Run("campos normales se incluyen como string", func(t *testing.T) { type Cfg struct { Host string Port int } got := ConfigDump(Cfg{Host: "localhost", Port: 8080}) if got["Host"] != "localhost" { t.Errorf("expected Host=localhost, got %q", got["Host"]) } if got["Port"] != "8080" { t.Errorf("expected Port=8080, got %q", got["Port"]) } }) t.Run("campos secret aparecen como tres asteriscos", func(t *testing.T) { type Cfg struct { APIKey string `secret:"true"` } got := ConfigDump(Cfg{APIKey: "super-secret-key"}) if got["APIKey"] != "***" { t.Errorf("expected ***, got %q", got["APIKey"]) } }) t.Run("campos no exportados no aparecen", func(t *testing.T) { type Cfg struct { Public string private string //nolint:structcheck } _ = Cfg{} // ensure it compiles got := ConfigDump(Cfg{Public: "yes"}) if _, ok := got["private"]; ok { t.Error("private field should not be in dump") } }) t.Run("puntero a struct funciona", func(t *testing.T) { type Cfg struct { Name string } got := ConfigDump(&Cfg{Name: "test"}) if got["Name"] != "test" { t.Errorf("expected Name=test, got %q", got["Name"]) } }) t.Run("struct con bool y float se formatean correctamente", func(t *testing.T) { type Cfg struct { Debug bool Timeout float64 } got := ConfigDump(Cfg{Debug: true, Timeout: 3.14}) if got["Debug"] != "true" { t.Errorf("expected Debug=true, got %q", got["Debug"]) } if got["Timeout"] != "3.14" { t.Errorf("expected Timeout=3.14, got %q", got["Timeout"]) } }) }