From ecef55b7559f9160b3eadf7cf5d2cbb9fdbbc4d6 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Mon, 30 Oct 2023 09:50:17 +0100 Subject: [PATCH] test different NodeJS versions using beaker_facter --- .github/workflows/ci.yml | 1 + .sync.yml | 2 ++ spec/acceptance/class_spec.rb | 38 +++++++++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b66d8ca7..21b6ad03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,3 +16,4 @@ jobs: uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v2 with: pidfile_workaround: 'false' + beaker_facter: 'nodejs_version:NodeJS:16,18,20' diff --git a/.sync.yml b/.sync.yml index 4cf442c8..6520a600 100644 --- a/.sync.yml +++ b/.sync.yml @@ -3,3 +3,5 @@ spec/spec_helper.rb: mock_with: ':mocha' spec/spec_helper_acceptance.rb: unmanaged: true +.github/workflows/ci.yml: + beaker_facter: 'nodejs_version:NodeJS:16,18,20' diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index a57e1298..b80ff9f9 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -10,6 +10,8 @@ pkg_cmd = 'dpkg -s nodejs | grep "^Maintainer"' end + nodejs_version = fact('nodejs_version') || '20' + context 'default parameters' do it_behaves_like 'an idempotent resource' do let(:manifest) { "class { 'nodejs': }" } @@ -27,6 +29,34 @@ end end + context "explicitly using version #{nodejs_version} from nodesource", if: %w[RedHat Debian].include? fact('os.family') do + include_examples 'cleanup' + + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'nodejs': + repo_version => '#{nodejs_version}' + } + PUPPET + end + end + + 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' + end + end + + describe command('node --version') do + its(:exit_status) { is_expected.to eq 0 } + its(:stdout) { is_expected.to match(%r{^v#{nodejs_version}}) } + end + end + context 'RedHat with repo_class => epel', if: fact('os.family') == 'RedHat' do include_examples 'cleanup' @@ -66,11 +96,11 @@ class { 'nodejs': end context 'RedHat with repo_class => nodejs::repo::dnfmodule', if: fact('os.family') == 'RedHat' && %w[8 9].include?(fact('os.release.major')) do - include_examples 'cleanup' - # Node 20 is only available in Stream yet, not in a released EL - # So we're testing 18 here - nodejs_version = '18' + # So we're not testing it here yet + skip if nodejs_version == '20' && fact('os.name') != 'CentOS' + + include_examples 'cleanup' it_behaves_like 'an idempotent resource' do let(:manifest) do