From 35ab76b1ecb24f3778cae06efa7f6230e1b60065 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Mon, 8 Jul 2024 11:41:24 +0200 Subject: [PATCH] custom facts: Honour stringified facts --- .rubocop_todo.yml | 10 +++++----- lib/voxpupuli/test/facts.rb | 21 ++++++++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e2058e2..a6ef207 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 @@ -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. diff --git a/lib/voxpupuli/test/facts.rb b/lib/voxpupuli/test/facts.rb index 057b396..abc58ff 100644 --- a/lib/voxpupuli/test/facts.rb +++ b/lib/voxpupuli/test/facts.rb @@ -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 @@ -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'