Explode anchors now applies to map keys too

This commit is contained in:
Mike Farah 2020-09-13 11:26:07 +10:00
parent 7dabc57b65
commit eedbb0a99f
2 changed files with 21 additions and 0 deletions

View File

@ -617,6 +617,23 @@ pointer: *value-pointer`
test.AssertResult(t, expectedOutput, result.Output) 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) { func TestReadMergeAnchorsExplodeSimpleArrayCmd(t *testing.T) {
content := `- things` content := `- things`
filename := test.WriteTempYamlFile(content) filename := test.WriteTempYamlFile(content)

View File

@ -202,6 +202,10 @@ func explodeNode(node *yaml.Node) error {
if errorInContent != nil { if errorInContent != nil {
return errorInContent return errorInContent
} }
errorInContent = explodeNode(keyNode)
if errorInContent != nil {
return errorInContent
}
} else { } else {
if valueNode.Kind == yaml.SequenceNode { if valueNode.Kind == yaml.SequenceNode {
log.Debugf("an alias merge list!") log.Debugf("an alias merge list!")