Skip to content

Commit

Permalink
FacterDB: stringify facts
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jul 23, 2024
1 parent 0d3e074 commit 23e928b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
spec/spec_helper_acceptance.rb:
unmanaged: false
spec/spec_helper.rb:
facterdb_string_keys: true
22 changes: 11 additions & 11 deletions spec/classes/defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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')
Expand All @@ -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',
Expand All @@ -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')
}
Expand All @@ -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')
Expand Down
14 changes: 7 additions & 7 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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').
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/defines/cron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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').
Expand All @@ -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').
Expand All @@ -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' }
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 23e928b

Please sign in to comment.