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

Puppet::Util is not properly defined before use in tests (possibly elsewhere) #509

Open
jstraw opened this issue May 4, 2023 · 0 comments

Comments

@jstraw
Copy link
Contributor

jstraw commented May 4, 2023

Describe the Bug

In a MayTheSourceBeWithYou rubocop clean up I attempted to clean Style/ClassAndModuleChildren on this repository, and found that for puppet modules, the rubocop is configured for compact, but if you do class Puppet::Util::IniFile instead of module Puppet:Util\n class IniFile tests fail with a NameError uninitialized constant Puppet::Util::IniFile to which @binford2k suggested I make a ticket because "Maybe raise a ticket for someone to investigate because basically what this means is that this is being loaded before Puppet's fully initialized and that seems potentially problematic too."

Expected Behavior

I expected to have tests run successfully

What I got

pdk (INFO): Using Ruby 2.7.7
pdk (INFO): Using Puppet 7.23.0
[✔] Preparing to run the unit tests.
/opt/puppetlabs/pdk/private/ruby/2.7.7/bin/ruby -I/home/jstraw/.pdk/cache/ruby/2.7.0/gems/rspec-core-3.12.2/lib:/opt/puppetlabs/pdk/share/cache/ruby/2.7.0/gems/rspec-support-3.12.0/lib /home/jstraw/.pdk/cache/ruby/2.7.0/gems/rspec-core-3.12.2/exe/rspec --pattern spec/\{aliases,classes,defines,functions,hosts,integration,plans,tasks,type_aliases,types,unit\}/\*\*/\*_spec.rb --format progress

An error occurred while loading ./spec/unit/puppet/provider/ini_setting/inheritance_spec.rb.
Failure/Error: class Puppet::Util::IniFile::Section

Puppet::Error:
  Could not autoload puppet/type/inherit_ini_setting: Could not autoload puppet/provider/inherit_ini_setting/ini_setting: Could not autoload puppet/type/ini_setting: Could not autoload puppet/provider/ini_setting/ruby: uninitialized constant Puppet::Util::IniFile
# ./lib/puppet/util/ini_file/section.rb:6:in `<top (required)>'
# ./lib/puppet/util/ini_file.rb:4:in `<top (required)>'
# ./lib/puppet/provider/ini_setting/ruby.rb:3:in `<top (required)>'
# ./lib/puppet/type/ini_setting.rb:6:in `<top (required)>'
# ./spec/fixtures/inherit_ini_setting/lib/puppet/provider/inherit_ini_setting/ini_setting.rb:3:in `<top (required)>'
# ./spec/fixtures/inherit_ini_setting/lib/puppet/type/inherit_ini_setting.rb:1:in `<top (required)>'
# ./spec/unit/puppet/provider/ini_setting/inheritance_spec.rb:9:in `<top (required)>'
# ------------------
# --- Caused by: ---
# NameError:
#   uninitialized constant Puppet::Util::IniFile
#   ./lib/puppet/util/ini_file/section.rb:6:in `<top (required)>'

An error occurred while loading ./spec/unit/puppet/provider/ini_setting/ruby_spec.rb.
Failure/Error: class Puppet::Util::IniFile::Section

Puppet::Error:
  Could not autoload puppet/provider/ini_setting/ruby: uninitialized constant Puppet::Util::IniFile
# ./lib/puppet/util/ini_file/section.rb:6:in `<top (required)>'
# ./lib/puppet/util/ini_file.rb:4:in `<top (required)>'
# ./lib/puppet/provider/ini_setting/ruby.rb:3:in `<top (required)>'
# ./spec/unit/puppet/provider/ini_setting/ruby_spec.rb:6:in `<top (required)>'
# ------------------
# --- Caused by: ---
# NameError:
#   uninitialized constant Puppet::Util::IniFile
#   ./lib/puppet/util/ini_file/section.rb:6:in `<top (required)>'

An error occurred while loading ./spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb.
Failure/Error: class Puppet::Util::IniFile::Section

Puppet::Error:
  Could not autoload puppet/type/ini_subsetting: Could not autoload puppet/provider/ini_subsetting/ruby: uninitialized constant Puppet::Util::IniFile
# ./lib/puppet/util/ini_file/section.rb:6:in `<top (required)>'
# ./lib/puppet/util/ini_file.rb:4:in `<top (required)>'
# ./lib/puppet/provider/ini_subsetting/ruby.rb:3:in `<top (required)>'
# ./lib/puppet/type/ini_subsetting.rb:5:in `<top (required)>'
# ./spec/unit/puppet/provider/ini_subsetting/ruby_spec.rb:6:in `<top (required)>'
# ------------------
# --- Caused by: ---
# NameError:
#   uninitialized constant Puppet::Util::IniFile
#   ./lib/puppet/util/ini_file/section.rb:6:in `<top (required)>'

An error occurred while loading ./spec/unit/puppet/util/ini_file_spec.rb.
Failure/Error: class Puppet::Util::IniFile::Section

NameError:
  uninitialized constant Puppet::Util::IniFile
# ./lib/puppet/util/ini_file/section.rb:6:in `<top (required)>'
# ./lib/puppet/util/ini_file.rb:4:in `<top (required)>'
# ./spec/unit/puppet/util/ini_file_spec.rb:5:in `<top (required)>'```


## Steps to Reproduce
Steps to reproduce the behavior:
1. Remove the disable of the rubocop for Style/ClassAndModuleChildren
2. Update the 4 classes in question using either autocorrect or manually (using concise rather then nested)
3. run pdk validate and find that the rubocop is no longer failing
4. run pdk test unit and get the errors above

## Environment
 - PDK 2.7.1
 - (Module on 2.7.0)
 - Debian Testing
jstraw added a commit to jstraw/puppetlabs-inifile that referenced this issue May 4, 2023
Disable the Style/ClassAndModuleChildren rubocop manually on the 4
places it is need until puppetlabs#509 is reviewed/resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants