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

cleanup spec tests & facterdb_string_keys: switch to strings #113

Merged
merged 2 commits into from
Jun 25, 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
2 changes: 1 addition & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
fixtures:
repositories:
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
puppet_archive: "https://github.com/voxpupuli/puppet-archive.git"
archive: "https://github.com/voxpupuli/puppet-archive.git"
1 change: 1 addition & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
spec/spec_helper.rb:
hiera_config: "'spec/fixtures/hiera.yaml'"
facterdb_string_keys: true
spec/spec_helper_acceptance.rb:
unmanaged: false
20 changes: 9 additions & 11 deletions spec/classes/ca_cert_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require 'spec_helper'

describe 'ca_cert', type: :class do
on_supported_os.each do |os, facts|
case facts[:os]['family']
describe 'ca_cert' do
on_supported_os.each do |os, os_facts|
case os_facts['os']['family']
when 'Debian'
trusted_cert_dir = '/usr/local/share/ca-certificates'
update_cmd = 'update-ca-certificates'
when 'RedHat'
trusted_cert_dir = '/etc/pki/ca-trust/source/anchors'
update_cmd = 'update-ca-trust extract'
Expand All @@ -16,24 +17,21 @@
update_cmd = 'update-ca-certificates'
end

cert_dir_group = 'root' if cert_dir_group.nil?
cert_dir_mode = '0755' if cert_dir_mode.nil?
update_cmd = 'update-ca-certificates' if update_cmd.nil?
package_name = 'ca-certificates' if package_name.nil?
package_name = 'ca-certificates'

context "on #{os}" do
let(:facts) { facts }
let(:facts) { os_facts }

it { is_expected.to compile }
it { is_expected.to compile.with_all_deps }

it do
is_expected.to contain_file('trusted_certs').only_with(
{
'ensure' => 'directory',
'path' => trusted_cert_dir,
'owner' => 'root',
'group' => cert_dir_group,
'mode' => cert_dir_mode,
'group' => 'root',
'mode' => '0755',
'purge' => false,
'recurse' => false,
'notify' => 'Exec[ca_cert_update]',
Expand Down
25 changes: 13 additions & 12 deletions spec/defines/ca_spec.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
require 'spec_helper'

describe 'ca_cert::ca', type: :define do
describe 'ca_cert::ca' do
let(:title) { 'Globalsign_Org_Intermediate' }
let(:pre_condition) do
'class {"ca_cert":
ca_certs => {},
}'
end

on_supported_os.sort.each do |os, facts|
on_supported_os.sort.each do |os, os_facts|
# define os specific defaults
case facts[:os]['family']
case os_facts['os']['family']
when 'Debian'
trusted_cert_dir = '/usr/local/share/ca-certificates'
when 'RedHat'
trusted_cert_dir = '/etc/pki/ca-trust/source/anchors'
distrusted_cert_dir = if facts[:os]['release']['major'] < '9'
distrusted_cert_dir = if os_facts['os']['release']['major'] < '9'
'/etc/pki/ca-trust/source/blacklist'
else
'/etc/pki/ca-trust/source/blocklist'
Expand All @@ -26,15 +26,16 @@
when 'Suse'
trusted_cert_dir = '/etc/pki/trust/anchors'
distrusted_cert_dir = '/etc/pki/trust/blacklist'
else
distrusted_cert_dir = ''
end

ca_file_extension = 'crt' if ca_file_extension.nil?
ca_file_group = 'root' if ca_file_group.nil?
ca_file_mode = '0644' if ca_file_mode.nil?
distrusted_cert_dir = '' if distrusted_cert_dir.nil?
ca_file_extension = 'crt'
ca_file_group = 'root'
ca_file_mode = '0644'

describe "on #{os}" do
let(:facts) { facts }
let(:facts) { os_facts }

context 'with default values for parameters' do
it { is_expected.to compile.and_raise_error(%r{Either `source` or `content` is required}) }
Expand Down Expand Up @@ -100,7 +101,7 @@

it { is_expected.not_to contain_archive("#{distrusted_cert_dir}/#{title}.#{ca_file_extension}") }

case facts[:os]['family']
case os_facts['os']['family']
when 'Debian'
it { is_expected.to contain_exec("trust ca #{title}.#{ca_file_extension}") }
it { is_expected.not_to contain_file("#{distrusted_cert_dir}/#{title}.#{ca_file_extension}") }
Expand All @@ -121,7 +122,7 @@
context 'with ensure set to "distrusted" and no source or content' do
let(:params) { { ensure: 'distrusted' } }

case facts[:os]['family']
case os_facts['os']['family']
when 'Debian'
it { is_expected.to contain_exec("distrust ca #{title}.#{ca_file_extension}") }
it { is_expected.not_to contain_archive("#{distrusted_cert_dir}/#{title}.#{ca_file_extension}") }
Expand All @@ -134,7 +135,7 @@
context 'with ensure set to "distrusted" and valid source' do
let(:params) { { ensure: 'distrusted', source: 'puppet:///testing.crt' } }

case facts[:os]['family']
case os_facts['os']['family']
when 'Debian'
it { is_expected.to contain_exec("distrust ca #{title}.#{ca_file_extension}") }
it { is_expected.not_to contain_archive("#{distrusted_cert_dir}/#{title}.#{ca_file_extension}") }
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'voxpupuli/test/spec_helper'

RSpec.configure do |c|
c.facterdb_string_keys = true
c.hiera_config = 'spec/fixtures/hiera.yaml'
end

Expand Down