rspec-puppet 2.11.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +154 -469
- data/README.md +71 -168
- data/bin/rspec-puppet-init +4 -3
- data/lib/rspec-puppet/adapters.rb +84 -230
- data/lib/rspec-puppet/cache.rb +3 -2
- data/lib/rspec-puppet/consts.rb +16 -14
- data/lib/rspec-puppet/coverage.rb +37 -42
- data/lib/rspec-puppet/errors.rb +6 -6
- data/lib/rspec-puppet/example/class_example_group.rb +3 -1
- data/lib/rspec-puppet/example/define_example_group.rb +3 -1
- data/lib/rspec-puppet/example/function_example_group.rb +42 -57
- data/lib/rspec-puppet/example/host_example_group.rb +3 -1
- data/lib/rspec-puppet/example/provider_example_group.rb +2 -0
- data/lib/rspec-puppet/example/type_alias_example_group.rb +4 -2
- data/lib/rspec-puppet/example/type_example_group.rb +3 -1
- data/lib/rspec-puppet/example.rb +6 -9
- data/lib/rspec-puppet/facter_impl.rb +11 -10
- data/lib/rspec-puppet/matchers/allow_value.rb +10 -10
- data/lib/rspec-puppet/matchers/compile.rb +54 -61
- data/lib/rspec-puppet/matchers/count_generic.rb +18 -18
- data/lib/rspec-puppet/matchers/create_generic.rb +69 -79
- data/lib/rspec-puppet/matchers/dynamic_matchers.rb +15 -4
- data/lib/rspec-puppet/matchers/include_class.rb +5 -4
- data/lib/rspec-puppet/matchers/parameter_matcher.rb +11 -12
- data/lib/rspec-puppet/matchers/raise_error.rb +5 -1
- data/lib/rspec-puppet/matchers/run.rb +41 -42
- data/lib/rspec-puppet/matchers/type_matchers.rb +37 -48
- data/lib/rspec-puppet/matchers.rb +2 -0
- data/lib/rspec-puppet/monkey_patches/win32/registry.rb +7 -5
- data/lib/rspec-puppet/monkey_patches/win32/taskscheduler.rb +3 -1
- data/lib/rspec-puppet/monkey_patches/windows/taskschedulerconstants.rb +208 -205
- data/lib/rspec-puppet/monkey_patches.rb +80 -93
- data/lib/rspec-puppet/rake_task.rb +6 -4
- data/lib/rspec-puppet/raw_string.rb +2 -0
- data/lib/rspec-puppet/sensitive.rb +31 -39
- data/lib/rspec-puppet/setup.rb +45 -56
- data/lib/rspec-puppet/spec_helper.rb +2 -3
- data/lib/rspec-puppet/support.rb +129 -177
- data/lib/rspec-puppet/tasks/release_test.rb +8 -5
- data/lib/rspec-puppet/version.rb +5 -0
- data/lib/rspec-puppet.rb +37 -61
- metadata +18 -15
- data/lib/rspec-puppet/example/application_example_group.rb +0 -19
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require 'rspec-puppet'
|
|
4
4
|
|
|
5
5
|
RSpec.configure do |c|
|
|
6
6
|
c.module_path = File.join(fixture_path, 'modules')
|
|
7
|
-
c.manifest_dir = File.join(fixture_path, 'manifests')
|
|
8
7
|
c.manifest = File.join(fixture_path, 'manifests', 'site.pp')
|
|
9
8
|
c.environmentpath = File.join(Dir.pwd, 'spec')
|
|
10
9
|
end
|
data/lib/rspec-puppet/support.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rspec-puppet/cache'
|
|
2
4
|
require 'rspec-puppet/adapters'
|
|
3
5
|
require 'rspec-puppet/raw_string'
|
|
@@ -11,7 +13,7 @@ module RSpec::Puppet
|
|
|
11
13
|
@@fixture_hiera_configs = Hash.new { |h, k| h[k] = nil }
|
|
12
14
|
|
|
13
15
|
def subject
|
|
14
|
-
|
|
16
|
+
-> { catalogue }
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def environment
|
|
@@ -19,42 +21,36 @@ module RSpec::Puppet
|
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def build_code(type, manifest_opts)
|
|
22
|
-
|
|
23
|
-
[site_pp_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n")
|
|
24
|
-
else
|
|
25
|
-
[import_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n")
|
|
26
|
-
end
|
|
24
|
+
[site_pp_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n")
|
|
27
25
|
end
|
|
28
26
|
|
|
29
27
|
def guess_type_from_path(path)
|
|
30
28
|
case path
|
|
31
|
-
when /
|
|
29
|
+
when %r{spec/defines}
|
|
32
30
|
:define
|
|
33
|
-
when /
|
|
31
|
+
when %r{spec/classes}
|
|
34
32
|
:class
|
|
35
|
-
when /
|
|
33
|
+
when %r{spec/functions}
|
|
36
34
|
:function
|
|
37
|
-
when /
|
|
35
|
+
when %r{spec/hosts}
|
|
38
36
|
:host
|
|
39
|
-
when /
|
|
37
|
+
when %r{spec/types}
|
|
40
38
|
:type
|
|
41
|
-
when /
|
|
39
|
+
when %r{spec/type_aliases}
|
|
42
40
|
:type_alias
|
|
43
|
-
when /
|
|
41
|
+
when %r{spec/provider}
|
|
44
42
|
:provider
|
|
45
|
-
when /spec\/applications/
|
|
46
|
-
:application
|
|
47
43
|
else
|
|
48
44
|
:unknown
|
|
49
45
|
end
|
|
50
46
|
end
|
|
51
47
|
|
|
52
48
|
def stub_file_consts(example)
|
|
53
|
-
if example.respond_to?(:metadata)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
type = if example.respond_to?(:metadata)
|
|
50
|
+
example.metadata[:type]
|
|
51
|
+
else
|
|
52
|
+
guess_type_from_path(example.example.metadata[:file_path])
|
|
53
|
+
end
|
|
58
54
|
|
|
59
55
|
munged_facts = facts_hash(nodename(type))
|
|
60
56
|
|
|
@@ -64,15 +60,15 @@ module RSpec::Puppet
|
|
|
64
60
|
|
|
65
61
|
def find_pretend_platform(test_facts)
|
|
66
62
|
from_value = lambda { |value|
|
|
67
|
-
value.to_s.
|
|
63
|
+
value.to_s.casecmp('windows').zero? ? :windows : :posix
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
[
|
|
66
|
+
%w[operatingsystem osfamily].each do |os_fact|
|
|
71
67
|
return from_value.call(test_facts[os_fact]) if test_facts.key?(os_fact)
|
|
72
68
|
end
|
|
73
69
|
|
|
74
70
|
if test_facts.key?('os') && test_facts['os'].is_a?(Hash)
|
|
75
|
-
[
|
|
71
|
+
%w[name family].each do |os_hash_key|
|
|
76
72
|
return from_value.call(test_facts['os'][os_hash_key]) if test_facts['os'].key?(os_hash_key)
|
|
77
73
|
end
|
|
78
74
|
end
|
|
@@ -80,20 +76,18 @@ module RSpec::Puppet
|
|
|
80
76
|
nil
|
|
81
77
|
end
|
|
82
78
|
|
|
83
|
-
|
|
84
79
|
def load_catalogue(type, exported = false, manifest_opts = {})
|
|
85
80
|
with_vardir do
|
|
86
81
|
node_name = nodename(type)
|
|
87
82
|
|
|
88
|
-
hiera_config_value =
|
|
89
|
-
hiera_data_value =
|
|
83
|
+
hiera_config_value = respond_to?(:hiera_config) ? hiera_config : nil
|
|
84
|
+
hiera_data_value = respond_to?(:hiera_data) ? hiera_data : nil
|
|
90
85
|
|
|
91
|
-
rspec_config_values = [
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
:fallback_to_default_hiera,
|
|
86
|
+
rspec_config_values = %i[
|
|
87
|
+
disable_module_hiera
|
|
88
|
+
use_fixture_spec_hiera
|
|
89
|
+
fixture_hiera_configs
|
|
90
|
+
fallback_to_default_hiera
|
|
97
91
|
].map { |setting| RSpec.configuration.send(setting) }
|
|
98
92
|
|
|
99
93
|
build_facts = facts_hash(node_name)
|
|
@@ -108,7 +102,7 @@ module RSpec::Puppet
|
|
|
108
102
|
trusted_external_data: trusted_external_data_hash,
|
|
109
103
|
ignored_cache_params: {
|
|
110
104
|
hiera_data_value: hiera_data_value,
|
|
111
|
-
rspec_config_values: rspec_config_values
|
|
105
|
+
rspec_config_values: rspec_config_values
|
|
112
106
|
}
|
|
113
107
|
)
|
|
114
108
|
|
|
@@ -127,30 +121,6 @@ module RSpec::Puppet
|
|
|
127
121
|
end
|
|
128
122
|
end
|
|
129
123
|
|
|
130
|
-
def import_str
|
|
131
|
-
import_str = ""
|
|
132
|
-
adapter.modulepath.each { |d|
|
|
133
|
-
if File.exists?(File.join(d, 'manifests', 'init.pp'))
|
|
134
|
-
path_to_manifest = File.join([
|
|
135
|
-
d,
|
|
136
|
-
'manifests',
|
|
137
|
-
class_name.split('::')[1..-1]
|
|
138
|
-
].flatten)
|
|
139
|
-
import_str = [
|
|
140
|
-
"import '#{d}/manifests/init.pp'",
|
|
141
|
-
"import '#{path_to_manifest}.pp'",
|
|
142
|
-
'',
|
|
143
|
-
].join("\n")
|
|
144
|
-
break
|
|
145
|
-
elsif File.exists?(d)
|
|
146
|
-
import_str = "import '#{adapter.manifest}'\n"
|
|
147
|
-
break
|
|
148
|
-
end
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
import_str
|
|
152
|
-
end
|
|
153
|
-
|
|
154
124
|
def site_pp_str
|
|
155
125
|
return '' unless (path = adapter.manifest)
|
|
156
126
|
|
|
@@ -167,34 +137,29 @@ module RSpec::Puppet
|
|
|
167
137
|
end
|
|
168
138
|
|
|
169
139
|
def test_manifest(type, opts = {})
|
|
170
|
-
opts[:params] = params if
|
|
140
|
+
opts[:params] = params if respond_to?(:params)
|
|
171
141
|
|
|
172
|
-
|
|
142
|
+
case type
|
|
143
|
+
when :class
|
|
173
144
|
if opts[:params].nil? || opts[:params] == {}
|
|
174
145
|
"include #{class_name}"
|
|
175
146
|
else
|
|
176
147
|
"class { '#{class_name}': #{param_str(opts[:params])} }"
|
|
177
148
|
end
|
|
178
|
-
|
|
179
|
-
if opts.has_key?(:params)
|
|
180
|
-
"site { #{class_name} { #{sanitise_resource_title(title)}: #{param_str(opts[:params])} } }"
|
|
181
|
-
else
|
|
182
|
-
raise ArgumentError, "You need to provide params for an application"
|
|
183
|
-
end
|
|
184
|
-
elsif type == :define
|
|
149
|
+
when :define
|
|
185
150
|
title_str = if title.is_a?(Array)
|
|
186
151
|
'[' + title.map { |r| sanitise_resource_title(r) }.join(', ') + ']'
|
|
187
152
|
else
|
|
188
153
|
sanitise_resource_title(title)
|
|
189
154
|
end
|
|
190
|
-
if opts.
|
|
155
|
+
if opts.key?(:params)
|
|
191
156
|
"#{class_name} { #{title_str}: #{param_str(opts[:params])} }"
|
|
192
157
|
else
|
|
193
158
|
"#{class_name} { #{title_str}: }"
|
|
194
159
|
end
|
|
195
|
-
|
|
160
|
+
when :host
|
|
196
161
|
nil
|
|
197
|
-
|
|
162
|
+
when :type_alias
|
|
198
163
|
"$test = #{str_from_value(opts[:test_value])}\nassert_type(#{self.class.top_level_description}, $test)"
|
|
199
164
|
end
|
|
200
165
|
end
|
|
@@ -204,8 +169,9 @@ module RSpec::Puppet
|
|
|
204
169
|
end
|
|
205
170
|
|
|
206
171
|
def nodename(type)
|
|
207
|
-
return node if
|
|
208
|
-
|
|
172
|
+
return node if respond_to?(:node)
|
|
173
|
+
|
|
174
|
+
if %i[class define function].include? type
|
|
209
175
|
Puppet[:certname]
|
|
210
176
|
else
|
|
211
177
|
class_name
|
|
@@ -217,47 +183,51 @@ module RSpec::Puppet
|
|
|
217
183
|
end
|
|
218
184
|
|
|
219
185
|
def pre_cond
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
pre_condition
|
|
225
|
-
end
|
|
186
|
+
return unless respond_to?(:pre_condition) && !pre_condition.nil?
|
|
187
|
+
|
|
188
|
+
if pre_condition.is_a? Array
|
|
189
|
+
pre_condition.compact.join("\n")
|
|
226
190
|
else
|
|
227
|
-
|
|
191
|
+
pre_condition
|
|
228
192
|
end
|
|
229
193
|
end
|
|
230
194
|
|
|
231
195
|
def post_cond
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
post_condition
|
|
237
|
-
end
|
|
196
|
+
return unless respond_to?(:post_condition) && !post_condition.nil?
|
|
197
|
+
|
|
198
|
+
if post_condition.is_a? Array
|
|
199
|
+
post_condition.compact.join("\n")
|
|
238
200
|
else
|
|
239
|
-
|
|
201
|
+
post_condition
|
|
240
202
|
end
|
|
241
203
|
end
|
|
242
204
|
|
|
243
205
|
def facts_hash(node)
|
|
244
206
|
base_facts = {
|
|
245
207
|
'clientversion' => Puppet::PUPPETVERSION,
|
|
246
|
-
'environment'
|
|
208
|
+
'environment' => environment.to_s
|
|
247
209
|
}
|
|
248
210
|
|
|
249
211
|
node_facts = {
|
|
250
|
-
'hostname'
|
|
251
|
-
'fqdn'
|
|
252
|
-
'domain'
|
|
253
|
-
'clientcert' => node
|
|
254
|
-
'ipaddress6' => 'FE80:0000:0000:0000:AAAA:AAAA:AAAA',
|
|
212
|
+
'hostname' => node.split('.').first,
|
|
213
|
+
'fqdn' => node,
|
|
214
|
+
'domain' => node.split('.', 2).last,
|
|
215
|
+
'clientcert' => node
|
|
255
216
|
}
|
|
256
217
|
|
|
218
|
+
# Puppet 6.9.0 started setting a `serverip6` server fact which is set
|
|
219
|
+
# using the value of the `ipaddress6` fact. If the fact set(s) provided
|
|
220
|
+
# by FacterDB don't have an `ipaddress6` fact set, then the normal Facter
|
|
221
|
+
# fact will be resolved, which can result in Ruby trying to load Windows
|
|
222
|
+
# only gems on Linux. This is only a problem if facter is used.
|
|
223
|
+
if RSpec.configuration.facter_implementation.to_sym == :facter
|
|
224
|
+
node_facts['ipaddress6'] = 'FE80:0000:0000:0000:AAAA:AAAA:AAAA'
|
|
225
|
+
end
|
|
226
|
+
|
|
257
227
|
networking_facts = {
|
|
258
228
|
'hostname' => node_facts['hostname'],
|
|
259
|
-
'fqdn'
|
|
260
|
-
'domain'
|
|
229
|
+
'fqdn' => node_facts['fqdn'],
|
|
230
|
+
'domain' => node_facts['domain']
|
|
261
231
|
}
|
|
262
232
|
|
|
263
233
|
result_facts = if RSpec.configuration.default_facts.any?
|
|
@@ -269,11 +239,13 @@ module RSpec::Puppet
|
|
|
269
239
|
# Merge in node facts so they always exist by default, but only if they
|
|
270
240
|
# haven't been defined in `RSpec.configuration.default_facts`
|
|
271
241
|
result_facts.merge!(munge_facts(node_facts)) { |_key, old_val, new_val| old_val.nil? ? new_val : old_val }
|
|
272
|
-
(result_facts['networking'] ||= {}).merge!(networking_facts)
|
|
242
|
+
(result_facts['networking'] ||= {}).merge!(networking_facts) do |_key, old_val, new_val|
|
|
243
|
+
old_val.nil? ? new_val : old_val
|
|
244
|
+
end
|
|
273
245
|
|
|
274
246
|
# Merge in `let(:facts)` facts
|
|
275
247
|
result_facts.merge!(munge_facts(base_facts))
|
|
276
|
-
result_facts.merge!(munge_facts(facts)) if
|
|
248
|
+
result_facts.merge!(munge_facts(facts)) if respond_to?(:facts)
|
|
277
249
|
|
|
278
250
|
# Merge node facts again on top of `let(:facts)` facts, but only if
|
|
279
251
|
# a node name is given with `let(:node)`
|
|
@@ -284,8 +256,7 @@ module RSpec::Puppet
|
|
|
284
256
|
|
|
285
257
|
# Facter currently supports lower case facts. Bug FACT-777 has been submitted to support case sensitive
|
|
286
258
|
# facts.
|
|
287
|
-
|
|
288
|
-
downcase_facts
|
|
259
|
+
result_facts.transform_keys(&:downcase)
|
|
289
260
|
end
|
|
290
261
|
|
|
291
262
|
def node_params_hash
|
|
@@ -301,29 +272,25 @@ module RSpec::Puppet
|
|
|
301
272
|
param_str_from_hash(params)
|
|
302
273
|
end
|
|
303
274
|
|
|
304
|
-
def trusted_facts_hash(
|
|
305
|
-
return {} unless Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
|
|
306
|
-
|
|
275
|
+
def trusted_facts_hash(_node_name)
|
|
307
276
|
extensions = {}
|
|
308
277
|
|
|
309
278
|
if RSpec.configuration.default_trusted_facts.any?
|
|
310
279
|
extensions.merge!(munge_facts(RSpec.configuration.default_trusted_facts))
|
|
311
280
|
end
|
|
312
281
|
|
|
313
|
-
extensions.merge!(munge_facts(trusted_facts)) if
|
|
282
|
+
extensions.merge!(munge_facts(trusted_facts)) if respond_to?(:trusted_facts)
|
|
314
283
|
extensions
|
|
315
284
|
end
|
|
316
285
|
|
|
317
286
|
def trusted_external_data_hash
|
|
318
|
-
return {} unless Puppet::Util::Package.versioncmp(Puppet.version, '6.14.0') >= 0
|
|
319
|
-
|
|
320
287
|
external_data = {}
|
|
321
288
|
|
|
322
289
|
if RSpec.configuration.default_trusted_external_data.any?
|
|
323
290
|
external_data.merge!(munge_facts(RSpec.configuration.default_trusted_external_data))
|
|
324
291
|
end
|
|
325
292
|
|
|
326
|
-
external_data.merge!(munge_facts(trusted_external_data)) if
|
|
293
|
+
external_data.merge!(munge_facts(trusted_external_data)) if respond_to?(:trusted_external_data)
|
|
327
294
|
external_data
|
|
328
295
|
end
|
|
329
296
|
|
|
@@ -331,26 +298,25 @@ module RSpec::Puppet
|
|
|
331
298
|
server_facts = {}
|
|
332
299
|
|
|
333
300
|
# Add our server version to the fact list
|
|
334
|
-
server_facts[
|
|
301
|
+
server_facts['serverversion'] = Puppet.version.to_s
|
|
335
302
|
|
|
336
303
|
# And then add the server name and IP
|
|
337
|
-
{
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if value = FacterImpl.value(fact)
|
|
304
|
+
{ 'servername' => 'fqdn',
|
|
305
|
+
'serverip' => 'ipaddress' }.each do |var, fact|
|
|
306
|
+
if (value = Puppet.runtime[:facter].value(fact))
|
|
341
307
|
server_facts[var] = value
|
|
342
308
|
else
|
|
343
309
|
warn "Could not retrieve fact #{fact}"
|
|
344
310
|
end
|
|
345
311
|
end
|
|
346
312
|
|
|
347
|
-
if server_facts[
|
|
348
|
-
host =
|
|
349
|
-
if domain =
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
313
|
+
if server_facts['servername'].nil?
|
|
314
|
+
host = Puppet.runtime[:facter].value(:hostname)
|
|
315
|
+
server_facts['servername'] = if (domain = Puppet.runtime[:facter].value(:domain))
|
|
316
|
+
[host, domain].join('.')
|
|
317
|
+
else
|
|
318
|
+
host
|
|
319
|
+
end
|
|
354
320
|
end
|
|
355
321
|
server_facts
|
|
356
322
|
end
|
|
@@ -358,19 +324,19 @@ module RSpec::Puppet
|
|
|
358
324
|
def str_from_value(value)
|
|
359
325
|
case value
|
|
360
326
|
when Hash
|
|
361
|
-
kvs = value.collect do |k,v|
|
|
327
|
+
kvs = value.collect do |k, v|
|
|
362
328
|
"#{str_from_value(k)} => #{str_from_value(v)}"
|
|
363
|
-
end.join(
|
|
329
|
+
end.join(', ')
|
|
364
330
|
"{ #{kvs} }"
|
|
365
331
|
when Array
|
|
366
332
|
vals = value.map do |v|
|
|
367
333
|
str_from_value(v)
|
|
368
|
-
end.join(
|
|
334
|
+
end.join(', ')
|
|
369
335
|
"[ #{vals} ]"
|
|
370
336
|
when :default
|
|
371
|
-
'default'
|
|
337
|
+
'default' # verbatim default keyword
|
|
372
338
|
when :undef
|
|
373
|
-
'undef'
|
|
339
|
+
'undef' # verbatim undef keyword
|
|
374
340
|
when Symbol
|
|
375
341
|
str_from_value(value.to_s)
|
|
376
342
|
else
|
|
@@ -381,8 +347,8 @@ module RSpec::Puppet
|
|
|
381
347
|
def param_str_from_hash(params_hash)
|
|
382
348
|
# the param_str has special quoting rules, because the top-level keys are the Puppet
|
|
383
349
|
# params, which may not be quoted
|
|
384
|
-
params_hash.collect do |k,v|
|
|
385
|
-
"#{k
|
|
350
|
+
params_hash.collect do |k, v|
|
|
351
|
+
"#{k} => #{str_from_value(v)}"
|
|
386
352
|
end.join(', ')
|
|
387
353
|
end
|
|
388
354
|
|
|
@@ -390,11 +356,6 @@ module RSpec::Puppet
|
|
|
390
356
|
vardir = Dir.mktmpdir
|
|
391
357
|
Puppet[:vardir] = vardir
|
|
392
358
|
|
|
393
|
-
# Enable app_management by default for Puppet versions that support it
|
|
394
|
-
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 && Puppet.version.to_i < 5
|
|
395
|
-
Puppet[:app_management] = ENV.include?('PUPPET_NOAPP_MANAGMENT') ? false : true
|
|
396
|
-
end
|
|
397
|
-
|
|
398
359
|
adapter.modulepath.map do |d|
|
|
399
360
|
Dir["#{d}/*/lib"].entries
|
|
400
361
|
end.flatten.each do |lib|
|
|
@@ -405,25 +366,24 @@ module RSpec::Puppet
|
|
|
405
366
|
end
|
|
406
367
|
|
|
407
368
|
def with_vardir
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
FileUtils.rm_rf(vardir) if vardir && File.directory?(vardir)
|
|
413
|
-
end
|
|
369
|
+
vardir = setup_puppet
|
|
370
|
+
yield(vardir) if block_given?
|
|
371
|
+
ensure
|
|
372
|
+
FileUtils.rm_rf(vardir) if vardir && File.directory?(vardir)
|
|
414
373
|
end
|
|
415
374
|
|
|
416
|
-
def build_catalog_without_cache(nodename, facts_val, trusted_facts_val, hiera_config_val, code, exported,
|
|
375
|
+
def build_catalog_without_cache(nodename, facts_val, trusted_facts_val, hiera_config_val, code, exported,
|
|
376
|
+
node_params, *_)
|
|
417
377
|
build_catalog_without_cache_v2({
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
378
|
+
nodename: nodename,
|
|
379
|
+
facts_val: facts_val,
|
|
380
|
+
trusted_facts_val: trusted_facts_val,
|
|
381
|
+
hiera_config_val: hiera_config_val,
|
|
382
|
+
code: code,
|
|
383
|
+
exported: exported,
|
|
384
|
+
node_params: node_params,
|
|
385
|
+
trusted_external: {}
|
|
386
|
+
})
|
|
427
387
|
end
|
|
428
388
|
|
|
429
389
|
def build_catalog_without_cache_v2(
|
|
@@ -445,7 +405,7 @@ module RSpec::Puppet
|
|
|
445
405
|
# It would be nice if Puppet offered a public API for invalidating their
|
|
446
406
|
# cached instance of Hiera, but que sera sera. We will go directly against
|
|
447
407
|
# the implementation out of absolute necessity.
|
|
448
|
-
HieraPuppet.instance_variable_set(
|
|
408
|
+
HieraPuppet.instance_variable_set(:@hiera, nil) if defined? HieraPuppet
|
|
449
409
|
|
|
450
410
|
Puppet[:code] = code
|
|
451
411
|
|
|
@@ -456,30 +416,26 @@ module RSpec::Puppet
|
|
|
456
416
|
node_facts = Puppet::Node::Facts.new(nodename, facts_val.dup)
|
|
457
417
|
node_params = facts_val.merge(node_params)
|
|
458
418
|
|
|
459
|
-
node_obj = Puppet::Node.new(nodename, { :
|
|
419
|
+
node_obj = Puppet::Node.new(nodename, { parameters: node_params, facts: node_facts })
|
|
460
420
|
|
|
461
421
|
trusted_info = ['remote', nodename, trusted_facts_val]
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
},
|
|
470
|
-
"Context for spec trusted hash"
|
|
471
|
-
)
|
|
422
|
+
trusted_info.push(trusted_external_data)
|
|
423
|
+
Puppet.push_context(
|
|
424
|
+
{
|
|
425
|
+
trusted_information: Puppet::Context::TrustedInformation.new(*trusted_info)
|
|
426
|
+
},
|
|
427
|
+
'Context for spec trusted hash'
|
|
428
|
+
)
|
|
472
429
|
|
|
473
|
-
|
|
474
|
-
end
|
|
430
|
+
node_obj.add_server_facts(server_facts_hash)
|
|
475
431
|
|
|
476
432
|
adapter.catalog(node_obj, exported)
|
|
477
433
|
end
|
|
478
434
|
|
|
479
435
|
def stub_facts!(facts)
|
|
480
436
|
Puppet.settings[:autosign] = false if Puppet.settings.include? :autosign
|
|
481
|
-
|
|
482
|
-
facts.each { |k, v|
|
|
437
|
+
Puppet.runtime[:facter].clear
|
|
438
|
+
facts.each { |k, v| Puppet.runtime[:facter].add(k, weight: 999) { setcode { v } } }
|
|
483
439
|
end
|
|
484
440
|
|
|
485
441
|
def build_catalog(*args)
|
|
@@ -493,27 +449,23 @@ module RSpec::Puppet
|
|
|
493
449
|
end
|
|
494
450
|
|
|
495
451
|
def munge_facts(facts)
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
452
|
+
if facts.is_a? Hash
|
|
453
|
+
return facts.reduce({}) do |memo, (k, v)|
|
|
454
|
+
memo.tap { |m| m[k.to_s] = munge_facts(v) }
|
|
455
|
+
end
|
|
456
|
+
end
|
|
499
457
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
458
|
+
if facts.is_a? Array
|
|
459
|
+
return facts.each_with_object([]) do |v, memo|
|
|
460
|
+
memo << munge_facts(v)
|
|
461
|
+
end
|
|
462
|
+
end
|
|
503
463
|
|
|
504
464
|
facts
|
|
505
465
|
end
|
|
506
466
|
|
|
507
467
|
def escape_special_chars(string)
|
|
508
|
-
string.gsub(
|
|
509
|
-
end
|
|
510
|
-
|
|
511
|
-
def rspec_compatibility
|
|
512
|
-
if RSpec::Version::STRING < '3'
|
|
513
|
-
# RSpec 2 compatibility:
|
|
514
|
-
alias_method :failure_message_for_should, :failure_message
|
|
515
|
-
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
|
516
|
-
end
|
|
468
|
+
string.gsub('$', '\\$')
|
|
517
469
|
end
|
|
518
470
|
|
|
519
471
|
def fixture_spec_hiera_conf(mod)
|
|
@@ -540,7 +492,7 @@ module RSpec::Puppet
|
|
|
540
492
|
# @param [String] title reference title
|
|
541
493
|
# @return [RSpec::Puppet::RawString] return a new RawString with the type/title populated correctly
|
|
542
494
|
def ref(type, title)
|
|
543
|
-
|
|
495
|
+
RSpec::Puppet::RawString.new("#{type}['#{title}']")
|
|
544
496
|
end
|
|
545
497
|
|
|
546
498
|
# Helper to return value wrapped in Sensitive type.
|
|
@@ -548,7 +500,7 @@ module RSpec::Puppet
|
|
|
548
500
|
# @param [Object] value to wrap
|
|
549
501
|
# @return [RSpec::Puppet::Sensitive] a new Sensitive wrapper with the new value
|
|
550
502
|
def sensitive(value)
|
|
551
|
-
|
|
503
|
+
RSpec::Puppet::Sensitive.new(value)
|
|
552
504
|
end
|
|
553
505
|
|
|
554
506
|
# @!attribute [r] adapter
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rake'
|
|
2
4
|
require 'open3'
|
|
3
5
|
require 'json'
|
|
@@ -17,7 +19,7 @@ task :release_test do
|
|
|
17
19
|
'garethr/garethr-docker',
|
|
18
20
|
'sensu/sensu-puppet',
|
|
19
21
|
'jenkinsci/puppet-jenkins',
|
|
20
|
-
'rnelson0/puppet-local_user'
|
|
22
|
+
'rnelson0/puppet-local_user'
|
|
21
23
|
]
|
|
22
24
|
|
|
23
25
|
Bundler.with_clean_env do
|
|
@@ -61,7 +63,8 @@ task :release_test do
|
|
|
61
63
|
end
|
|
62
64
|
|
|
63
65
|
print ' Running baseline tests... '
|
|
64
|
-
baseline_output, _, status = Open3.capture3({'SPEC_OPTS' => '--format json'}, 'bundle', 'exec', 'rake',
|
|
66
|
+
baseline_output, _, status = Open3.capture3({ 'SPEC_OPTS' => '--format json' }, 'bundle', 'exec', 'rake',
|
|
67
|
+
'spec')
|
|
65
68
|
if status.success?
|
|
66
69
|
puts 'Done'
|
|
67
70
|
else
|
|
@@ -94,12 +97,12 @@ task :release_test do
|
|
|
94
97
|
if status.success?
|
|
95
98
|
puts 'Done'
|
|
96
99
|
else
|
|
97
|
-
puts
|
|
100
|
+
puts 'FAILED'
|
|
98
101
|
next
|
|
99
102
|
end
|
|
100
103
|
|
|
101
104
|
print ' Running tests against rspec-puppet HEAD... '
|
|
102
|
-
head_output, _, status = Open3.capture3({'SPEC_OPTS' => '--format json'}, 'bundle', 'exec', 'rake', 'spec')
|
|
105
|
+
head_output, _, status = Open3.capture3({ 'SPEC_OPTS' => '--format json' }, 'bundle', 'exec', 'rake', 'spec')
|
|
103
106
|
if status.success?
|
|
104
107
|
puts 'Done'
|
|
105
108
|
else
|
|
@@ -114,7 +117,7 @@ task :release_test do
|
|
|
114
117
|
puts 'FAILED'
|
|
115
118
|
end
|
|
116
119
|
|
|
117
|
-
json_regex =
|
|
120
|
+
json_regex = /\{(?:[^{}]|(?:\g<0>))*\}/x
|
|
118
121
|
baseline_results = JSON.parse(baseline_output.scan(json_regex).find { |r| r.include?('summary_line') })
|
|
119
122
|
head_results = JSON.parse(head_output.scan(json_regex).find { |r| r.include?('summary_line') })
|
|
120
123
|
if head_results['summary_line'] == baseline_results['summary_line']
|