mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-14 04:25:36 +00:00
Don't fail when reading an empty file
This commit is contained in:
parent
b7554e6e76
commit
f52de57652
@ -342,6 +342,20 @@ func TestReadCmd_ArrayYaml(t *testing.T) {
|
|||||||
test.AssertResult(t, "false", result.Output)
|
test.AssertResult(t, "false", result.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadEmptyContentCmd(t *testing.T) {
|
||||||
|
content := ``
|
||||||
|
filename := test.WriteTempYamlFile(content)
|
||||||
|
defer test.RemoveTempYamlFile(filename)
|
||||||
|
|
||||||
|
cmd := getRootCommand()
|
||||||
|
result := test.RunCmd(cmd, fmt.Sprintf("read %s", filename))
|
||||||
|
if result.Error != nil {
|
||||||
|
t.Error(result.Error)
|
||||||
|
}
|
||||||
|
expectedOutput := ``
|
||||||
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadPrettyPrintCmd(t *testing.T) {
|
func TestReadPrettyPrintCmd(t *testing.T) {
|
||||||
cmd := getRootCommand()
|
cmd := getRootCommand()
|
||||||
result := test.RunCmd(cmd, "read -P ../examples/sample.json")
|
result := test.RunCmd(cmd, "read -P ../examples/sample.json")
|
||||||
@ -1636,9 +1650,13 @@ c:
|
|||||||
test.AssertResult(t, expectedOutput, result.Output)
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeDontAllowEmptyCmd(t *testing.T) {
|
func TestMergeAllowEmptyMergeCmd(t *testing.T) {
|
||||||
cmd := getRootCommand()
|
cmd := getRootCommand()
|
||||||
result := test.RunCmd(cmd, "merge ../examples/data1.yaml ../examples/empty.yaml")
|
result := test.RunCmd(cmd, "merge ../examples/data1.yaml ../examples/empty.yaml")
|
||||||
expectedOutput := `Could not process document index 0 as there are only 0 document(s)`
|
expectedOutput := `a: simple # just the best
|
||||||
test.AssertResult(t, expectedOutput, result.Error.Error())
|
b: [1, 2]
|
||||||
|
c:
|
||||||
|
test: 1
|
||||||
|
`
|
||||||
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func readYamlFile(filename string, path string, updateAll bool, docIndexInt int)
|
|||||||
|
|
||||||
func handleEOF(updateAll bool, docIndexInt int, currentIndex int) error {
|
func handleEOF(updateAll bool, docIndexInt int, currentIndex int) error {
|
||||||
log.Debugf("done %v / %v", currentIndex, docIndexInt)
|
log.Debugf("done %v / %v", currentIndex, docIndexInt)
|
||||||
if !updateAll && currentIndex <= docIndexInt {
|
if !updateAll && currentIndex <= docIndexInt && docIndexInt != 0 {
|
||||||
return fmt.Errorf("Could not process document index %v as there are only %v document(s)", docIndex, currentIndex)
|
return fmt.Errorf("Could not process document index %v as there are only %v document(s)", docIndex, currentIndex)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user