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

(GH-768) Fix in_module_root? gives false positives #783

Merged
merged 3 commits into from
Oct 21, 2019

Conversation

glennsarti
Copy link
Contributor

Fixes #768

Previously the module root detection used the bare lib directory to detect if
a user was in a module root, without a metadata.json. However this caused
false positives as lib is a very common directory. For example when in a ruby
gem project. This commit modifies the detect to use more puppet specific paths:

  • lib/puppet
  • lib/facter
  • lib/puppet_x

This commit also adds tests for these folder directories, and uses the PDK
Filesystem abstraction classes.

Previously the module root detection used the bare `lib` directory to detect if
a user was in a module root, without a metadata.json.  However this caused
false positives as `lib` is a very common directory. For example when in a ruby
gem project. This commit modifies the detect to use more puppet specific paths:
* lib/puppet
* lib/facter
* lib/puppet_x

This commit also adds tests for these folder directories, and uses the PDK
Filesystem abstraction classes.
Previously the module root detection was changed to not detect the bare `lib`
directory however this caused many of the unit tests to fail as it was detecting
the PDK gem as a valid module (which it is not).  This commit adds an empty
module root fixture and mocks the various tests use this as the module root.
Previously the `ensure_in_module!` tests tested for the various module
directories (lib, tasks and so on).  However this is really just duplicating
the tests for `in_module_root?` which is not required.  This commit removes
these tests and just mocks the response from `in_module_root?`.  This results
in no loss of test coverage.
@glennsarti glennsarti requested a review from a team as a code owner October 21, 2019 04:31
@glennsarti glennsarti added this to the November 2019 milestone Oct 21, 2019
@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.842% when pulling 5302c70 on glennsarti:gh-768-module-root into 3687f6c on puppetlabs:master.

Copy link
Contributor

@scotje scotje left a 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!

@glennsarti glennsarti merged commit 25ad912 into puppetlabs:master Oct 21, 2019
@glennsarti glennsarti deleted the gh-768-module-root branch March 5, 2020 04:58
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.

PDK::Util.in_module_root? can give a false positive result
4 participants