From 0427379cee93a77e7001f4f6e2f7050ee98d4e08 Mon Sep 17 00:00:00 2001 From: juniorsysadmin Date: Tue, 28 Nov 2017 20:21:26 +1100 Subject: [PATCH] Remove EOL operating systems, Legacy facts. - Update the `repo_url_suffix` table in the README, dropping EOL operating systems and adding new ones - Drop explicit handling of Debian 6 and 7 (EOL) - Drop explicit handling of Ubuntu 10.04 and 12.04 (EOL) - Drop explicit handling of EOL Fedora versions - Drop explicit handling of RHEL5 (EOL) - Add explicit handling of Debian 9 - Replace most Legacy facts with Modern facts using the new facts hash syntax. This explicitly drops support for Facter versions less than 3, which are not supported under Puppet4/5 anyway. - Drop explicit support for Amazon Linux versions less than 2015.03. Amazon Linux is rolling distribution, and earlier versions did not have Facter 3 - Use the Modern system32 fact Also: - Remove the old Puppetlabs footer from the README. Reference CONTRIBUTING.md instead - Perform minor doc fixes - Use less granular error handling --- README.md | 34 +-- manifests/install.pp | 4 +- manifests/npm.pp | 4 +- manifests/params.pp | 98 +------- manifests/repo/nodesource.pp | 69 +----- spec/classes/nodejs_spec.rb | 385 ++++++-------------------------- spec/defines/nodejs_npm_spec.rb | 15 +- 7 files changed, 111 insertions(+), 498 deletions(-) diff --git a/README.md b/README.md index 1536a09a..41701ea2 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,6 @@ When a separate npm package exists (natively or via EPEL) the Node.js developmen package also needs to be installed as it is a dependency for npm. Install Node.js and npm using the native packages provided by the distribution: -(Only applicable for Ubuntu 12.04/14.04 and Fedora operating systems): ```puppet class { '::nodejs': @@ -470,13 +469,11 @@ the NodeSource URL structure - NodeSource might remove old versions (such as 0.10 and 0.12) or add new ones (such as 8.x) at any time. The following are ``repo_url_suffix`` values that reflect NodeSource versions -that were available on 2017-11-14: +that were available on 2017-11-29: -* Debian 7 (Wheezy) ```0.10``` ```0.12``` ```4.x``` ```5.x``` ```6.x``` * Debian 8 (Jessie) ```0.10``` ```0.12``` ```4.x``` ```5.x``` ```6.x``` ```7.x``` ```8.x``` ```9.x``` * Debian 9 (Stretch) ```4.x``` ```6.x``` ```7.x``` ```8.x``` ```9.x``` * Debian (Sid) ```0.10``` ```0.12``` ```4.x``` ```5.x``` ```6.x``` ```7.x``` ```8.x``` ```9.x``` -* Ubuntu 12.04 (Precise) ```0.10``` ```0.12``` ```4.x``` ```5.x``` ```6.x``` * Ubuntu 14.04 (Trusty) ```0.10``` ```0.12``` ```4.x``` ```5.x``` ```6.x``` ```7.x``` ```8.x``` ```9.x``` * Ubuntu 16.04 (Xenial) ```0.10``` ```0.12``` ```4.x``` ```5.x``` ```6.x``` ```7.x``` ```8.x``` ```9.x``` * Ubuntu 16.10 (Yakkety) ```0.12``` ```4.x``` ```6.x``` ```7.x``` ```8.x``` @@ -487,6 +484,7 @@ that were available on 2017-11-14: * Amazon Linux - See RHEL/CentOS 7 * Fedora 25 ```4.x``` ```6.x``` ```7.x``` ```8.x``` ```9.x``` * Fedora 26 ```6.x``` ```8.x``` ```9.x``` +* Fedora 27 ```8.x``` ```9.x``` #### `use_flags` @@ -497,34 +495,30 @@ The USE flags to use for the Node.js package on Gentoo systems. Defaults to This module has received limited testing on: -* CentOS/RHEL 5/6/7 -* Debian 7 -* Ubuntu 10.04/12.04/14.04 +* CentOS/RHEL 6/7 +* Debian 8 +* Ubuntu 14.04 The following platforms should also work, but have not been tested: * Amazon Linux * Archlinux * Darwin -* Debian 8 +* Debian 9 +* Fedora * FreeBSD * Gentoo * OpenBSD * OpenSuse/SLES * Windows -This module is not supported on Debian Squeeze. - ### Module dependencies This modules uses `puppetlabs-apt` for the management of the NodeSource repository. If using an operating system of the Debian-based family, you will need to ensure that `puppetlabs-apt` version 2.x or above is installed. -If using CentoOS/RHEL 5, you will need to ensure that the `stahnma-epel` -module is installed. - -If using CentoOS/RHEL 5/6/7 and you wish to install Node.js from EPEL rather +If using CentOS/RHEL 6/7 and you wish to install Node.js from EPEL rather than from the NodeSource repository, you will need to ensure `stahnma-epel` is installed and is applied before this module. @@ -539,14 +533,4 @@ wish to use this functionality, Git needs to be installed and be in the ## Development -Puppet Labs modules on the Puppet Forge are open projects, and community -contributions are essential for keeping them great. We can’t access the huge -number of platforms and myriad of hardware, software, and deployment -configurations that Puppet is intended to serve. - -We want to keep it as easy as possible to contribute changes so that our -modules work in your environment. There are a few guidelines that we need -contributors to follow so that we can have a chance of keeping on top of -things. - -Read the complete module [contribution guide](https://docs.puppetlabs.com/forge/contributing.html) +See [CONTRIBUTING](CONTRIBUTING.md) diff --git a/manifests/install.pp b/manifests/install.pp index d363cba2..4169e9eb 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -9,7 +9,7 @@ } # npm is a Gentoo USE flag - if $::operatingsystem == 'Gentoo' { + if $facts['os']['name'] == 'Gentoo' { package_use { $nodejs::nodejs_package_name: ensure => present, target => 'nodejs-flags', @@ -41,7 +41,7 @@ } # Replicates the nodejs-legacy package functionality - if ($::osfamily == 'Debian' and $nodejs::legacy_debian_symlinks) { + if ($facts['os']['family'] == 'Debian' and $nodejs::legacy_debian_symlinks) { file { '/usr/bin/node': ensure => 'link', target => '/usr/bin/nodejs', diff --git a/manifests/npm.pp b/manifests/npm.pp index c3564e2b..8b4924a3 100644 --- a/manifests/npm.pp +++ b/manifests/npm.pp @@ -33,12 +33,12 @@ $package_string = "${package}@${ensure}" } - $grep_command = $::osfamily ? { + $grep_command = $facts['os']['family'] ? { 'Windows' => "${cmd_exe_path} /c findstr /l", default => 'grep', } - $dirsep = $::osfamily ? { + $dirsep = $facts['os']['family'] ? { 'Windows' => "\\", default => '/' } diff --git a/manifests/params.pp b/manifests/params.pp index e3f76a08..25800568 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -13,19 +13,14 @@ $repo_url_suffix = '0.10' $use_flags = ['npm', 'snapshot'] - # The full path to cmd.exe is required on Windows. The system32 fact is only - # available from Facter 2.3 - $cmd_exe_path = $::osfamily ? { - 'Windows' => 'C:\Windows\system32\cmd.exe', + $cmd_exe_path = $facts['os']['family'] ? { + 'Windows' => "${facts['os']['windows']['system32']}\\cmd.exe", default => undef, } - case $::osfamily { + case $facts['os']['family'] { 'Debian': { - if $::operatingsystemrelease =~ /^6\.(\d+)/ { - fail("The ${module_name} module is not supported on Debian Squeeze.") - } - elsif $::operatingsystemrelease =~ /^[78]\.(\d+)/ { + if $facts['os']['release']['major'] =~ /^[89]$/ { $legacy_debian_symlinks = false $manage_package_repo = true $nodejs_debug_package_name = 'nodejs-dbg' @@ -37,43 +32,7 @@ $npm_path = '/usr/bin/npm' $repo_class = '::nodejs::repo::nodesource' } - elsif $::operatingsystemrelease =~ /^10.04$/ { - $legacy_debian_symlinks = false - $manage_package_repo = true - $nodejs_debug_package_name = 'nodejs-dbg' - $nodejs_dev_package_name = undef - $nodejs_dev_package_ensure = 'absent' - $nodejs_package_name = 'nodejs' - $npm_package_ensure = 'absent' - $npm_package_name = false - $npm_path = '/usr/bin/npm' - $repo_class = '::nodejs::repo::nodesource' - } - elsif $::operatingsystemrelease =~ /^12.04$/ { - $legacy_debian_symlinks = false - $manage_package_repo = true - $nodejs_debug_package_name = 'nodejs-dbg' - $nodejs_dev_package_name = 'nodejs-dev' - $nodejs_dev_package_ensure = 'absent' - $nodejs_package_name = 'nodejs' - $npm_package_ensure = 'absent' - $npm_package_name = 'npm' - $npm_path = '/usr/bin/npm' - $repo_class = '::nodejs::repo::nodesource' - } - elsif $::operatingsystemrelease =~ /^14.04$/ { - $legacy_debian_symlinks = false - $manage_package_repo = true - $nodejs_debug_package_name = 'nodejs-dbg' - $nodejs_dev_package_name = 'nodejs-dev' - $nodejs_dev_package_ensure = 'absent' - $nodejs_package_name = 'nodejs' - $npm_package_ensure = 'absent' - $npm_package_name = 'npm' - $npm_path = '/usr/bin/npm' - $repo_class = '::nodejs::repo::nodesource' - } - elsif $::operatingsystemrelease =~ /^16.04$/ { + elsif $facts['os']['release']['full'] =~ /^1[46]\.04$/ { $legacy_debian_symlinks = false $manage_package_repo = true $nodejs_debug_package_name = 'nodejs-dbg' @@ -86,7 +45,7 @@ $repo_class = '::nodejs::repo::nodesource' } else { - warning("The ${module_name} module might not work on ${::operatingsystem} ${::operatingsystemrelease}. Sensible defaults will be attempted.") + warning("The ${module_name} module might not work on ${facts['os']['name']} ${facts['os']['release']['full']}. Sensible defaults will be attempted.") $legacy_debian_symlinks = false $manage_package_repo = true $nodejs_debug_package_name = 'nodejs-dbg' @@ -102,7 +61,7 @@ 'RedHat': { $legacy_debian_symlinks = false - if $::operatingsystemrelease =~ /^[5-7]\.(\d+)/ { + if $facts['os']['release']['major'] =~ /^[67]$/ { $manage_package_repo = true $nodejs_debug_package_name = 'nodejs-debuginfo' $nodejs_dev_package_name = 'nodejs-devel' @@ -113,7 +72,7 @@ $npm_path = '/usr/bin/npm' $repo_class = '::nodejs::repo::nodesource' } - elsif ($::operatingsystem == 'Fedora') and (versioncmp($::operatingsystemrelease, '18') > 0) { + elsif $facts['os']['name'] == 'Fedora' { $manage_package_repo = true $nodejs_debug_package_name = 'nodejs-debuginfo' $nodejs_dev_package_name = 'nodejs-devel' @@ -124,7 +83,7 @@ $npm_path = '/usr/bin/npm' $repo_class = '::nodejs::repo::nodesource' } - elsif ($::operatingsystem == 'Amazon') { + elsif ($facts['os']['name'] == 'Amazon') { $manage_package_repo = true $nodejs_debug_package_name = 'nodejs-debuginfo' $nodejs_dev_package_name = 'nodejs-devel' @@ -213,7 +172,6 @@ $repo_class = undef Package { provider => 'chocolatey' } } - # Gentoo was added as its own $::osfamily in Facter 1.7.0 'Gentoo': { $legacy_debian_symlinks = false $manage_package_repo = false @@ -226,44 +184,8 @@ $npm_path = '/usr/bin/npm' $repo_class = undef } - 'Linux': { - # Before Facter 1.7.0 Gentoo did not have its own $::osfamily - case $::operatingsystem { - 'Gentoo': { - $legacy_debian_symlinks = false - $manage_package_repo = false - $nodejs_debug_package_name = undef - $nodejs_dev_package_name = undef - $nodejs_dev_package_ensure = 'absent' - $nodejs_package_name = 'net-libs/nodejs' - $npm_package_ensure = 'absent' - $npm_package_name = false - $npm_path = '/usr/bin/npm' - $repo_class = undef - } - 'Amazon': { - # this is here only for historical reasons: - # old facter and Amazon Linux versions will run into this code path - $legacy_debian_symlinks = false - $manage_package_repo = true - $nodejs_debug_package_name = 'nodejs-debuginfo' - $nodejs_dev_package_name = 'nodejs-devel' - $nodejs_dev_package_ensure = 'absent' - $nodejs_package_name = 'nodejs' - $npm_package_ensure = 'absent' - $npm_package_name = 'npm' - $npm_path = '/usr/bin/npm' - $repo_class = '::nodejs::repo::nodesource' - } - - default: { - fail("The ${module_name} module is not supported on an ${::operatingsystem} distribution.") - } - } - } - default: { - fail("The ${module_name} module is not supported on a ${::osfamily} based system.") + fail("The ${module_name} module is not supported on a ${facts['os']['name']} distribution.") } } } diff --git a/manifests/repo/nodesource.pp b/manifests/repo/nodesource.pp index a380faf5..d77dd9b0 100644 --- a/manifests/repo/nodesource.pp +++ b/manifests/repo/nodesource.pp @@ -9,32 +9,21 @@ $proxy_username = $nodejs::repo_proxy_username $url_suffix = $nodejs::repo_url_suffix - case $::osfamily { + case $facts['os']['family'] { 'RedHat': { - if $::operatingsystemrelease =~ /^5\.(\d+)/ { - include ::epel - $dist_version = '5' - $name_string = 'Enterprise Linux 5' - } - - elsif $::operatingsystemrelease =~ /^6\.(\d+)/ { - $dist_version = '6' - $name_string = 'Enterprise Linux 6' - } - - elsif $::operatingsystemrelease =~ /^7\.(\d+)/ { - $dist_version = '7' - $name_string = 'Enterprise Linux 7' + if $facts['os']['release']['major'] =~ /^[67]$/ { + $dist_version = $facts['os']['release']['major'] + $name_string = "Enterprise Linux ${dist_version}" } # Fedora - elsif $::operatingsystem == 'Fedora' { - $dist_version = $::operatingsystemrelease - $name_string = "Fedora Core ${::operatingsystemrelease}" + elsif $facts['os']['name'] == 'Fedora' { + $dist_version = $facts['os']['release']['full'] + $name_string = "Fedora Core ${facts['os']['release']['full']}" } # newer Amazon Linux releases - elsif ($::operatingsystem == 'Amazon') { + elsif ($facts['os']['name'] == 'Amazon') { $dist_version = '7' $name_string = 'Enterprise Linux 7' } @@ -43,7 +32,7 @@ fail("Could not determine NodeSource repository URL for operatingsystem: ${::operatingsystem} operatingsystemrelease: ${::operatingsystemrelease}.") } - $dist_type = $::operatingsystem ? { + $dist_type = $facts['os']['name'] ? { 'Fedora' => 'fc', default => 'el', } @@ -59,44 +48,6 @@ class { '::nodejs::repo::nodesource::yum': } contain '::nodejs::repo::nodesource::yum' - if $::operatingsystemrelease =~ /^5\.(\d+)/ { - # On EL 5, EPEL needs to be applied first - Class['::epel'] -> Class['::nodejs::repo::nodesource::yum'] - } - - } - 'Linux': { - if $::operatingsystem == 'Amazon' { - - # Recent Amazon Linux instances - if $::operatingsystemrelease =~ /^201[4-9]\./ { - $dist_type = 'el' - $dist_version = '7' - $name_string = 'Enterprise Linux 7' - } - else { - $dist_type = 'el' - $dist_version = '6' - $name_string = 'Enterprise Linux 6' - } - - # nodesource repo - $descr = "Node.js Packages for ${name_string} - \$basearch" - $baseurl = "https://rpm.nodesource.com/pub_${url_suffix}/${dist_type}/${dist_version}/\$basearch" - - # nodesource-source repo - $source_descr = "Node.js for ${name_string} - \$basearch - Source" - $source_baseurl = "https://rpm.nodesource.com/pub_${url_suffix}/${dist_type}/${dist_version}/SRPMS" - - class { '::nodejs::repo::nodesource::yum': } - contain '::nodejs::repo::nodesource::yum' - } - - else { - if ($ensure == 'present') { - fail("Unsupported managed NodeSource repository for operatingsystem: ${::operatingsystem}.") - } - } } 'Debian': { class { '::nodejs::repo::nodesource::apt': } @@ -104,7 +55,7 @@ } default: { if ($ensure == 'present') { - fail("Unsupported managed NodeSource repository for osfamily: ${::osfamily}, operatingsystem: ${::operatingsystem}.") + fail("Unsupported managed NodeSource repository for osfamily: ${facts['os']['family']}, operatingsystem: ${facts['os']['name']}.") } } } diff --git a/spec/classes/nodejs_spec.rb b/spec/classes/nodejs_spec.rb index e887a78e..1c228c1f 100644 --- a/spec/classes/nodejs_spec.rb +++ b/spec/classes/nodejs_spec.rb @@ -2,13 +2,19 @@ describe 'nodejs', type: :class do on_supported_os.each do |os, facts| - next unless facts[:osfamily] == 'Debian' + next unless facts[:os]['family'] == 'Debian' context "on #{os} " do let :facts do facts end + is_supported_debian_version = if facts[:os]['family'] == 'Debian' && %w[8 9].include?(facts[:os]['release']['major']) + true + else + false + end + it 'the file resource root_npmrc should be in the catalog' do is_expected.to contain_file('root_npmrc').with( 'ensure' => 'file', @@ -208,10 +214,8 @@ } end - if facts[:osfamily] == 'Debian' && ( - facts[:operatingsystemrelease] == '10.04' || - %w[7 8].include?(facts[:operatingsystemmajrelease]) - ) + if is_supported_debian_version + it 'the nodejs development package resource should not be present' do is_expected.not_to contain_package('nodejs-dev') end @@ -229,10 +233,8 @@ } end - if facts[:osfamily] == 'Debian' && ( - facts[:operatingsystemrelease] == '10.04' || - %w[7 8].include?(facts[:operatingsystemmajrelease]) - ) + if is_supported_debian_version + it 'the nodejs development package resource should not be present' do is_expected.not_to contain_package('nodejs-dev') end @@ -276,10 +278,8 @@ } end - if facts[:osfamily] == 'Debian' && ( - facts[:operatingsystemrelease] == '10.04' || - %w[7 8].include?(facts[:operatingsystemmajrelease]) - ) + if is_supported_debian_version + it 'the npm package resource should not be present' do is_expected.not_to contain_package('npm') end @@ -297,10 +297,8 @@ } end - if facts[:osfamily] == 'Debian' && ( - facts[:operatingsystemrelease] == '10.04' || - %w[7 8].include?(facts[:operatingsystemmajrelease]) - ) + if is_supported_debian_version + it 'the npm package resource should not be present' do is_expected.not_to contain_package('npm') end @@ -326,25 +324,11 @@ end end - context 'when run on an unsupported version of Fedora (18)' do - let :facts do - { - osfamily: 'RedHat', - operatingsystem: 'Fedora', - operatingsystemrelease: '18' - } - end - - it do - expect { catalogue }.to raise_error(Puppet::Error, %r{The nodejs module is not supported on Fedora 18.}) - end - end - - ['5.0', '6.0', '7.0', '25'].each do |operatingsystemrelease| + ['6.0', '7.0', '27'].each do |operatingsystemrelease| osversions = operatingsystemrelease.split('.') operatingsystemmajrelease = osversions[0] - if operatingsystemrelease =~ %r{^[5-7]\.(\d+)} + if operatingsystemrelease =~ %r{^[6-7]\.(\d+)} operatingsystem = 'CentOS' dist_type = 'el' repo_baseurl = "https://rpm.nodesource.com/pub_0.10/#{dist_type}/#{operatingsystemmajrelease}/\$basearch" @@ -363,10 +347,14 @@ context "when run on #{operatingsystem} release #{operatingsystemrelease}" do let :facts do { - operatingsystem: operatingsystem, - operatingsystemmajrelease: operatingsystemmajrelease, - operatingsystemrelease: operatingsystemrelease, - osfamily: 'RedHat' + 'os' => { + 'family' => 'RedHat', + 'name' => operatingsystem, + 'release' => { + 'major' => operatingsystemmajrelease, + 'full' => operatingsystemrelease + } + } } end @@ -656,8 +644,10 @@ context 'when running on Suse' do let :facts do { - osfamily: 'Suse', - operatingsystem: 'SLES' + 'os' => { + 'family' => 'Suse', + 'name' => 'SLES' + } } end @@ -765,8 +755,10 @@ context 'when running on Archlinux' do let :facts do { - osfamily: 'Archlinux', - operatingsystem: 'Archlinux' + 'os' => { + 'family' => 'Archlinux', + 'name' => 'Archlinux' + } } end @@ -799,8 +791,10 @@ context 'when running on FreeBSD' do let :facts do { - osfamily: 'FreeBSD', - operatingsystem: 'FreeBSD' + 'os' => { + 'family' => 'FreeBSD', + 'name' => 'FreeBSD' + } } end @@ -883,8 +877,10 @@ context 'when running on OpenBSD' do let :facts do { - osfamily: 'OpenBSD', - operatingsystem: 'OpenBSD' + 'os' => { + 'family' => 'OpenBSD', + 'name' => 'OpenBSD' + } } end @@ -917,8 +913,10 @@ context 'when running on Darwin' do let :facts do { - osfamily: 'Darwin', - operatingsystem: 'Darwin' + 'os' => { + 'family' => 'Darwin', + 'name' => 'Darwin' + } } end @@ -1001,8 +999,13 @@ context 'when running on Windows' do let :facts do { - osfamily: 'Windows', - operatingsystem: 'Windows' + 'os' => { + 'family' => 'Windows', + 'name' => 'Windows', + 'windows' => { + 'system32' => 'C:\Windows\system32' + } + } } end @@ -1059,7 +1062,12 @@ context 'when running on Gentoo' do let :facts do - { osfamily: 'Linux', operatingsystem: 'Gentoo' } + { + 'os' => { + 'family' => 'Gentoo', + 'name' => 'Gentoo' + } + } end # nodejs_package_ensure @@ -1100,277 +1108,18 @@ end end - context 'when running on Amazon Linux 2014.09' do - let :facts do - { - osfamily: 'Linux', - operatingsystem: 'Amazon', - operatingsystemrelease: '2014.09' - } - end - - repo_baseurl = 'https://rpm.nodesource.com/pub_0.10/el/7/$basearch' - repo_source_baseurl = 'https://rpm.nodesource.com/pub_0.10/el/7/SRPMS' - repo_descr = 'Node.js Packages for Enterprise Linux 7 - $basearch' - repo_source_descr = 'Node.js for Enterprise Linux 7 - $basearch - Source' - - # manage_package_repo - context 'with manage_package_repo set to true' do - let :default_params do - { - manage_package_repo: true - } - end - - context 'and repo_class set to ::nodejs::repo::nodesource' do - let :params do - default_params.merge!(repo_class: 'nodejs::repo::nodesource') - end - - it '::nodejs::repo::nodesource should be in the catalog' do - is_expected.to contain_class('nodejs::repo::nodesource') - end - - it '::nodejs::repo::nodesource::yum should be in the catalog' do - is_expected.to contain_class('nodejs::repo::nodesource::yum') - end - - it 'the nodesource and nodesource-source repos should contain the right description and baseurl' do - is_expected.to contain_yumrepo('nodesource').with('baseurl' => repo_baseurl, - 'descr' => repo_descr) - - is_expected.to contain_yumrepo('nodesource-source').with('baseurl' => repo_source_baseurl, - 'descr' => repo_source_descr) - end - end - - context 'and repo_enable_src set to true' do - let :params do - default_params.merge!(repo_enable_src: true) - end - - it 'the yumrepo resource nodesource-source should contain enabled = 1' do - is_expected.to contain_yumrepo('nodesource-source').with('enabled' => '1') - end - end - - context 'and repo_enable_src set to false' do - let :params do - default_params.merge!(repo_enable_src: false) - end - - it 'the yumrepo resource should contain enabled = 0' do - is_expected.to contain_yumrepo('nodesource-source').with('enabled' => '0') - end - end - - context 'and repo_ensure set to present' do - let :params do - default_params.merge!(repo_ensure: 'present') - end - - it 'the nodesource yum repo files should exist' do - is_expected.to contain_yumrepo('nodesource') - is_expected.to contain_yumrepo('nodesource-source') - end - end - - context 'and repo_ensure set to absent' do - let :params do - default_params.merge!(repo_ensure: 'absent') - end - - it 'the nodesource yum repo files should not exist' do - is_expected.to contain_yumrepo('nodesource').with('enabled' => 'absent') - is_expected.to contain_yumrepo('nodesource-source').with('enabled' => 'absent') - end - end - - context 'and repo_proxy set to absent' do - let :params do - default_params.merge!(repo_proxy: 'absent') - end - - it 'the yumrepo resource should contain proxy = absent' do - is_expected.to contain_yumrepo('nodesource').with('proxy' => 'absent') - is_expected.to contain_yumrepo('nodesource-source').with('proxy' => 'absent') - end - end - - context 'and repo_proxy set to http://proxy.localdomain.com' do - let :params do - default_params.merge!(repo_proxy: 'http://proxy.localdomain.com') - end - - it 'the yumrepo resource should contain proxy = http://proxy.localdomain.com' do - is_expected.to contain_yumrepo('nodesource').with('proxy' => 'http://proxy.localdomain.com') - is_expected.to contain_yumrepo('nodesource-source').with('proxy' => 'http://proxy.localdomain.com') - end - end - - context 'and repo_proxy_password set to absent' do - let :params do - default_params.merge!(repo_proxy_password: 'absent') - end - - it 'the yumrepo resource should contain proxy_password = absent' do - is_expected.to contain_yumrepo('nodesource').with('proxy_password' => 'absent') - is_expected.to contain_yumrepo('nodesource-source').with('proxy_password' => 'absent') - end - end - - context 'and repo_proxy_password set to password' do - let :params do - default_params.merge!(repo_proxy_password: 'password') - end - - it 'the yumrepo resource should contain proxy_password = password' do - is_expected.to contain_yumrepo('nodesource').with('proxy_password' => 'password') - is_expected.to contain_yumrepo('nodesource-source').with('proxy_password' => 'password') - end - end - - context 'and repo_proxy_username set to absent' do - let :params do - default_params.merge!(repo_proxy_username: 'absent') - end - - it 'the yumrepo resource should contain proxy_username = absent' do - is_expected.to contain_yumrepo('nodesource').with('proxy_username' => 'absent') - is_expected.to contain_yumrepo('nodesource-source').with('proxy_username' => 'absent') - end - end - - context 'and repo_proxy_username set to proxyuser' do - let :params do - default_params.merge!(repo_proxy_username: 'proxyuser') - end - - it 'the yumrepo resource should contain proxy_username = proxyuser' do - is_expected.to contain_yumrepo('nodesource').with('proxy_username' => 'proxyuser') - is_expected.to contain_yumrepo('nodesource-source').with('proxy_username' => 'proxyuser') - end - end - end - - context 'with manage_package_repo set to false' do - let :params do - { - manage_package_repo: false - } - end - - it '::nodejs::repo::nodesource should not be in the catalog' do - is_expected.not_to contain_class('::nodejs::repo::nodesource') - end - end - - # nodejs_debug_package_ensure - context 'with nodejs_debug_package_ensure set to present' do - let :params do - { - nodejs_debug_package_ensure: 'present' - } - end - - it 'the nodejs package with debugging symbols should be installed' do - is_expected.to contain_package('nodejs-debuginfo').with('ensure' => 'present') - end - end - - context 'with nodejs_debug_package_ensure set to absent' do - let :params do - { - nodejs_debug_package_ensure: 'absent' - } - end - - it 'the nodejs package with debugging symbols should not be present' do - is_expected.to contain_package('nodejs-debuginfo').with('ensure' => 'absent') - end - end - - # nodejs_dev_package_ensure - context 'with nodejs_dev_package_ensure set to present' do - let :params do - { - nodejs_dev_package_ensure: 'present' - } - end - - it 'the nodejs development package should be installed' do - is_expected.to contain_package('nodejs-devel').with('ensure' => 'present') - end - end - - context 'with nodejs_dev_package_ensure set to absent' do - let :params do - { - nodejs_dev_package_ensure: 'absent' - } - end - - it 'the nodejs development package should not be present' do - is_expected.to contain_package('nodejs-devel').with('ensure' => 'absent') - end - end - - # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do - let :params do - { - nodejs_package_ensure: 'present' - } - end - - it 'the nodejs package should be present' do - is_expected.to contain_package('nodejs').with('ensure' => 'present') - end - end - - context 'with nodejs_package_ensure set to absent' do - let :params do - { - nodejs_package_ensure: 'absent' - } - end - - it 'the nodejs package should be absent' do - is_expected.to contain_package('nodejs').with('ensure' => 'absent') - end - end - - # npm_package_ensure - context 'with npm_package_ensure set to present' do - let :params do - { - npm_package_ensure: 'present' - } - end - - it 'the npm package should be present' do - is_expected.to contain_package('npm').with('ensure' => 'present') - end - end - - context 'with npm_package_ensure set to absent' do - let :params do - { - npm_package_ensure: 'absent' - } - end - - it 'the npm package should be absent' do - is_expected.to contain_package('npm').with('ensure' => 'absent') - end - end - end context 'when running on Amazon Linux 2015.03' do let :facts do { - osfamily: 'RedHat', - operatingsystem: 'Amazon', - operatingsystemrelease: '2015.03' + 'os' => { + 'family' => 'RedHat', + 'name' => 'Amazon', + 'release' => { + 'full' => '2015.03', + 'major' => '2015', + 'minor' => '03' + } + } } end diff --git a/spec/defines/nodejs_npm_spec.rb b/spec/defines/nodejs_npm_spec.rb index cdbb41d3..5a8b4559 100644 --- a/spec/defines/nodejs_npm_spec.rb +++ b/spec/defines/nodejs_npm_spec.rb @@ -403,8 +403,10 @@ context 'when run on Darwin' do let :facts do { - operatingsystem: 'Darwin', - osfamily: 'Darwin' + 'os' => { + 'family' => 'Darwin', + 'name' => 'Darwin' + } } end @@ -433,8 +435,13 @@ context 'when run on Windows' do let :facts do { - operatingsystem: 'Windows', - osfamily: 'Windows' + 'os' => { + 'family' => 'Windows', + 'name' => 'Windows', + 'windows' => { + 'system32' => 'C:\Windows\system32' + } + } } end