Skip to content

Commit

Permalink
FacterDB: Switch to stringified facts
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Sep 9, 2024
1 parent 959c7cf commit ab20288
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
enabled_lint_checks:
- parameter_documentation
- parameter_types
spec/spec_helper.rb:
facterdb_string_keys: true
21 changes: 10 additions & 11 deletions spec/classes/letsencrypt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
describe 'with defaults' do
it { is_expected.to compile }

epel = facts[:osfamily] == 'RedHat' && facts[:operatingsystem] != 'Fedora'

epel = facts['os']['family'] == 'RedHat' && facts['os']['name'] != 'Fedora'
it 'contains the correct resources' do
is_expected.to contain_class('letsencrypt::install').
with(configure_epel: epel).
Expand All @@ -33,7 +32,7 @@
cron_monthday: ['*'])
is_expected.to contain_cron('letsencrypt-renew').with_ensure('absent')

if facts[:osfamily] == 'FreeBSD'
if facts['os']['family'] == 'FreeBSD'
is_expected.to contain_ini_setting('/usr/local/etc/letsencrypt/cli.ini email [email protected]')
is_expected.to contain_ini_setting('/usr/local/etc/letsencrypt/cli.ini server https://acme-v02.api.letsencrypt.org/directory')
is_expected.to contain_file('letsencrypt-renewal-hooks-puppet').
Expand All @@ -50,7 +49,7 @@
is_expected.to contain_file('letsencrypt-renewal-hooks-puppet').with_path('/etc/letsencrypt/renewal-hooks-puppet')
end

if facts[:osfamily] == 'RedHat'
if facts['os']['family'] == 'RedHat'
if epel
is_expected.to contain_class('epel').that_comes_before('Package[letsencrypt]')
else
Expand All @@ -60,20 +59,20 @@
is_expected.to contain_class('letsencrypt').with(package_command: 'certbot')
is_expected.to contain_package('letsencrypt').with(name: 'certbot').with_ensure('installed')
is_expected.to contain_file('/etc/letsencrypt').with(ensure: 'directory')
elsif facts[:osfamily] == 'Debian'
elsif facts['os']['family'] == 'Debian'
is_expected.to contain_class('letsencrypt::install').with(package_name: 'certbot')
is_expected.to contain_file('/etc/letsencrypt').with(ensure: 'directory')
elsif facts[:operatingsystem] == 'Gentoo'
elsif facts['os']['name'] == 'Gentoo'
is_expected.to contain_class('letsencrypt::install').with(package_name: 'app-crypt/certbot')
is_expected.to contain_class('letsencrypt').with(package_command: 'certbot')
is_expected.to contain_package('letsencrypt').with(name: 'app-crypt/certbot').with_ensure('installed')
is_expected.to contain_file('/etc/letsencrypt').with(ensure: 'directory')
elsif facts[:operatingsystem] == 'OpenBSD'
elsif facts['os']['name' == 'OpenBSD'
is_expected.to contain_class('letsencrypt::install').with(package_name: 'certbot')

Check failure on line 71 in spec/classes/letsencrypt_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Lint/Syntax: unexpected token tIDENTIFIER (Using Ruby 2.6 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
is_expected.to contain_class('letsencrypt').with(package_command: 'certbot')
is_expected.to contain_package('letsencrypt').with(name: 'certbot').with_ensure('installed')
is_expected.to contain_file('/etc/letsencrypt').with(ensure: 'directory')
elsif facts[:operatingsystem] == 'FreeBSD'
elsif facts['os']['name' == 'FreeBSD'
is_expected.to contain_class('letsencrypt::install').with(package_name: 'py311-certbot')

Check failure on line 76 in spec/classes/letsencrypt_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Lint/Syntax: unexpected token tIDENTIFIER (Using Ruby 2.6 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
is_expected.to contain_class('letsencrypt').with(package_command: 'certbot')
is_expected.to contain_package('letsencrypt').with(name: 'py311-certbot').with_ensure('installed')
Expand All @@ -100,7 +99,7 @@
describe 'with custom config' do
let(:additional_params) { { config: { 'foo' => 'bar' } } }

case facts[:operatingsystem]
case facts['os']['name']
when 'FreeBSD'
it { is_expected.to contain_ini_setting('/usr/local/etc/letsencrypt/cli.ini foo bar') }
else
Expand Down Expand Up @@ -237,7 +236,7 @@

it { is_expected.to compile.with_all_deps }

case facts[:operatingsystem]
case facts['os']['name']
when 'FreeBSD'
it { is_expected.to contain_ini_setting('/usr/local/etc/letsencrypt/cli.ini email [email protected]') }
else
Expand All @@ -253,7 +252,7 @@
context 'with unsafe_registration set to true' do
let(:params) { { unsafe_registration: true } }

case facts[:operatingsystem]
case facts['os']['name']
when 'FreeBSD'
it { is_expected.not_to contain_ini_setting('/usr/local/etc/letsencrypt/cli.ini email [email protected]') }
it { is_expected.to contain_ini_setting('/usr/local/etc/letsencrypt/cli.ini register-unsafely-without-email true') }
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/plugin/dns_cloudflare_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class { 'letsencrypt':
PUPPET
end
let(:package_name) do
if %w[Debian RedHat].include?(facts[:os]['family'])
if %w[Debian RedHat].include?(facts['os']['family'])
'python3-certbot-dns-cloudflare'
elsif %w[FreeBSD].include?(facts[:os]['family'])
elsif %w[FreeBSD].include?(facts['os']['family'])
'py311-certbot-dns-cloudflare'
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/plugin/dns_rfc2136_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class { 'letsencrypt':
PUPPET
end
let(:package_name) do
case facts[:os]['family']
case facts['os']['family']
when 'FreeBSD'
'py311-certbot-dns-rfc2136'
when 'OpenBSD'
Expand All @@ -39,7 +39,7 @@ class { 'letsencrypt':
end

# FreeBSD uses a different filesystem path
let(:pathprefix) { facts[:kernel] == 'FreeBSD' ? '/usr/local' : '' }
let(:pathprefix) { facts['kernel'] == 'FreeBSD' ? '/usr/local' : '' }

it do
if package_name.empty?
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/plugin/dns_route53_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class { 'letsencrypt':
PUPPET
end
let(:package_name) do
case facts[:os]['family']
case facts['os']['family']
when 'FreeBSD'
'py311-certbot-dns-route53'
when 'OpenBSD'
Expand Down
6 changes: 3 additions & 3 deletions spec/defines/letsencrypt_certonly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let(:pre_condition) { "class { letsencrypt: email => '[email protected]', package_command => 'letsencrypt' }" }

# FreeBSD uses a different filesystem path
pathprefix = facts[:kernel] == 'FreeBSD' ? '/usr/local' : ''
pathprefix = facts['kernel'] == 'FreeBSD' ? '/usr/local' : ''

context 'with a single domain' do
let(:title) { 'foo.example.com' }
Expand All @@ -32,7 +32,7 @@
with_content(%r{#!/bin/sh})
end

if facts[:osfamily] == 'FreeBSD'
if facts['os']['family'] == 'FreeBSD'
it { is_expected.to contain_file('/usr/local/etc/letsencrypt') }
it { is_expected.to contain_ini_setting('/usr/local/etc/letsencrypt/cli.ini email [email protected]') }
it { is_expected.to contain_ini_setting('/usr/local/etc/letsencrypt/cli.ini server https://acme-v02.api.letsencrypt.org/directory') }
Expand Down Expand Up @@ -497,7 +497,7 @@ class { 'letsencrypt::plugin::dns_cloudflare':
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_unless(['test ! -f /usr/local/sbin/letsencrypt-domain-validation', '/usr/local/sbin/letsencrypt-domain-validation /foo/bar/baz/live/foo.example.com/cert.pem \'foo.example.com\'']) }
end

context 'on FreeBSD', if: facts[:os]['name'] == 'FreeBSD' do
context 'on FreeBSD', if: facts['os']['name'] == 'FreeBSD' do
let(:title) { 'foo.example.com' }
let(:pre_condition) { "class { letsencrypt: email => '[email protected]'}" }

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 ab20288

Please sign in to comment.