-
Notifications
You must be signed in to change notification settings - Fork 106
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
PDK::Util.in_module_root? can give a false positive result #768
Comments
|
Yup, this tripped me up before 😢 |
Wouldn't |
Good idea. |
👍 to making the directory check more specific |
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.
(GH-768) Fix in_module_root? gives false positives
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.
Describe the bug
The in_module_root? function reports true whenever a lib directory is found. It uses
the following folders to determine if the current directory is indeed a module.
However, just because a folder has a lib directory, does not mean it is a module and does not also mean it has a Gemfile either.
To Reproduce
mkdir -p /tmp/test/lib
pdk console
or possible any other pdk commandExpected behavior
PDK should return the correct boolean value when the current directory is not a module.
This might mean that instead of looking for lib, we look for lib/puppet.
Additional context
The text was updated successfully, but these errors were encountered: