From eedbb0a99f97f58aa8bc578d823d20b79b0382fe Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sun, 13 Sep 2020 11:26:07 +1000 Subject: [PATCH] Explode anchors now applies to map keys too --- cmd/read_test.go | 17 +++++++++++++++++ cmd/utils.go | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/cmd/read_test.go b/cmd/read_test.go index 2dd436b9..96d4121b 100644 --- a/cmd/read_test.go +++ b/cmd/read_test.go @@ -617,6 +617,23 @@ pointer: *value-pointer` test.AssertResult(t, expectedOutput, result.Output) } +func TestReadMergeAnchorsExplodeKeyCmd(t *testing.T) { + content := `name: &nameField Mike +*nameField: Great Guy` + filename := test.WriteTempYamlFile(content) + defer test.RemoveTempYamlFile(filename) + + cmd := getRootCommand() + result := test.RunCmd(cmd, fmt.Sprintf("read -X %s", filename)) + if result.Error != nil { + t.Error(result.Error) + } + expectedOutput := `name: Mike +Mike: Great Guy +` + test.AssertResult(t, expectedOutput, result.Output) +} + func TestReadMergeAnchorsExplodeSimpleArrayCmd(t *testing.T) { content := `- things` filename := test.WriteTempYamlFile(content) diff --git a/cmd/utils.go b/cmd/utils.go index cc79594d..cfc006be 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -202,6 +202,10 @@ func explodeNode(node *yaml.Node) error { if errorInContent != nil { return errorInContent } + errorInContent = explodeNode(keyNode) + if errorInContent != nil { + return errorInContent + } } else { if valueNode.Kind == yaml.SequenceNode { log.Debugf("an alias merge list!")