Skip to content

Commit

Permalink
Merge pull request #93 from alexjfisher/remove_use_of_legacy_facts
Browse files Browse the repository at this point in the history
Remove use of legacy facts
  • Loading branch information
alexjfisher authored Mar 14, 2023
2 parents 287ea89 + d6eb991 commit 0aa95ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 6 additions & 5 deletions lib/voxpupuli/test/facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def add_facts_for_metadata(metadata)
metadata['dependencies'].each do |dependency|
case normalize_module_name(dependency['name'])
when 'camptocamp/systemd', 'puppet/systemd'
add_custom_fact :systemd, ->(os, facts) { facts['service_provider'] == 'systemd' }
add_custom_fact :systemd, ->(_os, facts) { facts['service_provider'] == 'systemd' }
when 'puppetlabs/stdlib'
add_stdlib_facts
end
Expand All @@ -70,8 +70,9 @@ 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
add_custom_fact :service_provider, ->(_os, facts) do
os = RSpec.configuration.facterdb_string_keys ? facts['os'] : facts[:os]
case os['family'].downcase
when 'archlinux'
'systemd'
when 'darwin'
Expand All @@ -85,9 +86,9 @@ def add_stdlib_facts
when 'openbsd'
'openbsd'
when 'redhat'
facts[:operatingsystemmajrelease].to_i >= 7 ? 'systemd' : 'redhat'
os['release']['major'].to_i >= 7 ? 'systemd' : 'redhat'
when 'suse'
facts[:operatingsystemmajrelease].to_i >= 12 ? 'systemd' : 'redhat'
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 0aa95ac

Please sign in to comment.