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
test: Refactor modules to use mocked commands #936
Conversation
a83b007
to
1e6eb65
Compare
Have refactored the ruby module tests to use a mocked command and no longer depend on having a particular version of Ruby installed. While I was here I also added a quick test for checking the formatting of the ruby output.
Have refactored the php module tests to use a mocked command and no longer depend on having a particular version of PHP installed.
1e6eb65
to
c318172
Compare
2f4a79d
to
efa222c
Compare
I have been looking at migrating some of the other modules (python, terraform, etc), but it looks like they depend on having some env vars set. I've done a bit off Googling and I'm not sure what the best way to handle them in the test render is, does anyone have any suggestions? |
I'm afraid it's not going to be easy. We may have create an abstraction around For example: #[test]
fn check_env_var() -> io::Result<()> {
// starting now, `getEnvVar("USER")` will return `Some("root")`
mockEnvVar("USER", "root");
let actual = render_module("username", dir.path());
} In fact, this may also be the preferable pattern for mocking command execution, as it lets us keep the expected mock context near the test code. What are your thoughts, @andytom? |
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.
Looks good to me! 👍
Just a quick comment below, and it should be ready to merge. 😄
efa222c
to
c318172
Compare
I was thinking something similar, while it made the initial implementation easy the current way of doing things does have it's limitations. In addition to keeping the tests and the mocks closer together this would allow us to set different responses for on a per test basis, this would be useful for Java and Python where some versions print the version strings on |
Description
Have refactored the ruby and php modules tests to use a mocked
command and no longer depend on having a particular version of
Ruby or PHP installed. While I was here I also added a quick test for
checking the formatting of the ruby output.
Motivation and Context
This will make testing easier and less fragile.
Types of changes
Screenshots (if appropriate):
How Has This Been Tested?
Checklist: