Fixed error flag

This commit is contained in:
Mike Farah 2020-06-12 12:21:46 +10:00
parent d9ae8e1e5a
commit 767709fef5
2 changed files with 25 additions and 1 deletions

View File

@ -51,7 +51,7 @@ func readProperty(cmd *cobra.Command, args []string) error {
matchingNodes, errorReadingStream := readYamlFile(args[0], path, updateAll, docIndexInt)
if exitStatus {
if exitStatus && len(matchingNodes) == 0 {
cmd.SilenceUsage = true
return errors.New("No matches found")
}

View File

@ -17,6 +17,30 @@ func TestReadCmd(t *testing.T) {
test.AssertResult(t, "2\n", result.Output)
}
func TestReadCmdWithExitStatus(t *testing.T) {
cmd := getRootCommand()
result := test.RunCmd(cmd, "read ../examples/sample.yaml b.c -e")
if result.Error != nil {
t.Error(result.Error)
}
test.AssertResult(t, "2\n", result.Output)
}
func TestReadCmdWithExitStatusNotExist(t *testing.T) {
cmd := getRootCommand()
result := test.RunCmd(cmd, "read ../examples/sample.yaml caterpillar -e")
test.AssertResult(t, "No matches found", result.Error.Error())
}
func TestReadCmdNotExist(t *testing.T) {
cmd := getRootCommand()
result := test.RunCmd(cmd, "read ../examples/sample.yaml caterpillar")
if result.Error != nil {
t.Error(result.Error)
}
test.AssertResult(t, "", result.Output)
}
func TestReadUnwrapCmd(t *testing.T) {
content := `b: 'frog' # my favourite`