diff --git a/functions/ensure.pp b/functions/ensure.pp index d509a74..6019be6 100644 --- a/functions/ensure.pp +++ b/functions/ensure.pp @@ -1,24 +1,30 @@ # @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', default => 'stopped', } } default: { $_ensure ? { 'present' => $resource, default => $_ensure, } } } } diff --git a/spec/functions/stdlib_ensure_spec.rb b/spec/functions/stdlib_ensure_spec.rb index 8a110b8..2c296c3 100644 --- a/spec/functions/stdlib_ensure_spec.rb +++ b/spec/functions/stdlib_ensure_spec.rb @@ -1,20 +1,26 @@ # frozen_string_literal: true require 'spec_helper' describe 'stdlib::ensure' do context 'work with service resource' do it { is_expected.to run.with_params('present', 'service').and_return('running') } it { is_expected.to run.with_params(true, 'service').and_return('running') } it { is_expected.to run.with_params('absent', 'service').and_return('stopped') } it { is_expected.to run.with_params(false, 'service').and_return('stopped') } end ['directory', 'link', 'mounted', 'file'].each do |resource| context "work with #{resource} resource" do it { is_expected.to run.with_params('present', resource).and_return(resource) } it { is_expected.to run.with_params(true, resource).and_return(resource) } it { is_expected.to run.with_params('absent', resource).and_return('absent') } 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