Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom facts: Honour stringified facts #144

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading