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

RFC: Add option to suppress legacy facts #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexjfisher
Copy link
Member

By default legacy facts will be removed in Puppet 8. This change mimics that.

@codecov
Copy link

codecov bot commented Mar 14, 2023

Codecov Report

Patch coverage: 70.00% and project coverage change: -7.44 ⚠️

Comparison is base (0921dff) 94.93% compared to head (b777fbc) 87.50%.

❗ Current head b777fbc differs from pull request most recent head e87a0de. Consider uploading reports for the commit e87a0de to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #143      +/-   ##
==========================================
- Coverage   94.93%   87.50%   -7.44%     
==========================================
  Files           2        3       +1     
  Lines         158      168      +10     
==========================================
- Hits          150      147       -3     
- Misses          8       21      +13     
Impacted Files Coverage Δ
lib/rspec-puppet-facts/legacy_facts.rb 62.50% <62.50%> (ø)
lib/rspec-puppet-facts.rb 91.61% <100.00%> (-6.43%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

end

RSpec.configure do |c|
c.add_setting :default_facter_version,
:default => RspecPuppetFacts.facter_version_for_puppet_version(Puppet.version)
c.add_setting :facterdb_string_keys, :default => false
c.add_setting :legacy_facts, :default => RspecPuppetFacts.legacy_facts_default_for_puppet_version(Puppet.version)
Copy link
Member Author

Choose a reason for hiding this comment

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

Following discussion with @ekohl perhaps this setting should get bumped up into rspec-puppet itself so that it can be used by both rspec-puppet-facts and the native facter implementation there.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Other than putting the configuration in rspec-puppet, I think this can make sense as a start.

The next steps should be to drop fact sets from FacterDB without modern facts (IIRC Facter < 3) and rewrite all the code here to only use modern facts.

# @return [Boolean] Is the fact a legacy fact
# @param [Symbol] fact Fact name
def self.legacy_fact?(fact)
legacy_facts.include?(fact) or fact.to_s.match(Regexp.union(legacy_fact_regexes))
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can store the union in a cache somewhere.

In Ruby it's common to use || and I think this could use match? since you don't need the actual result.

Suggested change
legacy_facts.include?(fact) or fact.to_s.match(Regexp.union(legacy_fact_regexes))
legacy_facts.include?(fact) || fact.to_s.match?(Regexp.union(legacy_fact_regexes))

@bastelfreak
Copy link
Member

some rubocop autofix will help here, I'm fine with the general code.

@alexjfisher
Copy link
Member Author

some rubocop autofix will help here, I'm fine with the general code.

I'm not though! ;)

Since rspec-puppet itself adds default legacy facts, I think the pruning has to take place there.
Something like puppetlabs/rspec-puppet#53

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.

3 participants