Skip to content

Commit a5ef0c9

Browse files
authored
Merge pull request #1286 from b4ldr/ensure_generic
stdlib::ensure: update function to support the generic case
2 parents fd418ae + fb3a5a6 commit a5ef0c9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

functions/ensure.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# @return [String]
44
function stdlib::ensure(
55
Variant[Boolean, Enum['present', 'absent']] $ensure,
6-
Enum['directory', 'link', 'mounted', 'service', 'file', 'package'] $resource,
6+
Optional[Enum['directory', 'link', 'mounted', 'service', 'file', 'package']] $resource = undef,
77
) >> String {
88
$_ensure = $ensure ? {
99
Boolean => $ensure.bool2str('present', 'absent'),
@@ -22,6 +22,7 @@ function stdlib::ensure(
2222
default => 'stopped',
2323
}
2424
}
25+
undef: { $_ensure }
2526
default: {
2627
$_ensure ? {
2728
'present' => $resource,

spec/functions/stdlib_ensure_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
require 'spec_helper'
44

55
describe 'stdlib::ensure' do
6+
context 'work without resource' do
7+
it { is_expected.to run.with_params(true).and_return('present') }
8+
it { is_expected.to run.with_params(false).and_return('absent') }
9+
end
610
context 'work with service resource' do
711
it { is_expected.to run.with_params('present', 'service').and_return('running') }
812
it { is_expected.to run.with_params(true, 'service').and_return('running') }

0 commit comments

Comments
 (0)