Skip to content

Commit

Permalink
Add support for ensure_packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Friderici committed Nov 9, 2023
1 parent 8de22c3 commit f1803d4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
21 changes: 13 additions & 8 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@
# @param services
# Hash of resource type `service`.
#
# @param ensure_packages
# Array of packages to install with `ensure_packages`.
#
class types (
Hash $crons = {},
Hash $execs = {},
Hash $file_lines = {},
Hash $files = {},
Hash $mounts = {},
Hash $packages = {},
Hash $selbooleans = {},
Hash $services = {},
Hash $crons = {},
Hash $execs = {},
Hash $file_lines = {},
Hash $files = {},
Hash $mounts = {},
Hash $packages = {},
Hash $selbooleans = {},
Hash $services = {},
Array $ensure_packages = [],
) {
create_resources('types::cron',$crons)
create_resources('types::exec',$execs)
Expand All @@ -46,4 +50,5 @@
create_resources('types::package',$packages)
create_resources('types::selboolean',$selbooleans)
create_resources('types::service',$services)
ensure_packages($ensure_packages)
}
28 changes: 28 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -579,4 +579,32 @@
}.to raise_error(Puppet::Error)
end
end

context 'with ensure_packages specified as an array [pkg1, pkg2]' do
let(:params) do
{
ensure_packages: ['pkg1', 'pkg2'],
}
end

it { is_expected.to contain_package('pkg1') }
it { is_expected.to contain_package('pkg2') }
end

context 'with ensure_packages specified as an array with duplicate package names [dupllicate, dupllicate, unique]' do
let(:params) { { ensure_packages: ['dupllicate', 'dupllicate', 'unique'] } }

it { is_expected.to contain_package('dupllicate') }
it { is_expected.to contain_package('unique') }
end

context 'with ensure_packages specifying an already declared package name' do
let(:params) { { ensure_packages: ['dupllicate', 'unique'] } }
let(:pre_condition) do
"ensure_packages('dupllicate')"
end

it { is_expected.to contain_package('dupllicate') }
it { is_expected.to contain_package('unique') }
end
end

0 comments on commit f1803d4

Please sign in to comment.