-
-
Notifications
You must be signed in to change notification settings - Fork 246
/
class_spec.rb
235 lines (199 loc) · 6.5 KB
/
class_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# frozen_string_literal: true
require 'spec_helper_acceptance'
def nodesource_unsupported(nodejs_version)
return unless fact('os.family') == 'RedHat'
return 'Only NodeJS 16 is supported on EL7' if nodejs_version != '16' && fact('os.release.major') == '7'
return 'NodeJS 16 is not supported on EL9' if nodejs_version == '16' && fact('os.release.major') == '9'
end
describe 'nodejs' do
case fact('os.family')
when 'RedHat'
pkg_cmd = 'yum info nodejs | grep "^From repo"'
when 'Debian'
pkg_cmd = 'dpkg -s nodejs | grep "^Maintainer"'
end
nodejs_version = ENV.fetch('BEAKER_FACTER_nodejs_version', '20')
context 'default parameters' do
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'
end
end
end
end
context "explicitly using version #{nodejs_version} from nodesource", if: %w[RedHat Debian].include?(fact('os.family')), skip: nodesource_unsupported(nodejs_version) do
# Only nodejs 16 is supported on EL7 by nodesource
include_examples 'cleanup'
# Debian 12 contains NodeJS 18, when we test 16 and 18, we need to force the nodesource version
# as Debians versions *can* be newer
repo_pin =
if %w[16 18].include?(nodejs_version) && fact('os.family') == 'Debian' && fact('os.release.major') == '12'
'1000'
else
'undef'
end
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'nodejs':
repo_version => '#{nodejs_version}',
repo_pin => #{repo_pin},
}
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'
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
let(:manifest) do
<<-PUPPET
class { 'nodejs':
nodejs_dev_package_ensure => #{nodejs_dev_package_ensure},
npm_package_ensure => installed,
repo_class => 'epel',
}
PUPPET
end
end
%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 'RedHat with repo_class => nodejs::repo::dnfmodule', if: fact('os.family') == 'RedHat' && %w[8 9].include?(fact('os.release.major')), skip: (nodejs_version == '16' && fact('os.release.major') == '9' ? 'NodeJS 16 is not available on EL9' : nil) do
# Node 16 is not available on EL9
include_examples 'cleanup'
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'nodejs':
nodejs_dev_package_ensure => installed,
npm_package_ensure => installed,
repo_class => 'nodejs::repo::dnfmodule',
repo_version => '#{nodejs_version}',
}
PUPPET
end
end
%w[
npm
nodejs
nodejs-devel
].each do |pkg|
describe package(pkg) do
it do
is_expected.to be_installed
end
it 'comes from the expected source' do
pkg_output = shell(pkg_cmd)
expect(pkg_output.stdout).to match 'appstream'
end
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 'Debian distribution packages', if: fact('os.family') == 'Debian' do
before(:context) { purge_node }
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
%w[
libnode-dev
npm
].each do |pkg|
describe package(pkg) do
it { is_expected.to be_installed }
end
end
end
context 'set global_config_entry secret' do
before(:context) { purge_node }
include_examples 'cleanup'
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'nodejs': }
nodejs::npm::global_config_entry { '//path.to.registry/:_authToken':
ensure => present,
value => 'cGFzc3dvcmQ=',
require => Package[nodejs],
}
PUPPET
end
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/:_authToken="cGFzc3dvcmQ="'
end
end
end
context 'set global_config_entry secret unquoted' do
before(:context) { purge_node }
include_examples 'cleanup'
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'nodejs': }
nodejs::npm::global_config_entry { '//path.to.registry/:_authToken':
ensure => present,
value => 'cGFzc3dvcmQ',
require => Package[nodejs],
}
PUPPET
end
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/:_authToken=cGFzc3dvcmQ'
end
end
end
end