Skip to content

Commit

Permalink
Merge pull request #144 from bastelfreak/stringify
Browse files Browse the repository at this point in the history
custom facts: Honour stringified facts
  • Loading branch information
bastelfreak authored Jul 8, 2024
2 parents 4e53f97 + 35ab76b commit 931b4f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
10 changes: 5 additions & 5 deletions .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-21 10:27:03 UTC using RuboCop version 1.50.2.
# on 2024-07-08 09:49:39 UTC using RuboCop version 1.50.2.
# 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 All @@ -9,17 +9,17 @@
# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 18
Max: 25

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 10
Max: 12

# Offense count: 1
# Offense count: 2
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 24
Max: 31

# Offense count: 1
# Configuration parameters: Prefixes, AllowedPatterns.
Expand Down
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
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 931b4f4

Please sign in to comment.