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

(RK-393) Don't modify base module overrides #1267

Merged
merged 1 commit into from
Feb 3, 2022

Conversation

tvpartytonight
Copy link
Contributor

The base module class would modify the overrides supplied from
the puppetfile module loader; this ends up corrupting every
subsequent #add_module call. This change only reads that value
into the exclude_spec instance var for the module base class.

Please add all notable changes to the "Unreleased" section of the CHANGELOG in the format:

- (JIRA ticket) Summary of changes. [Issue or PR #](link to issue or PR)

@tvpartytonight tvpartytonight requested a review from a team February 3, 2022 00:39
The base module class would modify the overrides supplied from
the puppetfile module loader; this ends up corrupting every
subsequent #add_module call. This change only reads that value
into the `exclude_spec` instance var for the module base class.
it 'should not modify the overrides when adding modules' do
module_opts = { git: 'git@example.com:puppet/test_module.git' }
subject.add_module('puppet/test_module', module_opts)
expect(subject.instance_variable_get("@overrides")[:modules]).to eq({exclude_spec: true})
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this would have come out false before? Is that because we're passing a reference to the overrides hash rather than making a copy when we take it into the module/base class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not exactly; since the base module class deleted the key, the entire entry in the hash would be missing; if you run the test with the old code, you'll see this error message:

r10k: be rspec spec/unit/module_loader/puppetfile_spec.rb
............F............................

Failures:

  1) R10K::ModuleLoader::Puppetfile adding modules should not modify the overrides when adding modules
     Failure/Error: expect(subject.instance_variable_get("@overrides")[:modules]).to eq({exclude_spec: true})

       expected: {:exclude_spec=>true}
            got: {}

       (compared using ==)

       Diff:
       @@ -1,2 +1 @@
       -:exclude_spec => true,

     # ./spec/unit/module_loader/puppetfile_spec.rb:106:in `block (3 levels) in <top (required)>'

Finished in 0.07463 seconds (files took 0.46108 seconds to load)
41 examples, 1 failure

This means that the exclude_spec would end up as false for all remaining base class initializations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh okay. Wild.

@Magisus Magisus merged commit 2e9de59 into puppetlabs:main Feb 3, 2022
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.

2 participants