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

Performance improvements #124

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions lib/rspec-puppet-facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,30 @@
end

facterversion_obj = Gem::Version.new(facterversion)
received_facts = []

# FacterDB may have newer versions of facter data for which it contains a subset of all possible
# facter data (see FacterDB 0.5.2 for Facter releases 3.8 and 3.9). In this situation we need to
# cycle through and downgrade Facter versions per platform type until we find matching Facter data.
filter.each do |filter_spec|
facter_version_filter = RspecPuppetFacts.facter_version_to_filter(facterversion)
db = FacterDB.get_facts(filter_spec.merge({ :facterversion => facter_version_filter }))
facts = FacterDB.get_facts(filter_spec)
.select { |facts| Gem::Version.new(facts[:facterversion]) <= facterversion_obj }

Check failure on line 124 in lib/rspec-puppet-facts.rb

View workflow job for this annotation

GitHub Actions / rubocop

Lint/ShadowingOuterLocalVariable: Shadowing outer local variable - `facts`.
.max_by { |facts| Gem::Version.new(facts[:facterversion]) }

Check failure on line 125 in lib/rspec-puppet-facts.rb

View workflow job for this annotation

GitHub Actions / rubocop

Lint/ShadowingOuterLocalVariable: Shadowing outer local variable - `facts`.

if db.empty?
next unless facts
version = facts[:facterversion]

unless version == facterversion
if RspecPuppetFacts.spec_facts_strict?
raise ArgumentError, "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, aborting"
end

version = FacterDB.get_facts(filter_spec).map { |facts| Gem::Version.new(facts[:facterversion]) }.sort.reverse.detect { |v| v <= facterversion_obj }

next unless version
version = version.to_s
facter_version_filter = "/\\A#{Regexp.escape(version)}/"

unless version == facterversion
RspecPuppetFacts.warning "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, using v#{version} instead"
end
RspecPuppetFacts.warning "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, using v#{version} instead"
end

filter_spec[:facterversion] = facter_version_filter
received_facts << facts
end

received_facts = FacterDB::get_facts(filter)
unless received_facts.any?
RspecPuppetFacts.warning "No facts were found in the FacterDB for: #{filter.inspect}"
return {}
Expand Down
Loading