diff --git a/functions/ensure.pp b/functions/ensure.pp index d509a746b..6019be631 100644 --- a/functions/ensure.pp +++ b/functions/ensure.pp @@ -1,13 +1,19 @@ # @summary function to cast ensure parameter to resource specific value function stdlib::ensure( Variant[Boolean, Enum['present', 'absent']] $ensure, - Enum['directory', 'link', 'mounted', 'service', 'file'] $resource, + Enum['directory', 'link', 'mounted', 'service', 'file', 'package'] $resource, ) >> String { $_ensure = $ensure ? { Boolean => $ensure.bool2str('present', 'absent'), default => $ensure, } case $resource { + 'package': { + $_ensure ? { + 'present' => 'installed', + default => 'absent', + } + } 'service': { $_ensure ? { 'present' => 'running', diff --git a/spec/functions/stdlib_ensure_spec.rb b/spec/functions/stdlib_ensure_spec.rb index 8a110b89b..2c296c3ec 100644 --- a/spec/functions/stdlib_ensure_spec.rb +++ b/spec/functions/stdlib_ensure_spec.rb @@ -17,4 +17,10 @@ it { is_expected.to run.with_params(false, resource).and_return('absent') } end end + context 'work with package resource' do + it { is_expected.to run.with_params('present', 'package').and_return('installed') } + it { is_expected.to run.with_params(true, 'package').and_return('installed') } + it { is_expected.to run.with_params('absent', 'package').and_return('absent') } + it { is_expected.to run.with_params(false, 'package').and_return('absent') } + end end