From 18bb4eee965d5cc3934408aab577e5e43fd5f4b9 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sun, 8 Jul 2018 21:57:56 +1000 Subject: [PATCH] moar tests --- commands_test.go | 10 ++++++++++ yq.go | 5 ++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/commands_test.go b/commands_test.go index 94e654a270c..f9b617d7ba1 100644 --- a/commands_test.go +++ b/commands_test.go @@ -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") diff --git a/yq.go b/yq.go index cb6e96efa82..b5ffcf56866 100644 --- a/yq.go +++ b/yq.go @@ -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 }