RFC: Make RunCommand less brittle#856
Merged
probablycorey merged 4 commits intomasterfrom May 5, 2020
Merged
Conversation
vilmibm
approved these changes
May 4, 2020
Contributor
vilmibm
left a comment
There was a problem hiding this comment.
I'm very in favor of this.
mislav
reviewed
May 5, 2020
Contributor
mislav
left a comment
There was a problem hiding this comment.
I support this improvement!
To avoid changing all current call points, you could perhaps still accept the 1st argument but ignore it. New callers might simply pass nil.
When we address #759, I suspect that the RunCommand approach will change as well. But until then this is worthwhile.
Contributor
Author
|
I went ahead and updated all the call points because it wasn't difficult and it was obviously easy to test because they are all called inside tests! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.