moar tests

This commit is contained in:
Mike Farah 2018-07-08 21:57:56 +10:00
parent 86b9fe3ef9
commit 18bb4eee96
2 changed files with 12 additions and 3 deletions

View File

@ -104,6 +104,16 @@ func TestReadCmd(t *testing.T) {
assertResult(t, "2\n", result.Output)
}
func TestReadBadDocumentIndexCmd(t *testing.T) {
cmd := getRootCommand()
result := runCmd(cmd, "read -df examples/sample.yaml b.c")
if result.Error == nil {
t.Error("Expected command to fail due to invalid path")
}
expectedOutput := `Document index f is not a integer or *: strconv.ParseInt: parsing "f": invalid syntax`
assertResult(t, expectedOutput, result.Error.Error())
}
func TestReadOrderCmd(t *testing.T) {
cmd := getRootCommand()
result := runCmd(cmd, "read examples/order.yaml")

5
yq.go
View File

@ -236,16 +236,15 @@ func readProperty(cmd *cobra.Command, args []string) error {
}
return nil
}
log.Debugf("processing %v / %v", currentIndex, docIndexInt)
log.Debugf("processing %v - requested index %v", currentIndex, docIndexInt)
if updateAll || currentIndex == docIndexInt {
log.Debugf("reading %v in %v", path, currentIndex)
log.Debugf("reading %v in index %v", path, currentIndex)
mappedDoc, errorParsing := readPath(dataBucket, path)
log.Debugf("%v", mappedDoc)
if errorParsing != nil {
return errors.Wrapf(errorParsing, "Error reading path in document index %v", currentIndex)
}
mappedDocs = append(mappedDocs, mappedDoc)
log.Debugf("%v", mappedDocs)
}
currentIndex = currentIndex + 1
}