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

(MODULES-10638) Ease mocking of chocolatey internals #254

Merged
merged 3 commits into from
Mar 23, 2021

Conversation

DavidS
Copy link

@DavidS DavidS commented Mar 11, 2021

By using values from facter for choco_install_path and chocolateyversion
instead of directly calling into the utility code, users of this module
who want to run unit tests on non-windows platforms can provide mocked
fact values and avoid running into issues with the utility functions trying
to read the registry.

@DavidS DavidS added the bugfix label Mar 11, 2021
@DavidS DavidS requested a review from a team as a code owner March 11, 2021 10:19
@DavidS
Copy link
Author

DavidS commented Mar 11, 2021

I'll need to test whether this works on the first run to install choco AND manage packages in the same run.

@DavidS DavidS force-pushed the MODULES-10638-allow-mocking branch from e7e0fb2 to 6619259 Compare March 13, 2021 20:57
@rnelson0
Copy link

While this isn't passing tests, I can confirm these changes DO allow compile tests of classes that include chocolatey to pass! My changes to the reproduction case:

# In the spec test, uncomment the compile test:
      it { is_expected.to compile }

# In .fixtures.yml, replace the forge module for chocolatey with:
  repositories:
    chocolatey:
      repo: "https://github.com/DavidS/puppetlabs-chocolatey"
      ref: "6619259"

# Add back some hieradata fixtures at spec/fixtures/hieradata/environment.yaml
# Software Versions
ahchocolatey::version: '0.10.15'
ahchocolatey::versionext: '2.0.2'
ahchocolatey::source: "%{lookup('artifactory_nuget_url')}"
chocolatey::choco_install_location: 'c:\local_folder'

@DavidS DavidS force-pushed the MODULES-10638-allow-mocking branch 3 times, most recently from 59ee480 to f108cc1 Compare March 19, 2021 10:50
By using values from facter for choco_install_path and chocolateyversion
instead of directly calling into the utility code, users of this module
who want to run unit tests on non-windows platforms can provide mocked
fact values and avoid running into issues with the utility functions trying
to read the registry.
By falling back to the active lookup, this even works when choco was
not installed at the start of the agent run.
@DavidS DavidS force-pushed the MODULES-10638-allow-mocking branch from f108cc1 to 1cf1481 Compare March 19, 2021 11:21
Copy link

@michaeltlombardi michaeltlombardi left a comment

Choose a reason for hiding this comment

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

Well this is a small, clever, maintainable solution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants