Skip to content

Commit 5eb317d

Browse files
authored
Merge pull request #1213 from david-caro/stdlib_ensure_add_package_support
stdlib::ensure: Add support for package resource
2 parents 250db8f + 4bc548e commit 5eb317d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: functions/ensure.pp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# @summary function to cast ensure parameter to resource specific value
22
function stdlib::ensure(
33
Variant[Boolean, Enum['present', 'absent']] $ensure,
4-
Enum['directory', 'link', 'mounted', 'service', 'file'] $resource,
4+
Enum['directory', 'link', 'mounted', 'service', 'file', 'package'] $resource,
55
) >> String {
66
$_ensure = $ensure ? {
77
Boolean => $ensure.bool2str('present', 'absent'),
88
default => $ensure,
99
}
1010
case $resource {
11+
'package': {
12+
$_ensure ? {
13+
'present' => 'installed',
14+
default => 'absent',
15+
}
16+
}
1117
'service': {
1218
$_ensure ? {
1319
'present' => 'running',

Diff for: spec/functions/stdlib_ensure_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@
1717
it { is_expected.to run.with_params(false, resource).and_return('absent') }
1818
end
1919
end
20+
context 'work with package resource' do
21+
it { is_expected.to run.with_params('present', 'package').and_return('installed') }
22+
it { is_expected.to run.with_params(true, 'package').and_return('installed') }
23+
it { is_expected.to run.with_params('absent', 'package').and_return('absent') }
24+
it { is_expected.to run.with_params(false, 'package').and_return('absent') }
25+
end
2026
end

0 commit comments

Comments
 (0)