Skip to content

Commit

Permalink
custom facts: Honour stringified facts
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jul 8, 2024
1 parent 4e53f97 commit d93c3b5
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 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,20 @@ def normalize_module_name(name)
end

def add_stdlib_facts

Check failure on line 73 in lib/voxpupuli/test/facts.rb

View workflow job for this annotation

GitHub Actions / rubocop

Metrics/AbcSize: Assignment Branch Condition size for add_stdlib_facts is too high. [<3, 21, 13> 24.88/18] (http://c2.com/cgi/wiki?AbcMetric, https://en.wikipedia.org/wiki/ABC_Software_Metric)

Check failure on line 73 in lib/voxpupuli/test/facts.rb

View workflow job for this annotation

GitHub Actions / rubocop

Metrics/CyclomaticComplexity: Cyclomatic complexity for add_stdlib_facts is too high. [12/10]

Check failure on line 73 in lib/voxpupuli/test/facts.rb

View workflow job for this annotation

GitHub Actions / rubocop

Metrics/MethodLength: Method has too many lines. [31/24] (https://rubystyle.guide#short-methods)
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

0 comments on commit d93c3b5

Please sign in to comment.