From f1803d4dec5f8c44046b6f84df27b3826f55ed15 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Tue, 11 Apr 2023 13:56:02 +0000 Subject: [PATCH] Add support for ensure_packages --- manifests/init.pp | 21 +++++++++++++-------- spec/classes/init_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 6092ef7..e6ebfb0 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -28,15 +28,19 @@ # @param services # Hash of resource type `service`. # +# @param ensure_packages +# Array of packages to install with `ensure_packages`. +# class types ( - Hash $crons = {}, - Hash $execs = {}, - Hash $file_lines = {}, - Hash $files = {}, - Hash $mounts = {}, - Hash $packages = {}, - Hash $selbooleans = {}, - Hash $services = {}, + Hash $crons = {}, + Hash $execs = {}, + Hash $file_lines = {}, + Hash $files = {}, + Hash $mounts = {}, + Hash $packages = {}, + Hash $selbooleans = {}, + Hash $services = {}, + Array $ensure_packages = [], ) { create_resources('types::cron',$crons) create_resources('types::exec',$execs) @@ -46,4 +50,5 @@ create_resources('types::package',$packages) create_resources('types::selboolean',$selbooleans) create_resources('types::service',$services) + ensure_packages($ensure_packages) } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index caf55e1..365248c 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -579,4 +579,32 @@ }.to raise_error(Puppet::Error) end end + + context 'with ensure_packages specified as an array [pkg1, pkg2]' do + let(:params) do + { + ensure_packages: ['pkg1', 'pkg2'], + } + end + + it { is_expected.to contain_package('pkg1') } + it { is_expected.to contain_package('pkg2') } + end + + context 'with ensure_packages specified as an array with duplicate package names [dupllicate, dupllicate, unique]' do + let(:params) { { ensure_packages: ['dupllicate', 'dupllicate', 'unique'] } } + + it { is_expected.to contain_package('dupllicate') } + it { is_expected.to contain_package('unique') } + end + + context 'with ensure_packages specifying an already declared package name' do + let(:params) { { ensure_packages: ['dupllicate', 'unique'] } } + let(:pre_condition) do + "ensure_packages('dupllicate')" + end + + it { is_expected.to contain_package('dupllicate') } + it { is_expected.to contain_package('unique') } + end end