From f9d9483b9ec7bc96a8853100b848a584f37887b3 Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Thu, 27 Feb 2025 21:59:48 -0500 Subject: [PATCH] Convert tar_extract to a class --- manifests/init.pp | 3 +- manifests/tar_extract.pp | 13 +++------ spec/classes/certs_tar_extract_spec.rb | 31 +++++++++++++++++++++ spec/defines/tar_extract_spec.rb | 38 -------------------------- 4 files changed, 37 insertions(+), 48 deletions(-) create mode 100644 spec/classes/certs_tar_extract_spec.rb delete mode 100644 spec/defines/tar_extract_spec.rb diff --git a/manifests/init.pp b/manifests/init.pp index d473c321..b69d28d3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -109,7 +109,8 @@ $katello_default_ca_cert = "${pki_dir}/certs/${default_ca_name}.crt" if $tar_file { - certs::tar_extract { $tar_file: + class { 'certs::tar_extract': + path => $tar_file, before => Class['certs::install'], } } diff --git a/manifests/tar_extract.pp b/manifests/tar_extract.pp index 92efb754..710c3f3d 100644 --- a/manifests/tar_extract.pp +++ b/manifests/tar_extract.pp @@ -1,15 +1,10 @@ -# Definition: certs::tar_extract -# -# This class extracts a tarball -# +# @summary This class extracts a tarball +# @api private # Parameters: # - The $path of the tarball to extract # -# Actions: -# - Extracts a tarball -# -define certs::tar_extract ( - Stdlib::Absolutepath $path = $title, +class certs::tar_extract ( + Stdlib::Absolutepath $path, ) { validate_file_exists($path) diff --git a/spec/classes/certs_tar_extract_spec.rb b/spec/classes/certs_tar_extract_spec.rb new file mode 100644 index 00000000..3ef21a6e --- /dev/null +++ b/spec/classes/certs_tar_extract_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe 'certs::tar_extract' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let :facts do + os_facts + end + + let(:params) { { path: '/some/other/path/with/certs.tar' } } + + describe 'with default parameters' do + it { should compile.with_all_deps } + end + + it do + allow(File).to receive(:exist?).and_call_original + allow(File).to receive(:exist?).with('/some/other/path/with/certs.tar').and_return(true) + + is_expected.to compile.with_all_deps + is_expected.to contain_exec('extract /some/other/path/with/certs.tar') + .with_cwd('/root') + .with_path(['/usr/bin', '/bin']) + .with_command('tar -xaf /some/other/path/with/certs.tar') + + expect(File).not_to have_received(:exist?).with('/path/to/certs.tar') + expect(File).to have_received(:exist?).with('/some/other/path/with/certs.tar') + end + end + end +end diff --git a/spec/defines/tar_extract_spec.rb b/spec/defines/tar_extract_spec.rb deleted file mode 100644 index 0ca941f6..00000000 --- a/spec/defines/tar_extract_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'spec_helper' - -describe 'certs::tar_extract' do - let(:title) { '/path/to/certs.tar' } - - context 'without parameters' do - it do - allow(File).to receive(:exist?).and_call_original - allow(File).to receive(:exist?).with('/path/to/certs.tar').and_return(true) - - is_expected.to compile.with_all_deps - is_expected.to contain_exec('extract /path/to/certs.tar') - .with_cwd('/root') - .with_path(['/usr/bin', '/bin']) - .with_command('tar -xaf /path/to/certs.tar') - - expect(File).to have_received(:exist?).with('/path/to/certs.tar') - end - end - - context 'with an explicit path' do - let(:params) { { path: '/some/other/path/with/certs.tar' } } - - it do - allow(File).to receive(:exist?).and_call_original - allow(File).to receive(:exist?).with('/some/other/path/with/certs.tar').and_return(true) - - is_expected.to compile.with_all_deps - is_expected.to contain_exec('extract /some/other/path/with/certs.tar') - .with_cwd('/root') - .with_path(['/usr/bin', '/bin']) - .with_command('tar -xaf /some/other/path/with/certs.tar') - - expect(File).not_to have_received(:exist?).with('/path/to/certs.tar') - expect(File).to have_received(:exist?).with('/some/other/path/with/certs.tar') - end - end -end