Skip to content
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

Merged
merged 2 commits into from
Sep 5, 2024
Merged

Adding os/exec wrapper for testability #4314

merged 2 commits into from
Sep 5, 2024

Conversation

tshan2001
Copy link
Contributor

Summary

Adding a wrapper for os/exec so that we can add mock for the fault injection features that use linux tc

Implementation details

A new interface Cmd is added, which wraps around several features of os/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.

@tshan2001 tshan2001 requested a review from a team as a code owner August 29, 2024 00:35
Comment on lines +43 to +58
type cmdWrapper struct {
*exec.Cmd
}
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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)

xxx0624
xxx0624 previously approved these changes Sep 3, 2024
@tshan2001 tshan2001 merged commit 67ff392 into aws:dev Sep 5, 2024
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants