Skip to content

Commit

Permalink
moar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Farah committed Jul 8, 2018
1 parent 86b9fe3 commit 18bb4ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 10 additions & 0 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions yq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 18bb4ee

Please sign in to comment.