Skip to content

Commit

Permalink
Require FacterDB 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jun 9, 2024
1 parent 3803db4 commit e65a41f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-06-09 13:06:43 UTC using RuboCop version 1.63.5.
# on 2024-06-09 13:09:14 UTC using RuboCop version 1.63.5.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down
12 changes: 6 additions & 6 deletions lib/rspec-puppet-facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def on_supported_os_implementation(opts = {})
# 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|
versions = FacterDB.get_facts(filter_spec).to_h { |facts| [Gem::Version.new(facts[:facterversion]), facts] }
versions = FacterDB.get_facts(filter_spec, symbolize_keys: !RSpec.configuration.facterdb_string_keys).to_h { |facts| [Gem::Version.new(facts[:facterversion]), facts] }

version, facts = versions.select { |v, _f| strict_requirement =~ v }.max_by { |v, _f| v }

Expand All @@ -144,7 +144,7 @@ def on_supported_os_implementation(opts = {})

os_facts_hash = {}
received_facts.map do |facts|
os_fact = facts[:os]
os_fact = RSpec.configuration.facterdb_string_keys ? facts['os'] : facts[:os]
unless os_fact
RspecPuppetFacts.warning "No os fact was found in FacterDB for: #{facts}"
next
Expand All @@ -156,8 +156,6 @@ def on_supported_os_implementation(opts = {})
os_facts_hash[os] = RspecPuppetFacts.with_custom_facts(os, facts)
end

return stringify_keys(os_facts_hash) if RSpec.configuration.facterdb_string_keys

os_facts_hash
end

Expand Down Expand Up @@ -264,6 +262,7 @@ def self.common_facts
if augeas?
@common_facts[:augeasversion] = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD).get('/augeas/version')
end
@common_facts = stringify_keys(@common_facts) if RSpec.configuration.facterdb_string_keys

@common_facts
end
Expand Down Expand Up @@ -424,6 +423,7 @@ def self.facter_version_for_puppet_version(puppet_version)

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
default: RspecPuppetFacts.facter_version_for_puppet_version(Puppet.version)
c.add_setting :facterdb_string_keys,
default: false
end
14 changes: 8 additions & 6 deletions spec/rspec_puppet_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@
'os.hardware' => "x86_64",
}

expect(FacterDB).to receive(:get_facts).with(filter).once
expect(FacterDB).to receive(:get_facts).with(filter, symbolize_keys: true).once
subject
end

Expand Down Expand Up @@ -715,7 +715,9 @@

it 'returns facts from a facter version matching version and below' do
is_expected.to match(
'centos-9-x86_64' => include(:facterversion => /\A4\.[0-7]\./,),
'centos-9-x86_64' => include(
:facterversion => /\A4\.[0-7]\./,
),
)
end

Expand Down Expand Up @@ -790,18 +792,18 @@
before do
allow(FacterDB).to receive(:get_facts).and_call_original
allow(FacterDB).to receive(:get_facts).with(
{'os.name'=>"CentOS", 'os.release.full'=>"/^9/", 'os.hardware'=>"x86_64"},
{'os.name'=>"CentOS", 'os.release.full'=>"/^9/", 'os.hardware'=>"x86_64"}, symbolize_keys: true,
).and_wrap_original do |m, *args|
m.call(*args).reject { |facts| facts[:facterversion].start_with?('4.6.') }
end
end

it 'returns CentOS facts from a facter version matching 4.5' do
is_expected.to include('centos-9-x86_64' => include(:facterversion => '4.5.2'))
is_expected.to include('centos-9-x86_64' => include(facterversion: '4.5.2'))
end

it 'returns Debian facts from a facter version matching 4.6.1' do
is_expected.to include('debian-12-x86_64' => include(:facterversion => '4.6.1'),)
is_expected.to include('debian-12-x86_64' => include(facterversion: '4.6.1'),)
end
end
end
Expand All @@ -815,7 +817,7 @@
"operatingsystem" => "RedHat",
"operatingsystemrelease" => [
"8",
"9"
"9",
],
},
],
Expand Down

0 comments on commit e65a41f

Please sign in to comment.