From 1251c08d6f35e9735f986730eb3b4a614f420b99 Mon Sep 17 00:00:00 2001 From: Kenyon Ralph Date: Sun, 1 Nov 2020 12:34:52 -0800 Subject: [PATCH] add parameter $manage_nodejs_package 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. --- README.md | 4 + manifests/init.pp | 1 + manifests/install.pp | 10 +- manifests/params.pp | 1 + spec/classes/nodejs_spec.rb | 235 ++++++++++++++++++++++++++++++++++++ 5 files changed, 247 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f44c5fdb..0cb7a6b2 100644 --- a/README.md +++ b/README.md @@ -380,6 +380,10 @@ applied before the local installation of npm packages using `nodejs::npm`. Path to cmd.exe on Windows. Defaults to C:\Windows\system32\cmd.exe. You may need to change this parameter for certain versions of Windows Server. +#### `manage_nodejs_package` + +Whether to manage the nodejs package. Defaults to `true`. + #### `manage_package_repo` Whether to manage an external repository and use it as the source of the diff --git a/manifests/init.pp b/manifests/init.pp index f8ce08a5..3adaf073 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, diff --git a/manifests/install.pp b/manifests/install.pp index f28d912f..943d5c3a 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -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', @@ -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 diff --git a/manifests/params.pp b/manifests/params.pp index 87f935f0..9ae8848e 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,4 +1,5 @@ class nodejs::params { + $manage_nodejs_package = true $npmrc_auth = undef $npmrc_config = undef $nodejs_debug_package_ensure = 'absent' diff --git a/spec/classes/nodejs_spec.rb b/spec/classes/nodejs_spec.rb index 32df68ed..f3c49a23 100644 --- a/spec/classes/nodejs_spec.rb +++ b/spec/classes/nodejs_spec.rb @@ -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') @@ -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') @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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')