diff --git a/functions/ensure.pp b/functions/ensure.pp index b4ea17b2c..9b63d44e5 100644 --- a/functions/ensure.pp +++ b/functions/ensure.pp @@ -3,7 +3,7 @@ # @return [String] function stdlib::ensure( Variant[Boolean, Enum['present', 'absent']] $ensure, - Enum['directory', 'link', 'mounted', 'service', 'file', 'package'] $resource, + Optional[Enum['directory', 'link', 'mounted', 'service', 'file', 'package']] $resource = undef, ) >> String { $_ensure = $ensure ? { Boolean => $ensure.bool2str('present', 'absent'), @@ -22,6 +22,7 @@ function stdlib::ensure( default => 'stopped', } } + undef: { $_ensure } default: { $_ensure ? { 'present' => $resource, diff --git a/spec/functions/stdlib_ensure_spec.rb b/spec/functions/stdlib_ensure_spec.rb index 2c296c3ec..f4e5f7935 100644 --- a/spec/functions/stdlib_ensure_spec.rb +++ b/spec/functions/stdlib_ensure_spec.rb @@ -3,6 +3,10 @@ require 'spec_helper' describe 'stdlib::ensure' do + context 'work without resource' do + it { is_expected.to run.with_params(true).and_return('present') } + it { is_expected.to run.with_params(false).and_return('absent') } + end 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') }