Skip to content

Commit

Permalink
cleanup spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jun 25, 2024
1 parent dfe44e8 commit 16e351e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
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"
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

0 comments on commit 16e351e

Please sign in to comment.