Skip to content

Commit d867c10

Browse files
committed
stdlib::ensure: Add support for package resource
This only adds 'installed' and 'absent' support, not 'latest'.
1 parent 250db8f commit d867c10

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

functions/ensure.pp

Lines changed: 7 additions & 1 deletion
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',

spec/functions/stdlib_ensure_spec.rb

Lines changed: 6 additions & 0 deletions
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)