-
Notifications
You must be signed in to change notification settings - Fork 617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding os/exec wrapper for testability #4314
Conversation
type cmdWrapper struct { | ||
*exec.Cmd | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to create this new struct
? Shouldn't exec.Cmd
already implement Cmd
interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cmdWrapper
interface is not exactly the same, we also added a couple helper functions to help with common used functionalities such as SetIOStreams()
. Without having this extra struct, we won't be able to make the helper functions non-static (we would get error cannot define new methods on non-local type exec.Cmd
)
@@ -0,0 +1,91 @@ | |||
package execwrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, ditto in the mocks as well (ref)
Summary
Adding a wrapper for
os/exec
so that we can add mock for the fault injection features that use linuxtc
Implementation details
A new interface
Cmd
is added, which wraps around several features ofos/exec
Testing
go generate
was ran to create the mock file and passed.Description for the changelog
Adding wrapper and mock for
os/exec
Additional Information
Does this PR include breaking model changes? If so, Have you added transformation functions?
Does this PR include the addition of new environment variables in the README?
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.