From 5571526361430550b61714cf3cb548b3e2fc3dad Mon Sep 17 00:00:00 2001 From: Kenyon Ralph Date: Sun, 17 Sep 2023 13:16:27 -0700 Subject: [PATCH] shared examples: remove 'an idempotent resource' Use the shared example provided by https://github.com/voxpupuli/voxpupuli-acceptance/blob/730a129a9b5a9fc660f016e74e67dc3be9b4968a/lib/voxpupuli/acceptance/examples.rb instead. This also removes test code for EOL Debian-family. --- spec/acceptance/class_spec.rb | 86 ++++++++++++---------- spec/support/acceptance/shared_examples.rb | 36 ++++----- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index d154cbe3..daf084a4 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -11,9 +11,9 @@ 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 @@ -28,11 +28,16 @@ end context 'repo_class => epel', if: ((fact('os.family') == 'RedHat') && (fact('os.release.major') != '8')) do - let(:pp) { "class { 'nodejs': repo_class => '::epel' }" } - include_examples 'cleanup' - it_behaves_like 'an idempotent resource' + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'nodejs': + repo_class => '::epel', + } + PUPPET + end describe package('nodejs') do it { is_expected.to be_installed } @@ -45,12 +50,19 @@ 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],}" + 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 - it_behaves_like 'an idempotent resource' - describe package('nodejs') do it { is_expected.to be_installed } end @@ -64,12 +76,19 @@ 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],}" + 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 - it_behaves_like 'an idempotent resource' - describe package('nodejs') do it { is_expected.to be_installed } end @@ -84,34 +103,25 @@ end context 'native Debian packages' do - let(:pp) do - " - class { 'nodejs': - manage_package_repo => false, - nodejs_dev_package_ensure => present, - npm_package_ensure => present, - } - " - end - include_examples 'cleanup' - it_behaves_like 'an idempotent resource' - - expected_packages = [] - - if fact('os.family') == 'Debian' - if %w[9 16.04 18.04].include? fact('os.release.major') - expected_packages << 'nodejs-dev' - - expected_packages << 'npm' if %w[16.04 18.04].include? fact('os.release.major') - else - expected_packages << 'libnode-dev' - - expected_packages << 'npm' + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'nodejs': + manage_package_repo => false, + nodejs_dev_package_ensure => present, + npm_package_ensure => present, + } + PUPPET end + end - expected_packages.each do |pkg| + if fact('os.family') == 'Debian' + [ + 'libnode-dev', + 'npm', + ].each do |pkg| describe package(pkg) do it { is_expected.to be_installed } end diff --git a/spec/support/acceptance/shared_examples.rb b/spec/support/acceptance/shared_examples.rb index 2e2d41f7..d8346fa8 100644 --- a/spec/support/acceptance/shared_examples.rb +++ b/spec/support/acceptance/shared_examples.rb @@ -1,31 +1,21 @@ # frozen_string_literal: true -shared_examples 'an idempotent resource' do - it 'applies with no errors' do - apply_manifest(pp, catch_failures: true) - end - - it 'applies a second time without changes' do - apply_manifest(pp, catch_changes: true) - end -end - shared_examples 'cleanup' do context 'cleanup' 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, - } - " + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'nodejs': + nodejs_debug_package_ensure => absent, + nodejs_dev_package_ensure => absent, + nodejs_package_ensure => absent, + npm_package_ensure => absent, + repo_ensure => absent, + } + PUPPET + end end - it_behaves_like 'an idempotent resource' - - shell('yum info nodejs || true') + shell('yum info nodejs || true') # TODO: remove debugging output end end