Skip to content

Commit

Permalink
Debian and Ubuntu versioning and package name fixes
Browse files Browse the repository at this point in the history
* Debian has a native nodejs dev package, so define that.

* Debian 10 has a native npm package, so define that for Debian 10.

* Improve native_debian_devel_package logic: support Debian 10 onward
  and Ubuntu 20.04 onward with the libnode-dev package name.

* After the above changes, the variable is_supported_debian_version
  becomes obsolete, so most of the tests can work normally. The only
  special case is Debian 9 lacking the native npm package.
  • Loading branch information
kenyon committed Nov 1, 2020
1 parent b326a60 commit 70a7510
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
12 changes: 10 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@
case $facts['os']['family'] {
'Debian': {
if $facts['os']['release']['major'] =~ /^(9|10)$/ {
$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 = undef
$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 = false
$npm_package_name = $debian_npm_package_name
$npm_path = '/usr/bin/npm'
$repo_class = '::nodejs::repo::nodesource'
}
Expand Down
42 changes: 12 additions & 30 deletions spec/classes/nodejs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
facts
end

is_supported_debian_version = if facts[:os]['family'] == 'Debian' && %w[9 10].include?(facts[:os]['release']['major'])
true
else
false
end

native_debian_devel_package = if facts[:os]['name'] == 'Ubuntu' && facts[:os]['release']['major'] == '20.04'
'libnode-dev'
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
Expand Down Expand Up @@ -199,15 +195,8 @@
}
end

if is_supported_debian_version

it 'the nodejs development package resource should not be present' do
is_expected.not_to contain_package(native_debian_devel_package)
end
else
it 'the nodejs development package should be installed' do
is_expected.to contain_package(native_debian_devel_package).with('ensure' => 'present')
end
it 'the nodejs development package should be installed' do
is_expected.to contain_package(native_debian_devel_package).with('ensure' => 'present')
end
end

Expand All @@ -218,15 +207,8 @@
}
end

if is_supported_debian_version

it 'the nodejs development package resource should not be present' do
is_expected.not_to contain_package(native_debian_devel_package)
end
else
it 'the nodejs development package should not be present' do
is_expected.to contain_package(native_debian_devel_package).with('ensure' => 'absent')
end
it 'the nodejs development package should not be present' do
is_expected.to contain_package(native_debian_devel_package).with('ensure' => 'absent')
end
end

Expand Down Expand Up @@ -263,8 +245,8 @@
}
end

if is_supported_debian_version

# 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
Expand All @@ -282,8 +264,8 @@
}
end

if is_supported_debian_version

# 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
Expand Down

0 comments on commit 70a7510

Please sign in to comment.