From 4bc548e517acdaf3806a86520c08cfbb0a0dbaa8 Mon Sep 17 00:00:00 2001 From: David Caro Date: Fri, 24 Sep 2021 12:49:42 +0200 Subject: [PATCH] stdlib::ensure: Add support for package resource This only adds 'installed' and 'absent' support, not 'latest'. Signed-off-by: David Caro --- functions/ensure.pp | 8 +++++++- spec/functions/stdlib_ensure_spec.rb | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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