Skip to content

Commit

Permalink
require rspec-puppet-facts 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jul 8, 2024
1 parent 4e53f97 commit 231f7bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions lib/voxpupuli/test/facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ 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' }
if RSpec.configuration.facterdb_string_keys
add_custom_fact 'systemd', ->(_os, facts) { facts['service_provider'] == 'systemd' }
else
add_custom_fact :systemd, ->(_os, facts) { facts[:service_provider] == 'systemd' }
end
when 'puppetlabs/stdlib'
add_stdlib_facts
end
Expand All @@ -67,13 +71,21 @@ def normalize_module_name(name)
end

def add_stdlib_facts
add_custom_fact :puppet_environmentpath, '/etc/puppetlabs/code/environments'
add_custom_fact :puppet_vardir, '/opt/puppetlabs/puppet/cache'
add_custom_fact :root_home, '/root'
if RSpec.configuration.facterdb_string_keys
add_custom_fact 'puppet_environmentpath', '/etc/puppetlabs/code/environments'
add_custom_fact 'puppet_vardir', '/opt/puppetlabs/puppet/cache'
add_custom_fact 'root_home', '/root'
else
add_custom_fact :puppet_environmentpath, '/etc/puppetlabs/code/environments'
add_custom_fact :puppet_vardir, '/opt/puppetlabs/puppet/cache'
add_custom_fact :root_home, '/root'
end

# Rough conversion of grepping in the puppet source:
# grep defaultfor lib/puppet/provider/service/*.rb
add_custom_fact :service_provider, lambda { |_os, facts|
service_provider = RSpec.configuration.facterdb_string_keys ? 'service_provider' : :service_provider
add_custom_fact service_provider, lambda { |_os, facts|

os = RSpec.configuration.facterdb_string_keys ? facts['os'] : facts[:os]
case os['family'].downcase
when 'archlinux', 'debian', 'redhat'
Expand Down
2 changes: 1 addition & 1 deletion voxpupuli-test.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |s|
# 3.0.0 and later require Ruby 2.7
s.add_runtime_dependency 'puppet-strings', '~> 4.0'
s.add_runtime_dependency 'rspec-puppet', '~> 4.0'
s.add_runtime_dependency 'rspec-puppet-facts', '~> 4.0'
s.add_runtime_dependency 'rspec-puppet-facts', '~> 5.0'
s.add_runtime_dependency 'rspec-puppet-utils', '~> 3.4'

# Rubocop
Expand Down

0 comments on commit 231f7bf

Please sign in to comment.