RFC: Make RunCommand less brittle
#856
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In our tests we call RunCommand like this
output, err := RunCommand(issueListCmd, "issue list"). I was running into a problem where I would call RunCommand with the wrong command! For example, instead ofRunCommand(issueListCmd, "issue list")I would callRunCommand(OMGWrongCmd, "issue list"). This caused lots of problems because stderr and stdout weren't being captured in a way I could see. I was very confused.Could I have avoided this problem I was more thorough? Yes, but as we all know humans make errors especially if their name is @probablycorey. So I propose we protect our future selves by changing the arguments to
RunCommandtofunc RunCommand(args string) (*cmdOut, error). We can use cobra's ability to parse raw strings to figure out which command should be run.@mislav @vilmibm what do you think?
P.S. Moving
RunCommandto testing.go seems to make sense too.