diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 048d2b55..6aaa603f 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -124,7 +124,7 @@ If you have Ruby 2.x or want a specific version of Puppet, you must set an environment variable such as: ```sh -export PUPPET_VERSION="~> 5.5.6" +export PUPPET_GEM_VERSION="~> 6.1.0" ``` You can install all needed gems for spec tests into the modules directory by @@ -232,19 +232,21 @@ simple tests against it after applying the module. You can run this with: ```sh -BEAKER_setfile=debian10-x64 bundle exec rake beaker +BEAKER_PUPPET_COLLECTION=puppet7 BEAKER_setfile=debian11-64 bundle exec rake beaker ``` -You can replace the string `debian10` with any common operating system. +You can replace the string `debian11` with any common operating system. The following strings are known to work: -* ubuntu1604 -* ubuntu1804 * ubuntu2004 -* debian9 -* debian10 +* ubuntu2204 +* debian11 * centos7 * centos8 +* centos9 +* almalinux8 +* almalinux9 +* fedora36 For more information and tips & tricks, see [voxpupuli-acceptance's documentation](https://github.com/voxpupuli/voxpupuli-acceptance#running-tests). diff --git a/.github/SECURITY.md b/.github/SECURITY.md deleted file mode 100644 index cacadf22..00000000 --- a/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Vox Pupuli Security Policy - -Our vulnerabilities reporting process is at https://voxpupuli.org/security/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d08d05e8..8a077911 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,84 +7,12 @@ name: CI on: pull_request concurrency: - group: ${{ github.head_ref }} + group: ${{ github.ref_name }} cancel-in-progress: true jobs: - setup_matrix: - name: 'Setup Test Matrix' - runs-on: ubuntu-latest - timeout-minutes: 40 - outputs: - puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} - github_action_test_matrix: ${{ steps.get-outputs.outputs.github_action_test_matrix }} - env: - BUNDLE_WITHOUT: development:system_tests:release - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.0' - bundler-cache: true - - name: Run static validations - run: bundle exec rake validate lint check - - name: Run rake rubocop - run: bundle exec rake rubocop - - name: Setup Test Matrix - id: get-outputs - run: bundle exec metadata2gha --use-fqdn --pidfile-workaround false - - unit: - needs: setup_matrix - runs-on: ubuntu-latest - timeout-minutes: 40 - strategy: - fail-fast: false - matrix: - include: ${{fromJson(needs.setup_matrix.outputs.puppet_unit_test_matrix)}} - env: - BUNDLE_WITHOUT: development:system_tests:release - PUPPET_VERSION: "~> ${{ matrix.puppet }}.0" - name: Puppet ${{ matrix.puppet }} (Ruby ${{ matrix.ruby }}) - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run tests - run: bundle exec rake parallel_spec - - acceptance: - needs: setup_matrix - runs-on: ubuntu-latest - env: - BUNDLE_WITHOUT: development:test:release - strategy: - fail-fast: false - matrix: - include: ${{fromJson(needs.setup_matrix.outputs.github_action_test_matrix)}} - name: ${{ matrix.puppet.name }} - ${{ matrix.setfile.name }} - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.0' - bundler-cache: true - - name: Run tests - run: bundle exec rake beaker - env: - BEAKER_PUPPET_COLLECTION: ${{ matrix.puppet.collection }} - BEAKER_setfile: ${{ matrix.setfile.value }} - - tests: - needs: - - unit - - acceptance - runs-on: ubuntu-latest - name: Test suite - steps: - - run: echo Test suite completed + puppet: + name: Puppet + uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v1 + with: + pidfile_workaround: 'false' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 664ba694..15f17213 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,26 +9,14 @@ on: tags: - '*' -env: - BUNDLE_WITHOUT: development:test:system_tests - jobs: - deploy: - name: 'deploy to forge' - runs-on: ubuntu-latest - if: github.repository_owner == 'voxpupuli' - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '2.7' - bundler-cache: true - - name: Build and Deploy - env: - # Configure secrets here: - # https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets - BLACKSMITH_FORGE_USERNAME: '${{ secrets.PUPPET_FORGE_USERNAME }}' - BLACKSMITH_FORGE_API_KEY: '${{ secrets.PUPPET_FORGE_API_KEY }}' - run: bundle exec rake module:push + release: + name: Release + uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v1 + with: + allowed_owner: 'voxpupuli' + secrets: + # Configure secrets here: + # https://docs.github.com/en/actions/security-guides/encrypted-secrets + username: ${{ secrets.PUPPET_FORGE_USERNAME }} + api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} diff --git a/.gitignore b/.gitignore index 9b95224c..84fd904c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,23 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -pkg/ -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/fixtures/manifests/ -spec/fixtures/modules/ -.vagrant/ -.bundle/ -.ruby-version -coverage/ -log/ -.idea/ -.dependencies/ -.librarian/ -Puppetfile.lock +/pkg/ +/Gemfile.lock +/Gemfile.local +/vendor/ +/.vendor/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/.vagrant/ +/.bundle/ +/.ruby-version +/coverage/ +/log/ +/.idea/ +/.dependencies/ +/.librarian/ +/Puppetfile.lock *.iml .*.sw? -.yardoc/ -Guardfile +/.yardoc/ +/Guardfile diff --git a/.msync.yml b/.msync.yml index 43966c2f..dd3e9572 100644 --- a/.msync.yml +++ b/.msync.yml @@ -2,4 +2,4 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -modulesync_config_version: '4.2.0' +modulesync_config_version: '7.0.0' diff --git a/.pmtignore b/.pmtignore index 65f50514..58a04088 100644 --- a/.pmtignore +++ b/.pmtignore @@ -1,37 +1,37 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -docs/ -pkg/ -Gemfile -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/ -Rakefile -.vagrant/ -.bundle/ -.ruby-version -coverage/ -log/ -.idea/ -.dependencies/ -.github/ -.librarian/ -Puppetfile.lock +/docs/ +/pkg/ +/Gemfile +/Gemfile.lock +/Gemfile.local +/vendor/ +/.vendor/ +/spec/ +/Rakefile +/.vagrant/ +/.bundle/ +/.ruby-version +/coverage/ +/log/ +/.idea/ +/.dependencies/ +/.github/ +/.librarian/ +/Puppetfile.lock *.iml -.editorconfig -.fixtures.yml -.gitignore -.msync.yml -.overcommit.yml -.pmtignore -.rspec -.rspec_parallel -.rubocop.yml -.sync.yml +/.editorconfig +/.fixtures.yml +/.gitignore +/.msync.yml +/.overcommit.yml +/.pmtignore +/.rspec +/.rspec_parallel +/.rubocop.yml +/.sync.yml .*.sw? -.yardoc/ -.yardopts -Dockerfile +/.yardoc/ +/.yardopts +/Dockerfile diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 00000000..dd8272c7 --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,3 @@ +--fail-on-warnings +--no-parameter_documentation-check +--no-parameter_types-check diff --git a/.sync.yml b/.sync.yml index e295ca9c..4cf442c8 100644 --- a/.sync.yml +++ b/.sync.yml @@ -2,4 +2,4 @@ spec/spec_helper.rb: mock_with: ':mocha' spec/spec_helper_acceptance.rb: - unmanaged: false + unmanaged: true diff --git a/Dockerfile b/Dockerfile index e3cf307f..8dd82d63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /opt/puppet # https://github.com/puppetlabs/puppet/blob/06ad255754a38f22fb3a22c7c4f1e2ce453d01cb/lib/puppet/provider/service/runit.rb#L39 RUN mkdir -p /etc/sv -ARG PUPPET_VERSION="~> 6.0" +ARG PUPPET_GEM_VERSION="~> 6.0" ARG PARALLEL_TEST_PROCESSORS=4 # Cache gems diff --git a/Gemfile b/Gemfile index a39114ce..db21d3b5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,13 +1,13 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -source ENV['GEM_SOURCE'] || "https://rubygems.org" +source ENV['GEM_SOURCE'] || 'https://rubygems.org' group :test do - gem 'voxpupuli-test', '~> 2.5', :require => false + gem 'voxpupuli-test', '~> 7.0', :require => false gem 'coveralls', :require => false gem 'simplecov-console', :require => false - gem 'puppet_metadata', '~> 1.0', :require => false + gem 'puppet_metadata', '~> 3.0', :require => false end group :development do @@ -16,19 +16,19 @@ group :development do end group :system_tests do - gem 'voxpupuli-acceptance', '~> 1.0', :require => false + gem 'voxpupuli-acceptance', '~> 2.0', :require => false end group :release do - gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5' - gem 'voxpupuli-release', '>= 1.0.2', :require => false - gem 'puppet-strings', '>= 2.2', :require => false + gem 'github_changelog_generator', '>= 1.16.1', :require => false + gem 'voxpupuli-release', '~> 3.0', :require => false + gem 'faraday-retry', '~> 2.1', :require => false end gem 'rake', :require => false gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] -puppetversion = ENV['PUPPET_VERSION'] || '>= 6.0' +puppetversion = ENV['PUPPET_GEM_VERSION'] || '~> 7.24' gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/README.md b/README.md index c449ecf2..b1270885 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,13 @@ [![Puppet Forge - endorsement](https://img.shields.io/puppetforge/e/puppet/nodejs.svg)](https://forge.puppetlabs.com/puppet/nodejs) [![Puppet Forge - scores](https://img.shields.io/puppetforge/f/puppet/nodejs.svg)](https://forge.puppetlabs.com/puppet/nodejs) -#### Table of Contents +## Table of Contents 1. [Overview](#overview) 1. [Setup - The basics of getting started with nodejs](#setup) * [Beginning with nodejs - Installation](#beginning-with-nodejs) 1. [Usage](#usage) 1. [Npm packages](#npm-packages) -1. [Parameters](#parameters) 1. [Limitations - OS compatibility, etc.](#limitations) * [Module dependencies](#module-dependencies) 1. [Development](#development) @@ -74,8 +73,8 @@ Install Node.js and npm using the native packages provided by the distribution: ```puppet class { '::nodejs': manage_package_repo => false, - nodejs_dev_package_ensure => 'present', - npm_package_ensure => 'present', + nodejs_dev_package_ensure => installed, + npm_package_ensure => installed, } ``` @@ -83,15 +82,15 @@ Install Node.js and npm using the packages from EPEL: ```puppet class { '::nodejs': - nodejs_dev_package_ensure => 'present', - npm_package_ensure => 'present', - repo_class => '::epel', + nodejs_dev_package_ensure => installed, + npm_package_ensure => installed, + repo_class => 'epel', } ``` ### Upgrades -The parameter `nodejs_package_ensure` defaults to `present`. Changing the +The parameter `nodejs_package_ensure` defaults to `installed`. Changing the `repo_url_suffix` will not result in a new version being installed. Changing the `nodejs_package_ensure` parameter should provide the desired effect. @@ -100,9 +99,9 @@ For example: ```puppet # Upgrade from nodejs 5.x to 6.x class { 'nodejs': - repo_url_suffix => '6.x', - nodejs_package_ensure => '6.12.2', - } + repo_url_suffix => '6.x', + nodejs_package_ensure => '6.12.2', +} ``` ### Forcing the installation of NodeSource packages over native packages @@ -132,7 +131,7 @@ For example: ```puppet package { 'express': - ensure => 'present', + ensure => installed, provider => 'npm', } @@ -161,7 +160,7 @@ except version ranges. The title simply must be a unique, arbitrary value. the package parameter needs to be match the name of the package in the npm registry. * Package versions are specified with the ensure parameter, which defaults to - `present`. + `installed`. * Install options and uninstall options are also supported, and need to be specified as an array. * The user parameter is provided should you wish to run npm install or npm rm @@ -170,17 +169,6 @@ except version ranges. The title simply must be a unique, arbitrary value. (e.g. if you have a NodeJS server app), set the parameter use_package_json to true. The package name is then only used for the resource name. source parameter is ignored. -nodejs::npm parameters: - -* ensure: present (default), absent, latest, tag or version number. -* source: package source (defaults to a reserved value 'registry') -* target: where to install the package -* install_options: option flags invoked during installation such as --link (optional). -* uninstall_options: option flags invoked during removal (optional). -* npm_path: defaults to the value listed in `nodejs::params` -* user: defaults to undef -* use_package_json: read and install modules listed in package.json in target dir and install those in subdirectory node_modules (defaults to false) - Examples: Install the express package published on the npm registry to /opt/packages: @@ -373,168 +361,9 @@ nodejs::npm::global_config_entry { 'color': If a global_config_entry of `proxy` or `https-proxy` is specified, this will be applied before the local installation of npm packages using `nodejs::npm`. -### Parameters - -#### `cmd_exe_path` - -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 and nodejs-dev packages. Defaults to `true`. - -#### `manage_package_repo` - -Whether to manage an external repository and use it as the source of the -Node.js and npm package. Defaults to `true`. - -#### `nodejs_debug_package_ensure` - -When set to `present` or a version number, determines whether to install the -Node.js package with debugging symbols, if available. Defaults to `absent`. - -#### `nodejs_dev_package_ensure` - -When set to `present` or a version number, determines whether to install the -development Node.js package, if available. Defaults to `absent`. - -#### `nodejs_package_ensure` - -When set to `present` or a version number, determines whether to install the -Node.js package. Defaults to `present`. - -#### `npm_package_ensure` - -When set to `present` or a version number, determines whether to install the -separate npm package. When using the NodeSource repository, the Node.js -package includes npm, so this value defaults to `absent`. This parameter will -need to be set to `present` if you wish to use the native packages or are -using the EPEL repository. - -#### `npm_path` - -Path to the npm binary. - -#### `npmrc_auth` - -A string that contains the value for the key `_auth` that will be set in -`/root/.npmrc`, as this value is not allowed to be set by -nodejs::npm::global_config_entry. The default value is `undef`. - -#### `npmrc_config` - -A hash that contains keys/values that will be set in `/root/.npmrc`, -in the form of `key=value`. Useful for setting a http-proxy for npm only. -The default value is `undef`. - -#### `repo_class` - -Name of the Puppet class used for the setup and management of the Node.js -repository. Defaults to `::nodejs::repo::nodesource` (NodeSource). -If using the Node.js and npm packages from the EPEL repository, set this to -`::epel` and make sure that the EPEL module is applied before the nodejs -module in your Puppet node definitions. - -#### `repo_enable_src` - -Whether any repositories which hold sources are enabled. Defaults to `false`. - -#### `repo_ensure` - -Whether to ensure that the repository exists, if it is being managed. Defaults -to `present` and may also be set to `absent`. - -#### `repo_pin` - -Whether to perform APT pinning to pin the Node.js repository with a specific -value. Defaults to `undef`. - -#### `repo_priority` - -Whether to set a Yum priority for the Node.js repository. If using EPEL and -the NodeSource repository on the same system, you may wish to set this to a -value less than 99 (or the priority set for the EPEL repository) to ensure -that the NodeSource repository will always be preferred over the Node.js -packages in EPEL, should they both hold the same Node.js version. Defaults to -`absent`. - -#### `repo_proxy` - -Whether to use a proxy for this particular repository. For example, -`http://proxy.domain`. Defaults to `absent`. - -#### `repo_proxy_password` - -Password for the proxy used by the repository, if required. - -#### `repo_proxy_username` - -User for the proxy used by the repository, if required. - -#### `repo_release` - -Optional value to override the apt distribution release. Defaults to `undef` -which will autodetect the distribution. If a value is specified, this will -change the NodeSource apt repository distribution. -This is useful if the distribution name does not exist in the NodeSource -repositories. For example, the Ubilinux distribution release name 'dolcetto' -does not exist in NodeSource, but is a derivative of Debian 9 (Stretch). -Setting this value to `stretch` allows NodeSource repository management to -then work as expected on these systems. - -#### `repo_url_suffix` - -Defaults to ```12.x``` which means that the latest NodeSource 12.x release -is installed. If you wish to install a 13.x release or greater, you will -need to set this value accordingly. This parameter is a just a reflection of -the NodeSource URL structure - NodeSource might remove old versions (such as -0.10 and 0.12) or add new ones (such as 20.x) at any time. - -The following are ``repo_url_suffix`` values that reflect NodeSource versions -that were available on 2017-11-29: - -* 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 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``` -* Ubuntu 17.10 (Artful) ```4.x``` ```6.x``` ```8.x``` ```9.x``` -* RHEL/CentOS 7 ```0.10``` ```0.12``` ```4.x``` ```5.x``` ```6.x``` ```7.x``` ```8.x``` ```9.x``` -* 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` - -The USE flags to use for the Node.js package on Gentoo systems. Defaults to -['npm', 'snapshot']. - -#### `package_provider` - -The package provider is set as the default for most distributions. You can override -this with the package_provider parameter to use an alternative - ## Limitations -This module has received limited testing on: - -* CentOS/RHEL 7/8 -* Debian 9/10 -* Ubuntu 16.04/18.04/20.04 - -The following platforms should also work, but have not been tested: - -* Amazon Linux -* Archlinux -* Darwin -* Fedora -* FreeBSD -* Gentoo -* OpenBSD -* OpenSuse/SLES -* Ubilinux -* Windows +See [`metadata.json`](metadata.json) for supported operating systems. ### Module dependencies @@ -542,7 +371,7 @@ 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 4.4.0 or above is installed. -If using CentOS/RHEL 7 and you wish to install Node.js from EPEL rather +If using CentOS/RHEL and you wish to install Node.js from EPEL rather than from the NodeSource repository, you will need to ensure `puppet-epel` is installed and is applied before this module. diff --git a/Rakefile b/Rakefile index 80b799d6..862d8697 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper), +# Attempt to load voxpupuli-test (which pulls in puppetlabs_spec_helper), # otherwise attempt to load it directly. begin require 'voxpupuli/test/rake' @@ -24,6 +24,10 @@ end begin require 'voxpupuli/release/rake_tasks' rescue LoadError + # voxpupuli-release not present +else + GCGConfig.user = 'voxpupuli' + GCGConfig.project = 'puppet-nodejs' end desc "Run main 'test' task and report merged results to coveralls" @@ -37,36 +41,4 @@ task test_with_coveralls: [:test] do end end -desc 'Generate REFERENCE.md' -task :reference, [:debug, :backtrace] do |t, args| - patterns = '' - Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) -end - -begin - require 'github_changelog_generator/task' - require 'puppet_blacksmith' - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - metadata = Blacksmith::Modulefile.new - config.future_release = "v#{metadata.version}" if metadata.version =~ /^\d+\.\d+.\d+$/ - config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module." - config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} - config.user = 'voxpupuli' - config.project = metadata.metadata['name'] - end - - # Workaround for https://github.com/github-changelog-generator/github-changelog-generator/issues/715 - require 'rbconfig' - if RbConfig::CONFIG['host_os'] =~ /linux/ - task :changelog do - puts 'Fixing line endings...' - changelog_file = File.join(__dir__, 'CHANGELOG.md') - changelog_txt = File.read(changelog_file) - new_contents = changelog_txt.gsub(%r{\r\n}, "\n") - File.open(changelog_file, "w") {|file| file.puts new_contents } - end - end - -rescue LoadError -end # vim: syntax=ruby diff --git a/lib/puppet/feature/npm.rb b/lib/puppet/feature/npm.rb index 877d4f27..31ba2d40 100644 --- a/lib/puppet/feature/npm.rb +++ b/lib/puppet/feature/npm.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/util/feature' require 'puppet/util/npm' diff --git a/lib/puppet/provider/package/npm.rb b/lib/puppet/provider/package/npm.rb index 07d82503..d34e5a49 100644 --- a/lib/puppet/provider/package/npm.rb +++ b/lib/puppet/provider/package/npm.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/provider/package' Puppet::Type.type(:package).provide :npm, parent: Puppet::Provider::Package do @@ -18,9 +20,9 @@ def self.npmlist Puppet.debug("Warning: npm list --json exited with code #{output.exitstatus}") if output.exitstatus != 0 begin # ignore any npm output lines to be a bit more robust - output = PSON.parse(output.lines.select { |l| l =~ %r{^((?!^npm).*)$} }.join("\n"), max_nesting: 100) + output = JSON.parse(output.lines.grep(%r{^((?!^npm).*)$}).join("\n"), max_nesting: 100) @npmlist = output['dependencies'] || {} - rescue PSON::ParserError => e + rescue JSON::ParserError => e Puppet.debug("Error: npm list --json command error #{e.message}") @npmlist = {} end diff --git a/lib/puppet/util/npm.rb b/lib/puppet/util/npm.rb index 7f5a1c8c..4d0ed627 100644 --- a/lib/puppet/util/npm.rb +++ b/lib/puppet/util/npm.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Puppet module Util class Npm diff --git a/manifests/npm/global_config_entry.pp b/manifests/npm/global_config_entry.pp index 73d3101d..bcd2282a 100644 --- a/manifests/npm/global_config_entry.pp +++ b/manifests/npm/global_config_entry.pp @@ -49,7 +49,7 @@ if $nodejs::npm_package_ensure != 'absent' { $exec_require = "Package[${nodejs::npm_package_name}]" - } elsif $nodejs::repo_class == '::nodejs::repo::nodesource' { + } elsif $nodejs::repo_class == 'nodejs::repo::nodesource' { $exec_require = "Package[${nodejs::nodejs_package_name}]" } else { $exec_require = undef diff --git a/manifests/params.pp b/manifests/params.pp index 163c7313..abeb4cb0 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -2,7 +2,7 @@ $npmrc_auth = undef $npmrc_config = undef $nodejs_debug_package_ensure = 'absent' - $nodejs_package_ensure = 'present' + $nodejs_package_ensure = 'installed' $repo_enable_src = false $repo_ensure = 'present' $repo_pin = undef @@ -21,99 +21,27 @@ case $facts['os']['family'] { 'Debian': { - if $facts['os']['release']['major'] =~ /^(9|10|11)$/ { - $debian_nodejs_dev_package_name = $facts['os']['release']['major'] ? { - '9' => 'nodejs-dev', - default => 'libnode-dev', - } - $debian_npm_package_name = $facts['os']['release']['major'] ? { - '9' => false, - default => 'npm', - } - $manage_package_repo = true - $nodejs_debug_package_name = 'nodejs-dbg' - $nodejs_dev_package_name = $debian_nodejs_dev_package_name - $nodejs_dev_package_ensure = 'absent' - $nodejs_package_name = 'nodejs' - $npm_package_ensure = 'absent' - $npm_package_name = $debian_npm_package_name - $npm_path = '/usr/bin/npm' - $repo_class = '::nodejs::repo::nodesource' - } - elsif $facts['os']['release']['full'] =~ /^1[68]\.04$/ { - $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 $facts['os']['release']['full'] =~ /^20\.04$/ { - $manage_package_repo = true - $nodejs_debug_package_name = 'nodejs-dbg' - $nodejs_dev_package_name = 'libnode-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' - } - else { - warning("The ${module_name} module might not work on ${facts['os']['name']} ${facts['os']['release']['full']}. Sensible defaults will be attempted.") - $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' - } - + $manage_package_repo = true + $nodejs_debug_package_name = 'nodejs-dbg' + $nodejs_dev_package_name = 'libnode-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' $package_provider = undef } 'RedHat': { - if $facts['os']['release']['major'] =~ /^[78]$/ { - $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' - } - elsif $facts['os']['name'] == 'Fedora' { - $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' - } - elsif ($facts['os']['name'] == 'Amazon') { - $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' - } - else { - fail("The ${module_name} module is not supported on ${facts['os']['name']} ${facts['os']['release']['full']}.") - } + $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' $package_provider = undef } 'Suse': { @@ -122,7 +50,7 @@ $nodejs_dev_package_name = 'nodejs-devel' $nodejs_dev_package_ensure = 'absent' $nodejs_package_name = 'nodejs' - $npm_package_ensure = 'present' + $npm_package_ensure = 'installed' $npm_package_name = 'npm' $npm_path = '/usr/bin/npm' $repo_class = undef @@ -134,7 +62,7 @@ $nodejs_dev_package_name = undef $nodejs_dev_package_ensure = 'absent' $nodejs_package_name = 'nodejs' - $npm_package_ensure = 'present' + $npm_package_ensure = 'installed' $npm_package_name = 'npm' $npm_path = '/usr/bin/npm' $repo_class = undef @@ -146,7 +74,7 @@ $nodejs_dev_package_name = 'www/node-devel' $nodejs_dev_package_ensure = 'absent' $nodejs_package_name = 'www/node' - $npm_package_ensure = 'present' + $npm_package_ensure = 'installed' $npm_package_name = 'www/npm' $npm_path = '/usr/local/bin/npm' $repo_class = undef @@ -170,7 +98,7 @@ $nodejs_dev_package_name = 'nodejs-devel' $nodejs_dev_package_ensure = 'absent' $nodejs_package_name = 'nodejs' - $npm_package_ensure = 'present' + $npm_package_ensure = 'installed' $npm_package_name = 'npm' $npm_path = '/opt/local/bin/npm' $repo_class = undef diff --git a/manifests/repo/nodesource.pp b/manifests/repo/nodesource.pp index 564766b8..ac8a52cf 100644 --- a/manifests/repo/nodesource.pp +++ b/manifests/repo/nodesource.pp @@ -12,7 +12,7 @@ case $facts['os']['family'] { 'RedHat': { - if $facts['os']['release']['major'] =~ /^[78]$/ { + if $facts['os']['release']['major'] =~ /^[789]$/ { $dist_version = $facts['os']['release']['major'] $name_string = "Enterprise Linux ${dist_version}" } diff --git a/manifests/repo/nodesource/yum.pp b/manifests/repo/nodesource/yum.pp index f8ad9efb..d45f7b13 100644 --- a/manifests/repo/nodesource/yum.pp +++ b/manifests/repo/nodesource/yum.pp @@ -22,7 +22,7 @@ } if ($ensure == 'present') { - if $facts['os']['release']['major'] == '8' { + if versioncmp($facts['os']['release']['major'], '8') >= 0 { file { 'dnf_module': ensure => file, path => '/etc/dnf/modules.d/nodejs.module', @@ -79,7 +79,7 @@ ensure => 'absent', } - if $facts['os']['release']['major'] == '8' { + if versioncmp($facts['os']['release']['major'], '8') >= 0 { file { 'dnf_module': ensure => absent, path => '/etc/dnf/modules.d/nodejs.module', diff --git a/metadata.json b/metadata.json index 66c1fca1..acb3c598 100644 --- a/metadata.json +++ b/metadata.json @@ -12,34 +12,37 @@ "operatingsystem": "RedHat", "operatingsystemrelease": [ "7", - "8" + "8", + "9" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "7", - "8" + "8", + "9" ] }, { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ "7", - "8" + "8", + "9" ] }, { "operatingsystem": "Scientific", "operatingsystemrelease": [ "7", - "8" + "8", + "9" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ - "9", "10", "11" ] @@ -47,15 +50,12 @@ { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ - "16.04", - "18.04", "20.04" ] }, { "operatingsystem": "FreeBSD", "operatingsystemrelease": [ - "11", "12", "13" ] @@ -64,13 +64,13 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 7.0.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.25.0 < 9.0.0" + "version_requirement": ">= 4.25.0 < 10.0.0" } ] } diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index ab7b3e19..eda53722 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,23 +1,24 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' -describe 'nodejs class:' do +describe 'nodejs' do case fact('os.family') when 'RedHat' pkg_cmd = 'yum info nodejs | grep "^From repo"' - install_module_from_forge('puppet-epel', '>= 3.0.0 < 4.0.0') when 'Debian' pkg_cmd = 'dpkg -s nodejs | grep "^Maintainer"' - install_module_from_forge('puppetlabs-apt', '>= 4.4.0 < 9.0.0') end context 'default parameters' do - let(:pp) { "class { 'nodejs': }" } - - it_behaves_like 'an idempotent resource' + it_behaves_like 'an idempotent resource' do + let(:manifest) { "class { 'nodejs': }" } + end if %w[RedHat Debian].include? fact('os.family') describe package('nodejs') do it { is_expected.to be_installed } + it 'comes from the expected source' do pkg_output = shell(pkg_cmd) expect(pkg_output.stdout).to match 'nodesource' @@ -26,107 +27,113 @@ end end - context 'repo_class => epel', if: ((fact('os.family') == 'RedHat') && (fact('os.release.major') != '8')) do - let(:pp) { "class { 'nodejs': repo_class => '::epel' }" } - - it_behaves_like 'an idempotent resource' + context 'RedHat with repo_class => epel', if: fact('os.family') == 'RedHat' do + include_examples 'cleanup' + + it_behaves_like 'an idempotent resource' do + # nodejs-devel (from EPEL) is currently not installable alongside nodejs + # (from appstream) due to differing versions. + nodejs_dev_package_ensure = + if fact('os.release.major') == '9' + 'undef' + else + 'installed' + end - describe package('nodejs') do - it { is_expected.to be_installed } - it 'comes from the expected source' do - pending("This won't work until we have CentOS 7.4 because of dependency") - pkg_output = shell(pkg_cmd) - expect(pkg_output.stdout).to match 'epel' + let(:manifest) do + <<-PUPPET + class { 'nodejs': + nodejs_dev_package_ensure => #{nodejs_dev_package_ensure}, + npm_package_ensure => installed, + repo_class => 'epel', + } + PUPPET end end - context 'set global_config_entry secret', if: fact('os.family') == 'RedHat' do - let :pp do - "class { 'nodejs': }; nodejs::npm::global_config_entry { '//path.to.registry/:_secret': ensure => present, value => 'cGFzc3dvcmQ=', require => Package[nodejs],}" - end - - it_behaves_like 'an idempotent resource' - - describe package('nodejs') do - it { is_expected.to be_installed } - end - - describe 'npm config' do - it 'contains the global_config_entry secret' do - npm_output = shell('cat $(/usr/bin/npm config get globalconfig)') - expect(npm_output.stdout).to match '//path.to.registry/:_secret="cGFzc3dvcmQ="' + %w[ + npm + nodejs + nodejs-devel + ].each do |pkg| + describe package(pkg) do + it do + pending('nodejs-devel and nodejs not installable together on EL9') if fact('os.release.major') == '9' && pkg == 'nodejs-devel' + is_expected.to be_installed end end end + end - context 'set global_config_entry secret unquoted', if: fact('os.family') == 'RedHat' do - let :pp do - "class { 'nodejs': }; nodejs::npm::global_config_entry { '//path.to.registry/:_secret': ensure => present, value => 'cGFzc3dvcmQ', require => Package[nodejs],}" + context 'Debian distribution packages', if: fact('os.family') == 'Debian' do + include_examples 'cleanup' + + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'nodejs': + manage_package_repo => false, + nodejs_dev_package_ensure => installed, + npm_package_ensure => installed, + } + PUPPET end + end - it_behaves_like 'an idempotent resource' - - describe package('nodejs') do + %w[ + libnode-dev + npm + ].each do |pkg| + describe package(pkg) do it { is_expected.to be_installed } end - - describe 'npm config' do - it 'contains the global_config_entry secret' do - npm_output = shell('cat $(/usr/bin/npm config get globalconfig)') - expect(npm_output.stdout).to match '//path.to.registry/:_secret=cGFzc3dvcmQ' - end - end end end -end -# Must uninstall the default nodesource repo and packages which come from there before attempting -# to install native packages. -context 'uninstall' do - let(:pp) do - " - class { 'nodejs': - nodejs_debug_package_ensure => absent, - nodejs_dev_package_ensure => absent, - nodejs_package_ensure => absent, - npm_package_ensure => absent, - repo_ensure => absent, - } - " - end - - it_behaves_like 'an idempotent resource' -end + context 'set global_config_entry secret' do + include_examples 'cleanup' + + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'nodejs': } + nodejs::npm::global_config_entry { '//path.to.registry/:_secret': + ensure => present, + value => 'cGFzc3dvcmQ=', + require => Package[nodejs], + } + PUPPET + end + end -context 'native Debian packages' do - let(:pp) do - " - class { 'nodejs': - manage_package_repo => false, - nodejs_dev_package_ensure => present, - npm_package_ensure => present, - } - " + describe 'npm config' do + it 'contains the global_config_entry secret' do + npm_output = shell('cat $(/usr/bin/npm config get globalconfig)') + expect(npm_output.stdout).to match '//path.to.registry/:_secret="cGFzc3dvcmQ="' + end + end end - it_behaves_like 'an idempotent resource' - - if fact('os.family') == 'Debian' - if %w[9 16.04 18.04].include? fact('os.release.major') - describe package('nodejs-dev') do - it { is_expected.to be_installed } + context 'set global_config_entry secret unquoted' do + include_examples 'cleanup' + + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'nodejs': } + nodejs::npm::global_config_entry { '//path.to.registry/:_secret': + ensure => present, + value => 'cGFzc3dvcmQ', + require => Package[nodejs], + } + PUPPET end - if %w[16.04 18.04].include? fact('os.release.major') - describe package('npm') do - it { is_expected.to be_installed } - end - end - else - describe package('libnode-dev') do - it { is_expected.to be_installed } - end - describe package('npm') do - it { is_expected.to be_installed } + end + + describe 'npm config' do + it 'contains the global_config_entry secret' do + npm_output = shell('cat $(/usr/bin/npm config get globalconfig)') + expect(npm_output.stdout).to match '//path.to.registry/:_secret=cGFzc3dvcmQ' end end end diff --git a/spec/classes/nodejs_spec.rb b/spec/classes/nodejs_spec.rb index 95b3b462..c28dff9f 100644 --- a/spec/classes/nodejs_spec.rb +++ b/spec/classes/nodejs_spec.rb @@ -1,29 +1,23 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nodejs', type: :class do on_supported_os.each do |os, facts| next unless facts[:os]['family'] == 'Debian' - context "on #{os} " do + context "on #{os}" do let :facts do facts end - native_debian_devel_package = if facts[:os]['name'] == 'Ubuntu' && Gem::Version.new(facts[:os]['release']['major']) >= Gem::Version.new('20.04') - 'libnode-dev' - elsif facts[:os]['name'] == 'Debian' && Gem::Version.new(facts[:os]['release']['major']) >= Gem::Version.new(10) - 'libnode-dev' - else - 'nodejs-dev' - end - it 'the file resource root_npmrc should be in the catalog' do is_expected.to contain_file('root_npmrc').with( 'ensure' => 'file', - 'path' => '/root/.npmrc', - 'owner' => 'root', - 'group' => '0', - 'mode' => '0600' + 'path' => '/root/.npmrc', + 'owner' => 'root', + 'group' => '0', + 'mode' => '0600' ) end @@ -72,20 +66,20 @@ it 'the nodejs and dev package resources should not be present' do is_expected.not_to contain_package('nodejs') - is_expected.not_to contain_package(native_debian_devel_package) + is_expected.not_to contain_package('libnode-dev') end end - context 'and repo_class set to ::nodejs::repo::nodesource' do + 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 + it 'nodejs::repo::nodesource should be in the catalog' do is_expected.to contain_class('nodejs::repo::nodesource') end - it '::nodejs::repo::nodesource::apt should be in the catalog' do + it 'nodejs::repo::nodesource::apt should be in the catalog' do is_expected.to contain_class('nodejs::repo::nodesource::apt') end end @@ -178,21 +172,21 @@ } end - it '::nodejs::repo::nodesource should not be in the catalog' do - is_expected.not_to contain_class('::nodejs::repo::nodesource') + 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 + context 'with nodejs_debug_package_ensure set to installed' do let :params do { - nodejs_debug_package_ensure: 'present' + nodejs_debug_package_ensure: 'installed' } end it 'the nodejs package with debugging symbols should be installed' do - is_expected.to contain_package('nodejs-dbg').with('ensure' => 'present') + is_expected.to contain_package('nodejs-dbg').with('ensure' => 'installed') end end @@ -209,15 +203,15 @@ end # nodejs_dev_package_ensure - context 'with nodejs_dev_package_ensure set to present' do + context 'with nodejs_dev_package_ensure set to installed' do let :params do { - nodejs_dev_package_ensure: 'present' + nodejs_dev_package_ensure: 'installed' } end it 'the nodejs development package should be installed' do - is_expected.to contain_package(native_debian_devel_package).with('ensure' => 'present') + is_expected.to contain_package('libnode-dev').with('ensure' => 'installed') end end @@ -229,20 +223,20 @@ end it 'the nodejs development package should not be present' do - is_expected.to contain_package(native_debian_devel_package).with('ensure' => 'absent') + is_expected.to contain_package('libnode-dev').with('ensure' => 'absent') end end # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do + context 'with nodejs_package_ensure set to installed' do let :params do { - nodejs_package_ensure: 'present' + nodejs_package_ensure: 'installed' } end - it 'the nodejs package should be present' do - is_expected.to contain_package('nodejs').with('ensure' => 'present') + it 'the nodejs package should be installed' do + is_expected.to contain_package('nodejs').with('ensure' => 'installed') end end @@ -259,22 +253,15 @@ end # npm_package_ensure - context 'with npm_package_ensure set to present' do + context 'with npm_package_ensure set to installed' do let :params do { - npm_package_ensure: 'present' + npm_package_ensure: 'installed' } end - # Debian 9 (stretch) doesn't have npm in the standard repositories (it has been backported though). - if facts[:os]['family'] == 'Debian' && facts[:os]['release']['major'] == '9' - it 'the npm package resource should not be present' do - is_expected.not_to contain_package('npm') - end - else - it 'the npm package should be present' do - is_expected.to contain_package('npm').with('ensure' => 'present') - end + it 'the npm package should be installed' do + is_expected.to contain_package('npm').with('ensure' => 'installed') end end @@ -285,15 +272,8 @@ } end - # Debian 9 (stretch) doesn't have npm in the standard repositories (it has been backported though). - if facts[:os]['family'] == 'Debian' && facts[:os]['release']['major'] == '9' - it 'the npm package resource should not be present' do - is_expected.not_to contain_package('npm') - end - else - it 'the npm package should be absent' do - is_expected.to contain_package('npm').with('ensure' => 'absent') - end + it 'the npm package should be absent' do + is_expected.to contain_package('npm').with('ensure' => 'absent') end end @@ -319,17 +299,17 @@ if operatingsystemmajrelease == '7' operatingsystem = 'CentOS' dist_type = 'el' - repo_baseurl = "https://rpm.nodesource.com/pub_12.x/#{dist_type}/#{operatingsystemmajrelease}/\$basearch" + repo_baseurl = "https://rpm.nodesource.com/pub_12.x/#{dist_type}/#{operatingsystemmajrelease}/$basearch" repo_source_baseurl = "https://rpm.nodesource.com/pub_12.x/#{dist_type}/#{operatingsystemmajrelease}/SRPMS" - repo_descr = "Node.js Packages for Enterprise Linux #{operatingsystemmajrelease} - \$basearch" - repo_source_descr = "Node.js for Enterprise Linux #{operatingsystemmajrelease} - \$basearch - Source" + repo_descr = "Node.js Packages for Enterprise Linux #{operatingsystemmajrelease} - $basearch" + repo_source_descr = "Node.js for Enterprise Linux #{operatingsystemmajrelease} - $basearch - Source" else operatingsystem = 'Fedora' dist_type = 'fc' - repo_baseurl = "https://rpm.nodesource.com/pub_12.x/#{dist_type}/#{operatingsystemmajrelease}/\$basearch" + repo_baseurl = "https://rpm.nodesource.com/pub_12.x/#{dist_type}/#{operatingsystemmajrelease}/$basearch" repo_source_baseurl = "https://rpm.nodesource.com/pub_12.x/#{dist_type}/#{operatingsystemmajrelease}/SRPMS" - repo_descr = "Node.js Packages for Fedora Core #{operatingsystemmajrelease} - \$basearch" - repo_source_descr = "Node.js for Fedora Core #{operatingsystemmajrelease} - \$basearch - Source" + repo_descr = "Node.js Packages for Fedora Core #{operatingsystemmajrelease} - $basearch" + repo_source_descr = "Node.js for Fedora Core #{operatingsystemmajrelease} - $basearch - Source" end context "when run on #{operatingsystem} release #{operatingsystemrelease}" do @@ -340,7 +320,7 @@ 'name' => operatingsystem, 'release' => { 'major' => operatingsystemmajrelease, - 'full' => operatingsystemrelease + 'full' => operatingsystemrelease } } } @@ -375,25 +355,29 @@ end end - context 'and repo_class set to ::nodejs::repo::nodesource' do + 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 + 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 + 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) + 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 @@ -402,8 +386,8 @@ default_params.merge!(repo_url_suffix: '5.x') end - it "the yum nodesource repo resource should contain baseurl = https://rpm.nodesource.com/pub_5.x/#{dist_type}/#{operatingsystemmajrelease}/\$basearch" do - is_expected.to contain_yumrepo('nodesource').with('baseurl' => "https://rpm.nodesource.com/pub_5.x/#{dist_type}/#{operatingsystemmajrelease}/\$basearch") + it "the yum nodesource repo resource should contain baseurl = https://rpm.nodesource.com/pub_5.x/#{dist_type}/#{operatingsystemmajrelease}/$basearch" do + is_expected.to contain_yumrepo('nodesource').with('baseurl' => "https://rpm.nodesource.com/pub_5.x/#{dist_type}/#{operatingsystemmajrelease}/$basearch") end end @@ -543,21 +527,21 @@ } end - it '::nodejs::repo::nodesource should not be in the catalog' do - is_expected.not_to contain_class('::nodejs::repo::nodesource') + 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 + context 'with nodejs_debug_package_ensure set to installed' do let :params do { - nodejs_debug_package_ensure: 'present' + nodejs_debug_package_ensure: 'installed' } end it 'the nodejs package with debugging symbols should be installed' do - is_expected.to contain_package('nodejs-debuginfo').with('ensure' => 'present') + is_expected.to contain_package('nodejs-debuginfo').with('ensure' => 'installed') end end @@ -574,15 +558,15 @@ end # nodejs_dev_package_ensure - context 'with nodejs_dev_package_ensure set to present' do + context 'with nodejs_dev_package_ensure set to installed' do let :params do { - nodejs_dev_package_ensure: 'present' + nodejs_dev_package_ensure: 'installed' } end it 'the nodejs development package should be installed' do - is_expected.to contain_package('nodejs-devel').with('ensure' => 'present') + is_expected.to contain_package('nodejs-devel').with('ensure' => 'installed') end end @@ -599,15 +583,15 @@ end # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do + context 'with nodejs_package_ensure set to installed' do let :params do { - nodejs_package_ensure: 'present' + nodejs_package_ensure: 'installed' } end it 'the nodejs package should be present' do - is_expected.to contain_package('nodejs').with('ensure' => 'present') + is_expected.to contain_package('nodejs').with('ensure' => 'installed') end end @@ -624,15 +608,15 @@ end # npm_package_ensure - context 'with npm_package_ensure set to present' do + context 'with npm_package_ensure set to installed' do let :params do { - npm_package_ensure: 'present' + npm_package_ensure: 'installed' } end it 'the npm package should be present' do - is_expected.to contain_package('npm').with('ensure' => 'present') + is_expected.to contain_package('npm').with('ensure' => 'installed') end end @@ -661,15 +645,15 @@ end # nodejs_debug_package_ensure - context 'with nodejs_debug_package_ensure set to present' do + context 'with nodejs_debug_package_ensure set to installed' do let :params do { - nodejs_debug_package_ensure: 'present' + nodejs_debug_package_ensure: 'installed' } end it 'the nodejs package with debugging symbols should be installed' do - is_expected.to contain_package('nodejs-debuginfo').with('ensure' => 'present') + is_expected.to contain_package('nodejs-debuginfo').with('ensure' => 'installed') end end @@ -686,15 +670,15 @@ end # nodejs_dev_package_ensure - context 'with nodejs_dev_package_ensure set to present' do + context 'with nodejs_dev_package_ensure set to installed' do let :params do { - nodejs_dev_package_ensure: 'present' + nodejs_dev_package_ensure: 'installed' } end it 'the nodejs development package should be installed' do - is_expected.to contain_package('nodejs-devel').with('ensure' => 'present') + is_expected.to contain_package('nodejs-devel').with('ensure' => 'installed') end end @@ -737,15 +721,15 @@ end # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do + context 'with nodejs_package_ensure set to installed' do let :params do { - nodejs_package_ensure: 'present' + nodejs_package_ensure: 'installed' } end it 'the nodejs package should be present' do - is_expected.to contain_package('nodejs').with('ensure' => 'present') + is_expected.to contain_package('nodejs').with('ensure' => 'installed') end end @@ -762,15 +746,15 @@ end # npm_package_ensure - context 'with npm_package_ensure set to present' do + context 'with npm_package_ensure set to installed' do let :params do { - npm_package_ensure: 'present' + npm_package_ensure: 'installed' } end it 'the npm package should be present' do - is_expected.to contain_package('npm').with('ensure' => 'present') + is_expected.to contain_package('npm').with('ensure' => 'installed') end end @@ -823,15 +807,15 @@ end # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do + context 'with nodejs_package_ensure set to installed' do let :params do { - nodejs_package_ensure: 'present' + nodejs_package_ensure: 'installed' } end it 'the nodejs package should be present' do - is_expected.to contain_package('nodejs').with('ensure' => 'present') + is_expected.to contain_package('nodejs').with('ensure' => 'installed') end end @@ -885,15 +869,15 @@ end # nodejs_dev_package_ensure - context 'with nodejs_dev_package_ensure set to present' do + context 'with nodejs_dev_package_ensure set to installed' do let :params do { - nodejs_dev_package_ensure: 'present' + nodejs_dev_package_ensure: 'installed' } end it 'the nodejs development package should be installed' do - is_expected.to contain_package('www/node-devel').with('ensure' => 'present') + is_expected.to contain_package('www/node-devel').with('ensure' => 'installed') end end @@ -910,15 +894,15 @@ end # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do + context 'with nodejs_package_ensure set to installed' do let :params do { - nodejs_package_ensure: 'present' + nodejs_package_ensure: 'installed' } end it 'the nodejs package should be present' do - is_expected.to contain_package('www/node').with('ensure' => 'present') + is_expected.to contain_package('www/node').with('ensure' => 'installed') end end @@ -935,15 +919,15 @@ end # npm_package_ensure - context 'with npm_package_ensure set to present' do + context 'with npm_package_ensure set to installed' do let :params do { - npm_package_ensure: 'present' + npm_package_ensure: 'installed' } end it 'the npm package should be present' do - is_expected.to contain_package('www/npm').with('ensure' => 'present') + is_expected.to contain_package('www/npm').with('ensure' => 'installed') end end @@ -996,15 +980,15 @@ end # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do + context 'with nodejs_package_ensure set to installed' do let :params do { - nodejs_package_ensure: 'present' + nodejs_package_ensure: 'installed' } end it 'the nodejs package should be present' do - is_expected.to contain_package('node').with('ensure' => 'present') + is_expected.to contain_package('node').with('ensure' => 'installed') end end @@ -1058,15 +1042,15 @@ end # nodejs_dev_package_ensure - context 'with nodejs_dev_package_ensure set to present' do + context 'with nodejs_dev_package_ensure set to installed' do let :params do { - nodejs_dev_package_ensure: 'present' + nodejs_dev_package_ensure: 'installed' } end it 'the nodejs development package should be installed' do - is_expected.to contain_package('nodejs-devel').with('ensure' => 'present') + is_expected.to contain_package('nodejs-devel').with('ensure' => 'installed') end end @@ -1083,15 +1067,15 @@ end # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do + context 'with nodejs_package_ensure set to installed' do let :params do { - nodejs_package_ensure: 'present' + nodejs_package_ensure: 'installed' } end it 'the nodejs package should be present' do - is_expected.to contain_package('nodejs').with('ensure' => 'present') + is_expected.to contain_package('nodejs').with('ensure' => 'installed') end end @@ -1108,15 +1092,15 @@ end # npm_package_ensure - context 'with npm_package_ensure set to present' do + context 'with npm_package_ensure set to installed' do let :params do { - npm_package_ensure: 'present' + npm_package_ensure: 'installed' } end it 'the npm package should be present' do - is_expected.to contain_package('npm').with('ensure' => 'present') + is_expected.to contain_package('npm').with('ensure' => 'installed') end end @@ -1190,15 +1174,15 @@ end # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do + context 'with nodejs_package_ensure set to installed' do let :params do { - nodejs_package_ensure: 'present' + nodejs_package_ensure: 'installed' } end it 'the nodejs package should be present' do - is_expected.to contain_package('nodejs').with('ensure' => 'present') + is_expected.to contain_package('nodejs').with('ensure' => 'installed') end end @@ -1215,15 +1199,15 @@ end # npm_package_ensure - context 'with npm_package_ensure set to present' do + context 'with npm_package_ensure set to installed' do let :params do { - npm_package_ensure: 'present' + npm_package_ensure: 'installed' } end it 'the npm package should be present' do - is_expected.to contain_package('npm').with('ensure' => 'present') + is_expected.to contain_package('npm').with('ensure' => 'installed') end end @@ -1276,15 +1260,15 @@ end # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do + context 'with nodejs_package_ensure set to installed' do let :params do { - nodejs_package_ensure: 'present' + nodejs_package_ensure: 'installed' } end it 'the nodejs package should be present' do - is_expected.to contain_package('net-libs/nodejs').with('ensure' => 'present') + is_expected.to contain_package('net-libs/nodejs').with('ensure' => 'installed') end end @@ -1320,7 +1304,7 @@ 'family' => 'RedHat', 'name' => 'Amazon', 'release' => { - 'full' => '2015.03', + 'full' => '2015.03', 'major' => '2015', 'minor' => '03' } @@ -1362,25 +1346,25 @@ end end - context 'and repo_class set to ::nodejs::repo::nodesource' do + 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 + 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 + 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) + 'descr' => repo_descr) is_expected.to contain_yumrepo('nodesource-source').with('baseurl' => repo_source_baseurl, - 'descr' => repo_source_descr) + 'descr' => repo_source_descr) end end @@ -1500,21 +1484,21 @@ } end - it '::nodejs::repo::nodesource should not be in the catalog' do - is_expected.not_to contain_class('::nodejs::repo::nodesource') + 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 + context 'with nodejs_debug_package_ensure set to installed' do let :params do { - nodejs_debug_package_ensure: 'present' + nodejs_debug_package_ensure: 'installed' } end it 'the nodejs package with debugging symbols should be installed' do - is_expected.to contain_package('nodejs-debuginfo').with('ensure' => 'present') + is_expected.to contain_package('nodejs-debuginfo').with('ensure' => 'installed') end end @@ -1531,15 +1515,15 @@ end # nodejs_dev_package_ensure - context 'with nodejs_dev_package_ensure set to present' do + context 'with nodejs_dev_package_ensure set to installed' do let :params do { - nodejs_dev_package_ensure: 'present' + nodejs_dev_package_ensure: 'installed' } end it 'the nodejs development package should be installed' do - is_expected.to contain_package('nodejs-devel').with('ensure' => 'present') + is_expected.to contain_package('nodejs-devel').with('ensure' => 'installed') end end @@ -1556,15 +1540,15 @@ end # nodejs_package_ensure - context 'with nodejs_package_ensure set to present' do + context 'with nodejs_package_ensure set to installed' do let :params do { - nodejs_package_ensure: 'present' + nodejs_package_ensure: 'installed' } end it 'the nodejs package should be present' do - is_expected.to contain_package('nodejs').with('ensure' => 'present') + is_expected.to contain_package('nodejs').with('ensure' => 'installed') end end @@ -1581,15 +1565,15 @@ end # npm_package_ensure - context 'with npm_package_ensure set to present' do + context 'with npm_package_ensure set to installed' do let :params do { - npm_package_ensure: 'present' + npm_package_ensure: 'installed' } end it 'the npm package should be present' do - is_expected.to contain_package('npm').with('ensure' => 'present') + is_expected.to contain_package('npm').with('ensure' => 'installed') end end diff --git a/spec/defines/global_config_entry_spec.rb b/spec/defines/global_config_entry_spec.rb index 15221b57..fed654fb 100644 --- a/spec/defines/global_config_entry_spec.rb +++ b/spec/defines/global_config_entry_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nodejs::npm::global_config_entry', type: :define do @@ -6,7 +8,7 @@ end on_supported_os.each do |os, facts| - context "on #{os} " do + context "on #{os}" do let :facts do facts end @@ -104,7 +106,7 @@ class { 'nodejs': class { 'nodejs': nodejs_package_name => 'node-package-name', npm_package_ensure => absent, - repo_class => '::nodejs::repo::nodesource', + repo_class => 'nodejs::repo::nodesource', } PUPPET end diff --git a/spec/defines/nodejs_npm_spec.rb b/spec/defines/nodejs_npm_spec.rb index b9d65907..41c01304 100644 --- a/spec/defines/nodejs_npm_spec.rb +++ b/spec/defines/nodejs_npm_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'nodejs::npm', type: :define do @@ -6,7 +8,7 @@ end on_supported_os.each do |os, facts| - context "on #{os} " do + context "on #{os}" do let :facts do facts end @@ -35,7 +37,7 @@ it 'the npm install command should run under user foo' do is_expected.to contain_exec('npm_install_express').with( 'command' => "#{npm_path} install express ", - 'user' => 'foo' + 'user' => 'foo' ) end end @@ -380,7 +382,7 @@ it 'the command should be npm rm express --save' do is_expected.to contain_exec('npm_rm_express').with( 'command' => "#{npm_path} rm express --save", - 'cwd' => '/home/npm/packages' + 'cwd' => '/home/npm/packages' ) end end diff --git a/spec/setup_acceptance_node.pp b/spec/setup_acceptance_helper.pp similarity index 100% rename from spec/setup_acceptance_node.pp rename to spec/setup_acceptance_helper.pp diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 13da4ce5..3b8712f9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ @@ -7,15 +9,16 @@ # puppetlabs_spec_helper will set up coverage if the env variable is set. # We want to do this if lib exists and it hasn't been explicitly set. -ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__)) +ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) require 'voxpupuli/test/spec_helper' +add_mocked_facts! + if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) - if facts - facts.each do |name, value| - add_custom_fact name.to_sym, value - end + facts&.each do |name, value| + add_custom_fact name.to_sym, value end end +Dir['./spec/support/spec/**/*.rb'].sort.each { |f| require f } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index d3b906bf..669ccaff 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,8 +1,14 @@ -# Managed by modulesync - DO NOT EDIT -# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ +# frozen_string_literal: true require 'voxpupuli/acceptance/spec_helper_acceptance' -configure_beaker +configure_beaker do |host| + case fact('os.family') + when 'Debian' + install_puppet_module_via_pmt_on(host, 'puppetlabs-apt') + when 'RedHat' + install_puppet_module_via_pmt_on(host, 'puppet-epel') + end +end Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f } diff --git a/spec/support/acceptance/shared_examples.rb b/spec/support/acceptance/shared_examples.rb index f3b7627f..ce231dcc 100644 --- a/spec/support/acceptance/shared_examples.rb +++ b/spec/support/acceptance/shared_examples.rb @@ -1,9 +1,19 @@ -shared_examples 'an idempotent resource' do - it 'applies with no errors' do - apply_manifest(pp, catch_failures: true) - end +# frozen_string_literal: true - it 'applies a second time without changes' do - apply_manifest(pp, catch_changes: true) +shared_examples 'cleanup' do + context 'cleanup' do + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'nodejs': + nodejs_debug_package_ensure => purged, + nodejs_dev_package_ensure => purged, + nodejs_package_ensure => purged, + npm_package_ensure => purged, + repo_ensure => absent, + } + PUPPET + end + end end end diff --git a/spec/unit/puppet/provider/package/npm_spec.rb b/spec/unit/puppet/provider/package/npm_spec.rb index a9f0d7ff..f96ead57 100644 --- a/spec/unit/puppet/provider/package/npm_spec.rb +++ b/spec/unit/puppet/provider/package/npm_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Puppet::Type.type(:package).provider(:npm) do @@ -21,7 +23,7 @@ def self.it_should_respond_to(*actions) actions.each do |action| - it "should respond to :#{action}" do + it "responds to :#{action}" do expect(provider).to respond_to(action) end end