Skip to content

Commit

Permalink
shared examples: remove 'an idempotent resource'
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kenyon committed Sep 17, 2023
1 parent 509eb4b commit 5571526
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 61 deletions.
86 changes: 48 additions & 38 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
36 changes: 13 additions & 23 deletions spec/support/acceptance/shared_examples.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5571526

Please sign in to comment.