From 23e928be9a4b56770ef40b15fa2ead99800cb271 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Tue, 23 Jul 2024 12:14:48 +0200 Subject: [PATCH] FacterDB: stringify facts --- .sync.yml | 2 ++ spec/classes/defaults_spec.rb | 22 +++++++++++----------- spec/classes/init_spec.rb | 14 +++++++------- spec/defines/cron_spec.rb | 10 +++++----- spec/spec_helper.rb | 2 +- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.sync.yml b/.sync.yml index 5d21319c..a3a2734d 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,3 +1,5 @@ --- spec/spec_helper_acceptance.rb: unmanaged: false +spec/spec_helper.rb: + facterdb_string_keys: true diff --git a/spec/classes/defaults_spec.rb b/spec/classes/defaults_spec.rb index 542c60dd..a5eb19ba 100644 --- a/spec/classes/defaults_spec.rb +++ b/spec/classes/defaults_spec.rb @@ -6,20 +6,20 @@ let(:pre_condition) { 'class { "logrotate": }' } context 'no osfamily' do - let(:facts) { { os: { family: 'fake' } } } + let(:facts) { { 'os' => { 'family' => 'fake' } } } it { is_expected.to contain_logrotate__conf('/etc/logrotate.conf') } end - on_supported_os.each do |os, facts| - context os, if: facts[:osfamily] == 'Debian' do - let(:facts) { facts } + on_supported_os.each do |os, os_facts| + context os, if: os_facts['os']['family'] == 'Debian' do + let(:facts) { os_facts } it { is_expected.to compile.with_all_deps } - if facts[:operatingsystem] == 'Ubuntu' + if os_facts['os']['name'] == 'Ubuntu' it { is_expected.to contain_logrotate__conf('/etc/logrotate.conf').with( 'su_user' => 'root', @@ -56,8 +56,8 @@ } end - context os, if: facts[:osfamily] == 'RedHat' do - let(:facts) { facts } + context os, if: os_facts['os']['family'] == 'RedHat' do + let(:facts) { os_facts } it { is_expected.to contain_logrotate__conf('/etc/logrotate.conf') @@ -67,7 +67,7 @@ is_expected.to contain_logrotate__rule('wtmp').with( 'path' => '/var/log/wtmp', 'create_mode' => '0664', - 'missingok' => facts[:operatingsystemmajrelease].to_i >= 8, + 'missingok' => facts['os']['release']['major'].to_i >= 8, 'minsize' => '1M', 'create' => true, 'create_owner' => 'root', @@ -91,7 +91,7 @@ } end - context os, if: facts[:osfamily] == 'Suse' do + context os, if: os_facts['os']['family'] == 'Suse' do it { is_expected.to contain_logrotate__conf('/etc/logrotate.conf') } @@ -113,8 +113,8 @@ } end - context os, if: facts[:osfamily] == 'FreeBSD' do - let(:facts) { facts } + context os, if: os_facts['os']['family'] == 'FreeBSD' do + let(:facts) { os_facts } it { is_expected.to contain_logrotate__conf('/usr/local/etc/logrotate.conf') diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 28475bc8..2b649bec 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -4,10 +4,10 @@ describe 'logrotate' do context 'supported operating systems' do - on_supported_os.each do |os, facts| + on_supported_os.each do |os, os_facts| context "on #{os}" do let(:facts) do - facts + os_facts end context 'logrotate class without any parameters' do @@ -18,7 +18,7 @@ it { is_expected.to contain_class("logrotate::#{classs}") } end - case facts[:operatingsystem] + case os_facts['os']['name'] when 'FreeBSD' it do is_expected.to contain_file('/usr/local/etc/logrotate.d/hourly').with( @@ -52,7 +52,7 @@ is_expected.to contain_class('logrotate::defaults') end - if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i >= 9 + if os_facts['os']['family'] == 'RedHat' && os_facts['os']['release']['major'].to_i >= 9 it do is_expected.to contain_service('logrotate.timer').with( 'ensure' => 'running', @@ -142,7 +142,7 @@ context 'logrotate class with purge_configdir set to true' do let(:params) { { purge_configdir: true } } - case facts[:operatingsystem] + case os_facts['os']['name'] when 'FreeBSD' it do is_expected.to contain_file('/usr/local/etc/logrotate.d').with('ensure' => 'directory', @@ -176,7 +176,7 @@ context 'with config => { prerotate => "/usr/bin/test", rotate_every => "daily" }' do let(:params) { { config: { prerotate: '/usr/bin/test', rotate_every: 'daily' } } } - case facts[:operatingsystem] + case os_facts['os']['name'] when 'FreeBSD' it { is_expected.to contain_logrotate__conf('/usr/local/etc/logrotate.conf'). @@ -195,7 +195,7 @@ context 'with ensure => absent' do let(:params) { { ensure_cron_hourly: 'absent' } } - case facts[:operatingsystem] + case os_facts['os']['name'] when 'FreeBSD' it { is_expected.to contain_file('/usr/local/etc/logrotate.d/hourly').with_ensure('directory') } else diff --git a/spec/defines/cron_spec.rb b/spec/defines/cron_spec.rb index 9e56587e..4b6fbd9a 100644 --- a/spec/defines/cron_spec.rb +++ b/spec/defines/cron_spec.rb @@ -6,17 +6,17 @@ context 'supported operating systems' do let(:pre_condition) { 'class { "logrotate": }' } - on_supported_os.each do |os, facts| + on_supported_os.each do |os, os_facts| context "on #{os}" do let(:facts) do - facts + os_facts end context 'With default params' do let(:title) { 'test' } let(:params) { { ensure: 'present' } } - if facts[:osfamily] == 'FreeBSD' + if os_facts['os']['family'] == 'FreeBSD' it { is_expected.to contain_file('/usr/local/bin/logrotate.test.sh'). with_ensure('present'). @@ -36,7 +36,7 @@ let(:title) { 'test' } let(:params) { { ensure: 'present' } } - if facts[:osfamily] == 'FreeBSD' + if os_facts['os']['family'] == 'FreeBSD' it { is_expected.to contain_file('/usr/local/bin/logrotate.test.sh'). with_ensure('present'). @@ -56,7 +56,7 @@ # Test FreeBSD separately as it is only partially supported by the module and not in the list of supported os. # When FreeBSD is added to the list of supported systems, these tests can be removed as they are already part of the test set above. context 'on FreeBDS' do - let(:facts) { { os: { family: 'FreeBSD' } } } + let(:facts) { { 'os' => { 'family' => 'FreeBSD' } } } context 'With default params' do let(:title) { 'test' } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 58c9b66a..d9a3f293 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,7 +10,7 @@ require 'voxpupuli/test/spec_helper' RSpec.configure do |c| - c.facterdb_string_keys = false + c.facterdb_string_keys = true end add_mocked_facts!