rspec-puppet 2.7.0 → 2.12.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 +5 -5
- data/CHANGELOG.md +171 -10
- data/README.md +59 -7
- data/lib/rspec-puppet/adapters.rb +73 -1
- data/lib/rspec-puppet/cache.rb +11 -6
- data/lib/rspec-puppet/coverage.rb +112 -13
- data/lib/rspec-puppet/facter_impl.rb +49 -0
- data/lib/rspec-puppet/matchers/allow_value.rb +8 -0
- data/lib/rspec-puppet/matchers/compile.rb +8 -0
- data/lib/rspec-puppet/matchers/count_generic.rb +13 -3
- data/lib/rspec-puppet/matchers/create_generic.rb +26 -8
- data/lib/rspec-puppet/matchers/include_class.rb +8 -1
- data/lib/rspec-puppet/matchers/parameter_matcher.rb +5 -16
- data/lib/rspec-puppet/matchers/raise_error.rb +23 -0
- data/lib/rspec-puppet/matchers/run.rb +10 -0
- data/lib/rspec-puppet/matchers/type_matchers.rb +0 -3
- data/lib/rspec-puppet/matchers/unique_values.rb +31 -0
- data/lib/rspec-puppet/matchers.rb +2 -0
- data/lib/rspec-puppet/monkey_patches.rb +63 -1
- data/lib/rspec-puppet/sensitive.rb +51 -0
- data/lib/rspec-puppet/support.rb +120 -23
- data/lib/rspec-puppet.rb +6 -0
- metadata +16 -9
data/lib/rspec-puppet/support.rb
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
require 'rspec-puppet/cache'
|
|
2
2
|
require 'rspec-puppet/adapters'
|
|
3
3
|
require 'rspec-puppet/raw_string'
|
|
4
|
+
require 'rspec-puppet/sensitive'
|
|
4
5
|
|
|
5
6
|
module RSpec::Puppet
|
|
6
7
|
module Support
|
|
8
|
+
include GenericMatchers
|
|
9
|
+
|
|
7
10
|
@@cache = RSpec::Puppet::Cache.new
|
|
11
|
+
@@fixture_hiera_configs = Hash.new { |h, k| h[k] = nil }
|
|
8
12
|
|
|
9
13
|
def subject
|
|
10
14
|
lambda { catalogue }
|
|
@@ -84,10 +88,29 @@ module RSpec::Puppet
|
|
|
84
88
|
hiera_config_value = self.respond_to?(:hiera_config) ? hiera_config : nil
|
|
85
89
|
hiera_data_value = self.respond_to?(:hiera_data) ? hiera_data : nil
|
|
86
90
|
|
|
91
|
+
rspec_config_values = [
|
|
92
|
+
:trusted_server_facts,
|
|
93
|
+
:disable_module_hiera,
|
|
94
|
+
:use_fixture_spec_hiera,
|
|
95
|
+
:fixture_hiera_configs,
|
|
96
|
+
:fallback_to_default_hiera,
|
|
97
|
+
].map { |setting| RSpec.configuration.send(setting) }
|
|
98
|
+
|
|
87
99
|
build_facts = facts_hash(node_name)
|
|
88
|
-
catalogue = build_catalog(
|
|
89
|
-
|
|
90
|
-
|
|
100
|
+
catalogue = build_catalog(
|
|
101
|
+
nodename: node_name,
|
|
102
|
+
facts_val: build_facts,
|
|
103
|
+
trusted_facts_val: trusted_facts_hash(node_name),
|
|
104
|
+
hiera_config_val: hiera_config_value,
|
|
105
|
+
code: build_code(type, manifest_opts),
|
|
106
|
+
exported: exported,
|
|
107
|
+
node_params: node_params_hash,
|
|
108
|
+
trusted_external_data: trusted_external_data_hash,
|
|
109
|
+
ignored_cache_params: {
|
|
110
|
+
hiera_data_value: hiera_data_value,
|
|
111
|
+
rspec_config_values: rspec_config_values,
|
|
112
|
+
}
|
|
113
|
+
)
|
|
91
114
|
|
|
92
115
|
test_module = type == :host ? nil : class_name.split('::').first
|
|
93
116
|
if type == :define
|
|
@@ -129,13 +152,18 @@ module RSpec::Puppet
|
|
|
129
152
|
end
|
|
130
153
|
|
|
131
154
|
def site_pp_str
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
155
|
+
return '' unless (path = adapter.manifest)
|
|
156
|
+
|
|
157
|
+
if File.file?(path)
|
|
158
|
+
File.read(path)
|
|
159
|
+
elsif File.directory?(path)
|
|
160
|
+
# Read and concatenate all .pp files.
|
|
161
|
+
Dir[File.join(path, '*.pp')].sort.map do |f|
|
|
162
|
+
File.read(f)
|
|
163
|
+
end.join("\n")
|
|
164
|
+
else
|
|
165
|
+
''
|
|
137
166
|
end
|
|
138
|
-
site_pp_str
|
|
139
167
|
end
|
|
140
168
|
|
|
141
169
|
def test_manifest(type, opts = {})
|
|
@@ -219,10 +247,11 @@ module RSpec::Puppet
|
|
|
219
247
|
}
|
|
220
248
|
|
|
221
249
|
node_facts = {
|
|
222
|
-
'hostname'
|
|
223
|
-
'fqdn'
|
|
224
|
-
'domain'
|
|
225
|
-
'clientcert'
|
|
250
|
+
'hostname' => node.split('.').first,
|
|
251
|
+
'fqdn' => node,
|
|
252
|
+
'domain' => node.split('.', 2).last,
|
|
253
|
+
'clientcert' => node,
|
|
254
|
+
'ipaddress6' => 'FE80:0000:0000:0000:AAAA:AAAA:AAAA',
|
|
226
255
|
}
|
|
227
256
|
|
|
228
257
|
networking_facts = {
|
|
@@ -285,6 +314,19 @@ module RSpec::Puppet
|
|
|
285
314
|
extensions
|
|
286
315
|
end
|
|
287
316
|
|
|
317
|
+
def trusted_external_data_hash
|
|
318
|
+
return {} unless Puppet::Util::Package.versioncmp(Puppet.version, '6.14.0') >= 0
|
|
319
|
+
|
|
320
|
+
external_data = {}
|
|
321
|
+
|
|
322
|
+
if RSpec.configuration.default_trusted_external_data.any?
|
|
323
|
+
external_data.merge!(munge_facts(RSpec.configuration.default_trusted_external_data))
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
external_data.merge!(munge_facts(trusted_external_data)) if self.respond_to?(:trusted_external_data)
|
|
327
|
+
external_data
|
|
328
|
+
end
|
|
329
|
+
|
|
288
330
|
def server_facts_hash
|
|
289
331
|
server_facts = {}
|
|
290
332
|
|
|
@@ -295,7 +337,7 @@ module RSpec::Puppet
|
|
|
295
337
|
{"servername" => "fqdn",
|
|
296
338
|
"serverip" => "ipaddress"
|
|
297
339
|
}.each do |var, fact|
|
|
298
|
-
if value =
|
|
340
|
+
if value = FacterImpl.value(fact)
|
|
299
341
|
server_facts[var] = value
|
|
300
342
|
else
|
|
301
343
|
warn "Could not retrieve fact #{fact}"
|
|
@@ -303,8 +345,8 @@ module RSpec::Puppet
|
|
|
303
345
|
end
|
|
304
346
|
|
|
305
347
|
if server_facts["servername"].nil?
|
|
306
|
-
host =
|
|
307
|
-
if domain =
|
|
348
|
+
host = FacterImpl.value(:hostname)
|
|
349
|
+
if domain = FacterImpl.value(:domain)
|
|
308
350
|
server_facts["servername"] = [host, domain].join(".")
|
|
309
351
|
else
|
|
310
352
|
server_facts["servername"] = host
|
|
@@ -350,7 +392,7 @@ module RSpec::Puppet
|
|
|
350
392
|
|
|
351
393
|
# Enable app_management by default for Puppet versions that support it
|
|
352
394
|
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 && Puppet.version.to_i < 5
|
|
353
|
-
Puppet[:app_management] = true
|
|
395
|
+
Puppet[:app_management] = ENV.include?('PUPPET_NOAPP_MANAGMENT') ? false : true
|
|
354
396
|
end
|
|
355
397
|
|
|
356
398
|
adapter.modulepath.map do |d|
|
|
@@ -372,6 +414,29 @@ module RSpec::Puppet
|
|
|
372
414
|
end
|
|
373
415
|
|
|
374
416
|
def build_catalog_without_cache(nodename, facts_val, trusted_facts_val, hiera_config_val, code, exported, node_params, *_)
|
|
417
|
+
build_catalog_without_cache_v2({
|
|
418
|
+
nodename: nodename,
|
|
419
|
+
facts_val: facts_val,
|
|
420
|
+
trusted_facts_val: trusted_facts_val,
|
|
421
|
+
hiera_config_val: hiera_config_val,
|
|
422
|
+
code: code,
|
|
423
|
+
exported: exported,
|
|
424
|
+
node_params: node_params,
|
|
425
|
+
trusted_external: {},
|
|
426
|
+
})
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
def build_catalog_without_cache_v2(
|
|
430
|
+
nodename: nil,
|
|
431
|
+
facts_val: nil,
|
|
432
|
+
trusted_facts_val: nil,
|
|
433
|
+
hiera_config_val: nil,
|
|
434
|
+
code: nil,
|
|
435
|
+
exported: nil,
|
|
436
|
+
node_params: nil,
|
|
437
|
+
trusted_external_data: nil,
|
|
438
|
+
ignored_cache_params: {}
|
|
439
|
+
)
|
|
375
440
|
|
|
376
441
|
# If we're going to rebuild the catalog, we should clear the cached instance
|
|
377
442
|
# of Hiera that Puppet is using. This opens the possibility of the catalog
|
|
@@ -393,10 +458,14 @@ module RSpec::Puppet
|
|
|
393
458
|
|
|
394
459
|
node_obj = Puppet::Node.new(nodename, { :parameters => node_params, :facts => node_facts })
|
|
395
460
|
|
|
461
|
+
trusted_info = ['remote', nodename, trusted_facts_val]
|
|
462
|
+
if Puppet::Util::Package.versioncmp(Puppet.version, '6.14.0') >= 0
|
|
463
|
+
trusted_info.push(trusted_external_data)
|
|
464
|
+
end
|
|
396
465
|
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
|
|
397
466
|
Puppet.push_context(
|
|
398
467
|
{
|
|
399
|
-
:trusted_information => Puppet::Context::TrustedInformation.new(
|
|
468
|
+
:trusted_information => Puppet::Context::TrustedInformation.new(*trusted_info)
|
|
400
469
|
},
|
|
401
470
|
"Context for spec trusted hash"
|
|
402
471
|
)
|
|
@@ -409,13 +478,17 @@ module RSpec::Puppet
|
|
|
409
478
|
|
|
410
479
|
def stub_facts!(facts)
|
|
411
480
|
Puppet.settings[:autosign] = false if Puppet.settings.include? :autosign
|
|
412
|
-
|
|
413
|
-
facts.each { |k, v|
|
|
481
|
+
FacterImpl.clear
|
|
482
|
+
facts.each { |k, v| FacterImpl.add(k, :weight => 999) { setcode { v } } }
|
|
414
483
|
end
|
|
415
484
|
|
|
416
485
|
def build_catalog(*args)
|
|
417
486
|
@@cache.get(*args) do |*args|
|
|
418
|
-
|
|
487
|
+
if args.length == 1 && args.first.is_a?(Hash)
|
|
488
|
+
build_catalog_without_cache_v2(**args.first)
|
|
489
|
+
else
|
|
490
|
+
build_catalog_without_cache(*args)
|
|
491
|
+
end
|
|
419
492
|
end
|
|
420
493
|
end
|
|
421
494
|
|
|
@@ -432,8 +505,7 @@ module RSpec::Puppet
|
|
|
432
505
|
end
|
|
433
506
|
|
|
434
507
|
def escape_special_chars(string)
|
|
435
|
-
string.gsub
|
|
436
|
-
string
|
|
508
|
+
string.gsub(/\$/, "\\$")
|
|
437
509
|
end
|
|
438
510
|
|
|
439
511
|
def rspec_compatibility
|
|
@@ -444,6 +516,23 @@ module RSpec::Puppet
|
|
|
444
516
|
end
|
|
445
517
|
end
|
|
446
518
|
|
|
519
|
+
def fixture_spec_hiera_conf(mod)
|
|
520
|
+
return @@fixture_hiera_configs[mod.name] if @@fixture_hiera_configs.key?(mod.name)
|
|
521
|
+
|
|
522
|
+
path = Pathname.new(mod.path)
|
|
523
|
+
if path.join('spec').exist?
|
|
524
|
+
path.join('spec').find do |file|
|
|
525
|
+
Find.prune if %w[modules work-dir].any? do |dir|
|
|
526
|
+
file.relative_path_from(path).to_s.start_with?("spec/fixtures/#{dir}")
|
|
527
|
+
end
|
|
528
|
+
if file.basename.to_s.eql?(Puppet::Pops::Lookup::HieraConfig::CONFIG_FILE_NAME)
|
|
529
|
+
return @@fixture_hiera_configs[mod.name] = file.to_s
|
|
530
|
+
end
|
|
531
|
+
end
|
|
532
|
+
end
|
|
533
|
+
@@fixture_hiera_configs[mod.name]
|
|
534
|
+
end
|
|
535
|
+
|
|
447
536
|
# Helper to return a resource/node reference, so it gets translated in params to a raw string
|
|
448
537
|
# without quotes.
|
|
449
538
|
#
|
|
@@ -454,6 +543,14 @@ module RSpec::Puppet
|
|
|
454
543
|
return RSpec::Puppet::RawString.new("#{type}['#{title}']")
|
|
455
544
|
end
|
|
456
545
|
|
|
546
|
+
# Helper to return value wrapped in Sensitive type.
|
|
547
|
+
#
|
|
548
|
+
# @param [Object] value to wrap
|
|
549
|
+
# @return [RSpec::Puppet::Sensitive] a new Sensitive wrapper with the new value
|
|
550
|
+
def sensitive(value)
|
|
551
|
+
return RSpec::Puppet::Sensitive.new(value)
|
|
552
|
+
end
|
|
553
|
+
|
|
457
554
|
# @!attribute [r] adapter
|
|
458
555
|
# @api private
|
|
459
556
|
# @return [Class < RSpec::Puppet::Adapters::Base]
|
data/lib/rspec-puppet.rb
CHANGED
|
@@ -42,6 +42,8 @@ RSpec.configure do |c|
|
|
|
42
42
|
c.add_setting :default_facts, :default => {}
|
|
43
43
|
c.add_setting :default_node_params, :default => {}
|
|
44
44
|
c.add_setting :default_trusted_facts, :default => {}
|
|
45
|
+
c.add_setting :default_trusted_external_data, :default => {}
|
|
46
|
+
c.add_setting :facter_implementation, :default => :facter
|
|
45
47
|
c.add_setting :hiera_config, :default => Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
|
|
46
48
|
c.add_setting :parser, :default => 'current'
|
|
47
49
|
c.add_setting :trusted_node_data, :default => false
|
|
@@ -54,6 +56,10 @@ RSpec.configure do |c|
|
|
|
54
56
|
c.add_setting :platform, :default => Puppet::Util::Platform.actual_platform
|
|
55
57
|
c.add_setting :vendormoduledir, :default => Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
|
|
56
58
|
c.add_setting :basemodulepath, :default => Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
|
|
59
|
+
c.add_setting :disable_module_hiera, :default => false
|
|
60
|
+
c.add_setting :fixture_hiera_configs, :default => {}
|
|
61
|
+
c.add_setting :use_fixture_spec_hiera, :default => false
|
|
62
|
+
c.add_setting :fallback_to_default_hiera, :default => true
|
|
57
63
|
|
|
58
64
|
c.instance_eval do
|
|
59
65
|
def trusted_server_facts
|
metadata
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rspec-puppet
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.12.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tim Sharpe
|
|
8
|
-
|
|
8
|
+
- Puppet, Inc.
|
|
9
|
+
- Community Contributors
|
|
10
|
+
autorequire:
|
|
9
11
|
bindir: bin
|
|
10
12
|
cert_chain: []
|
|
11
|
-
date:
|
|
13
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
|
12
14
|
dependencies:
|
|
13
15
|
- !ruby/object:Gem::Dependency
|
|
14
16
|
name: rspec
|
|
@@ -25,7 +27,9 @@ dependencies:
|
|
|
25
27
|
- !ruby/object:Gem::Version
|
|
26
28
|
version: '0'
|
|
27
29
|
description: RSpec tests for your Puppet manifests
|
|
28
|
-
email:
|
|
30
|
+
email:
|
|
31
|
+
- tim@sharpe.id.au
|
|
32
|
+
- modules-team@puppet.com
|
|
29
33
|
executables:
|
|
30
34
|
- rspec-puppet-init
|
|
31
35
|
extensions: []
|
|
@@ -49,6 +53,7 @@ files:
|
|
|
49
53
|
- lib/rspec-puppet/example/provider_example_group.rb
|
|
50
54
|
- lib/rspec-puppet/example/type_alias_example_group.rb
|
|
51
55
|
- lib/rspec-puppet/example/type_example_group.rb
|
|
56
|
+
- lib/rspec-puppet/facter_impl.rb
|
|
52
57
|
- lib/rspec-puppet/matchers.rb
|
|
53
58
|
- lib/rspec-puppet/matchers/allow_value.rb
|
|
54
59
|
- lib/rspec-puppet/matchers/compile.rb
|
|
@@ -57,23 +62,26 @@ files:
|
|
|
57
62
|
- lib/rspec-puppet/matchers/dynamic_matchers.rb
|
|
58
63
|
- lib/rspec-puppet/matchers/include_class.rb
|
|
59
64
|
- lib/rspec-puppet/matchers/parameter_matcher.rb
|
|
65
|
+
- lib/rspec-puppet/matchers/raise_error.rb
|
|
60
66
|
- lib/rspec-puppet/matchers/run.rb
|
|
61
67
|
- lib/rspec-puppet/matchers/type_matchers.rb
|
|
68
|
+
- lib/rspec-puppet/matchers/unique_values.rb
|
|
62
69
|
- lib/rspec-puppet/monkey_patches.rb
|
|
63
70
|
- lib/rspec-puppet/monkey_patches/win32/registry.rb
|
|
64
71
|
- lib/rspec-puppet/monkey_patches/win32/taskscheduler.rb
|
|
65
72
|
- lib/rspec-puppet/monkey_patches/windows/taskschedulerconstants.rb
|
|
66
73
|
- lib/rspec-puppet/rake_task.rb
|
|
67
74
|
- lib/rspec-puppet/raw_string.rb
|
|
75
|
+
- lib/rspec-puppet/sensitive.rb
|
|
68
76
|
- lib/rspec-puppet/setup.rb
|
|
69
77
|
- lib/rspec-puppet/spec_helper.rb
|
|
70
78
|
- lib/rspec-puppet/support.rb
|
|
71
79
|
- lib/rspec-puppet/tasks/release_test.rb
|
|
72
|
-
homepage: https://github.com/
|
|
80
|
+
homepage: https://github.com/puppetlabs/rspec-puppet/
|
|
73
81
|
licenses:
|
|
74
82
|
- MIT
|
|
75
83
|
metadata: {}
|
|
76
|
-
post_install_message:
|
|
84
|
+
post_install_message:
|
|
77
85
|
rdoc_options: []
|
|
78
86
|
require_paths:
|
|
79
87
|
- lib
|
|
@@ -88,9 +96,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
88
96
|
- !ruby/object:Gem::Version
|
|
89
97
|
version: '0'
|
|
90
98
|
requirements: []
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
signing_key:
|
|
99
|
+
rubygems_version: 3.1.6
|
|
100
|
+
signing_key:
|
|
94
101
|
specification_version: 4
|
|
95
102
|
summary: RSpec tests for your Puppet manifests
|
|
96
103
|
test_files: []
|