Skip to content

Commit

Permalink
add parameter $manage_nodejs_package
Browse files Browse the repository at this point in the history
Defaults to true. This allows for using this module without managing
the nodejs package. The use case for this is where you want to use the
npm package provider in this module, but otherwise have no need for
directly installing nodejs. This patch allows for expressing that use
case in your puppet code.
  • Loading branch information
kenyon committed Nov 1, 2020
1 parent b326a60 commit b059949
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 4 deletions.
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# == Class: nodejs: See README.md for documentation.
class nodejs (
$cmd_exe_path = $nodejs::params::cmd_exe_path,
Boolean $manage_nodejs_package = $nodejs::params::manage_nodejs_package,
Boolean $manage_package_repo = $nodejs::params::manage_package_repo,
$nodejs_debug_package_ensure = $nodejs::params::nodejs_debug_package_ensure,
Optional[String] $nodejs_debug_package_name = $nodejs::params::nodejs_debug_package_name,
Expand Down
10 changes: 6 additions & 4 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

# npm is a Gentoo USE flag
if $facts['os']['name'] == 'Gentoo' {
if $facts['os']['name'] == 'Gentoo' and $nodejs::manage_nodejs_package {
package_use { $nodejs::nodejs_package_name:
ensure => present,
target => 'nodejs-flags',
Expand All @@ -20,9 +20,11 @@
Package { provider => $nodejs::package_provider }

# nodejs
package { $nodejs::nodejs_package_name:
ensure => $nodejs::nodejs_package_ensure,
tag => 'nodesource_repo',
if $nodejs::manage_nodejs_package {
package { $nodejs::nodejs_package_name:
ensure => $nodejs::nodejs_package_ensure,
tag => 'nodesource_repo',
}
}

# nodejs-development
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class nodejs::params {
$manage_nodejs_package = true
$npmrc_auth = undef
$npmrc_config = undef
$nodejs_debug_package_ensure = 'absent'
Expand Down
235 changes: 235 additions & 0 deletions spec/classes/nodejs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@
}
end

context 'and manage_nodejs_package set to true' do
let :params do
default_params.merge!(manage_nodejs_package: true)
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
default_params.merge!(manage_nodejs_package: false)
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('nodejs')
end
end

context 'and repo_class set to ::nodejs::repo::nodesource' do
let :params do
default_params.merge!(repo_class: 'nodejs::repo::nodesource')
Expand Down Expand Up @@ -351,6 +371,26 @@
}
end

context 'and manage_nodejs_package set to true' do
let :params do
default_params.merge!(manage_nodejs_package: true)
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
default_params.merge!(manage_nodejs_package: false)
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('nodejs')
end
end

context 'and repo_class set to ::nodejs::repo::nodesource' do
let :params do
default_params.merge!(repo_class: 'nodejs::repo::nodesource')
Expand Down Expand Up @@ -686,6 +726,31 @@
end
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('nodejs')
end
end

# nodejs_package_ensure
context 'with nodejs_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -747,6 +812,31 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('nodejs')
end
end

# nodejs_package_ensure
context 'with nodejs_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -783,6 +873,31 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('www/node')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('www/node')
end
end

# nodejs_dev_package_ensure
context 'with nodejs_dev_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -869,6 +984,31 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('node')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('node')
end
end

# nodejs_package_ensure
context 'with nodejs_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -905,6 +1045,31 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('nodejs')
end
end

# nodejs_dev_package_ensure
context 'with nodejs_dev_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -1012,6 +1177,31 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('nodejs')
end
end

# nodejs_package_ensure
context 'with nodejs_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -1073,6 +1263,31 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('net-libs/nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('net-libs/nodejs')
end
end

# nodejs_package_ensure
context 'with nodejs_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -1139,6 +1354,26 @@
}
end

context 'and manage_nodejs_package set to true' do
let :params do
default_params.merge!(manage_nodejs_package: true)
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
default_params.merge!(manage_nodejs_package: false)
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('nodejs')
end
end

context 'and repo_class set to ::nodejs::repo::nodesource' do
let :params do
default_params.merge!(repo_class: 'nodejs::repo::nodesource')
Expand Down

0 comments on commit b059949

Please sign in to comment.