Merge pull request #42 from mikefarah/bugfix/append-empty-array

Bugfix: Append when array empty results in null value
This commit is contained in:
Kenny Jones 2017-09-25 09:34:00 -04:00 committed by GitHub
commit 9dd4503b23
2 changed files with 19 additions and 1 deletions

View File

@ -454,6 +454,24 @@ func TestWriteCmd_Append(t *testing.T) {
assertResult(t, expectedOutput, result.Output) assertResult(t, expectedOutput, result.Output)
} }
func TestWriteCmd_AppendEmptyArray(t *testing.T) {
content := `a: 2
`
filename := writeTempYamlFile(content)
defer removeTempYamlFile(filename)
cmd := getRootCommand()
result := runCmd(cmd, fmt.Sprintf("write %s b[+] v", filename))
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `a: 2
b:
- v
`
assertResult(t, expectedOutput, result.Output)
}
func TestMergeCmd(t *testing.T) { func TestMergeCmd(t *testing.T) {
cmd := getRootCommand() cmd := getRootCommand()
result := runCmd(cmd, "merge examples/data1.yaml examples/data2.yaml") result := runCmd(cmd, "merge examples/data1.yaml examples/data2.yaml")

View File

@ -71,7 +71,7 @@ func writeArray(context interface{}, paths []string, value interface{}) []interf
case []interface{}: case []interface{}:
array = context.([]interface{}) array = context.([]interface{})
default: default:
array = make([]interface{}, 1) array = make([]interface{}, 0)
} }
if len(paths) == 0 { if len(paths) == 0 {