Skip to content

Commit

Permalink
Remove use of legacy facts
Browse files Browse the repository at this point in the history
At some point soon, either facterdb will stop providing legacy facts or
rspec-puppet-facts will be configurable to filter them out.  Either way,
we should not rely on them in this gem and use the modern counterparts
instead.
  • Loading branch information
alexjfisher committed Mar 14, 2023
1 parent 287ea89 commit 230ef78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/voxpupuli/test/facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def add_stdlib_facts
# Rough conversion of grepping in the puppet source:
# grep defaultfor lib/puppet/provider/service/*.rb
add_custom_fact :service_provider, ->(os, facts) do
case facts[:osfamily].downcase
case facts[:os]['family'].downcase
when 'archlinux'
'systemd'
when 'darwin'
Expand All @@ -85,9 +85,9 @@ def add_stdlib_facts
when 'openbsd'
'openbsd'
when 'redhat'
facts[:operatingsystemmajrelease].to_i >= 7 ? 'systemd' : 'redhat'
facts[:os]['release']['major'].to_i >= 7 ? 'systemd' : 'redhat'
when 'suse'
facts[:operatingsystemmajrelease].to_i >= 12 ? 'systemd' : 'redhat'
facts[:os]['release']['major'].to_i >= 12 ? 'systemd' : 'redhat'
when 'windows'
'windows'
else
Expand Down
12 changes: 9 additions & 3 deletions spec/facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,25 @@

it 'has systemd on Red Hat 7' do
add_facts_for_metadata(metadata)
facts = RspecPuppetFacts.with_custom_facts('redhat-7-x86_64', {osfamily: 'RedHat', operatingsystemmajrelease: '7'})
facts = RspecPuppetFacts.with_custom_facts('redhat-7-x86_64', {
os: { 'family' => 'RedHat', 'release' => { 'major' => '7' } }
})
expect(facts['systemd']).to be true
end

it 'has no systemd on Red Hat 6' do
add_facts_for_metadata(metadata)
facts = RspecPuppetFacts.with_custom_facts('redhat-6-x86_64', {osfamily: 'RedHat', operatingsystemmajrelease: '6'})
facts = RspecPuppetFacts.with_custom_facts('redhat-6-x86_64', {
os: {'family' => 'RedHat', 'release' => { 'major' => '6' }}
})
expect(facts['systemd']).to be false
end

it 'has no systemd on openbsd' do
add_facts_for_metadata(metadata)
facts = RspecPuppetFacts.with_custom_facts('openbsd-6.4-x86_64', {osfamily: 'OpenBSD'})
facts = RspecPuppetFacts.with_custom_facts('openbsd-6.4-x86_64', {
os: { 'family' => 'OpenBSD' }
})
expect(facts['systemd']).to be false
end
end
Expand Down

0 comments on commit 230ef78

Please sign in to comment.