From edb710b6f5d95d86631d05075d098a2ceea10e95 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Wed, 26 Jun 2024 19:25:44 +0200 Subject: [PATCH] handle stringified facterversion properly With symbolized keys we get something like this: ``` No facts were found in the FacterDB for Facter v4.7.0 on {"os.name"=>"Archlinux", "os.hardware"=>"x86_64"}, using v4.5.2 instead ``` But if we stringify the factset we get: ``` No facts were found in the FacterDB for Facter v4.7.0 on {"os.name"=>"Archlinux", "os.hardware"=>"x86_64"}, using v instead ``` This PR fixes it. --- lib/rspec-puppet-facts.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rspec-puppet-facts.rb b/lib/rspec-puppet-facts.rb index 81a34fd2..2c7b5d83 100644 --- a/lib/rspec-puppet-facts.rb +++ b/lib/rspec-puppet-facts.rb @@ -116,9 +116,10 @@ def on_supported_os_implementation(opts = {}) # 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. + facterversion_key = RSpec.configuration.facterdb_string_keys ? 'facterversion' : :facterversion filter.each do |filter_spec| versions = FacterDB.get_facts(filter_spec, symbolize_keys: !RSpec.configuration.facterdb_string_keys).to_h do |facts| - [Gem::Version.new(facts[:facterversion]), facts] + [Gem::Version.new(facts[facterversion_key]), facts] end version, facts = versions.select { |v, _f| strict_requirement =~ v }.max_by { |v, _f| v }