rspec-puppet 3.0.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -3
- data/README.md +54 -164
- data/lib/rspec-puppet/adapters.rb +63 -221
- data/lib/rspec-puppet/consts.rb +1 -1
- data/lib/rspec-puppet/example/function_example_group.rb +25 -45
- data/lib/rspec-puppet/example.rb +0 -2
- data/lib/rspec-puppet/matchers/compile.rb +1 -1
- data/lib/rspec-puppet/matchers/create_generic.rb +1 -1
- data/lib/rspec-puppet/matchers/dynamic_matchers.rb +2 -2
- data/lib/rspec-puppet/monkey_patches.rb +33 -46
- data/lib/rspec-puppet/sensitive.rb +29 -39
- data/lib/rspec-puppet/setup.rb +2 -8
- data/lib/rspec-puppet/spec_helper.rb +0 -3
- data/lib/rspec-puppet/support.rb +27 -74
- data/lib/rspec-puppet/version.rb +1 -1
- data/lib/rspec-puppet.rb +0 -16
- metadata +10 -8
- data/lib/rspec-puppet/example/application_example_group.rb +0 -21
@@ -1,53 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RSpec::Puppet
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
4
|
+
# A wrapper representing Sensitive data type, eg. in class params.
|
5
|
+
class Sensitive < ::Puppet::Pops::Types::PSensitiveType::Sensitive
|
6
|
+
# Create a new Sensitive object
|
7
|
+
# @param [Object] value to wrap
|
8
|
+
def initialize(value)
|
9
|
+
@value = value
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
# @return the wrapped value
|
13
|
+
def unwrap
|
14
|
+
@value
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
# @return true
|
18
|
+
def sensitive?
|
19
|
+
true
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
# @return inspect of the wrapped value, inside Sensitive()
|
23
|
+
def inspect
|
24
|
+
"Sensitive(#{@value.inspect})"
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
27
|
+
# Check for equality with another value.
|
28
|
+
# If compared to Puppet Sensitive type, it compares the wrapped values.
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
else
|
37
|
-
unwrap == other.unwrap
|
38
|
-
end
|
30
|
+
# @param other [#unwrap, Object] value to compare to
|
31
|
+
def ==(other)
|
32
|
+
if other.respond_to? :unwrap
|
33
|
+
if unwrap.is_a?(Regexp)
|
34
|
+
unwrap =~ other.unwrap
|
39
35
|
else
|
40
|
-
|
36
|
+
unwrap == other.unwrap
|
41
37
|
end
|
38
|
+
else
|
39
|
+
super
|
42
40
|
end
|
43
41
|
end
|
44
|
-
else
|
45
|
-
# :nocov:
|
46
|
-
class Sensitive
|
47
|
-
def initialize(_value)
|
48
|
-
raise 'The use of the Sensitive data type is not supported by this Puppet version'
|
49
|
-
end
|
50
|
-
end
|
51
|
-
# :nocov:
|
52
42
|
end
|
53
43
|
end
|
data/lib/rspec-puppet/setup.rb
CHANGED
@@ -91,14 +91,8 @@ module RSpec::Puppet
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def self.get_module_name_from_file(file)
|
94
|
-
|
95
|
-
|
96
|
-
if Puppet.version.to_f >= 4.0 || RSpec.configuration.parser == 'future'
|
97
|
-
require 'puppet/pops'
|
98
|
-
p = Puppet::Pops::Parser::Lexer2.new
|
99
|
-
else
|
100
|
-
p = Puppet::Parser::Lexer.new
|
101
|
-
end
|
94
|
+
require 'puppet/pops'
|
95
|
+
p = Puppet::Pops::Parser::Lexer2.new
|
102
96
|
module_name = nil
|
103
97
|
p.string = File.read(file)
|
104
98
|
tokens = p.fullscan
|
@@ -2,11 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'rspec-puppet'
|
4
4
|
|
5
|
-
fixture_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures')
|
6
|
-
|
7
5
|
RSpec.configure do |c|
|
8
6
|
c.module_path = File.join(fixture_path, 'modules')
|
9
|
-
c.manifest_dir = File.join(fixture_path, 'manifests')
|
10
7
|
c.manifest = File.join(fixture_path, 'manifests', 'site.pp')
|
11
8
|
c.environmentpath = File.join(Dir.pwd, 'spec')
|
12
9
|
end
|
data/lib/rspec-puppet/support.rb
CHANGED
@@ -21,11 +21,7 @@ module RSpec::Puppet
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def build_code(type, manifest_opts)
|
24
|
-
|
25
|
-
[site_pp_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n")
|
26
|
-
else
|
27
|
-
[import_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n")
|
28
|
-
end
|
24
|
+
[site_pp_str, pre_cond, test_manifest(type, manifest_opts), post_cond].compact.join("\n")
|
29
25
|
end
|
30
26
|
|
31
27
|
def guess_type_from_path(path)
|
@@ -44,8 +40,6 @@ module RSpec::Puppet
|
|
44
40
|
:type_alias
|
45
41
|
when %r{spec/provider}
|
46
42
|
:provider
|
47
|
-
when %r{spec/applications}
|
48
|
-
:application
|
49
43
|
else
|
50
44
|
:unknown
|
51
45
|
end
|
@@ -90,7 +84,6 @@ module RSpec::Puppet
|
|
90
84
|
hiera_data_value = respond_to?(:hiera_data) ? hiera_data : nil
|
91
85
|
|
92
86
|
rspec_config_values = %i[
|
93
|
-
trusted_server_facts
|
94
87
|
disable_module_hiera
|
95
88
|
use_fixture_spec_hiera
|
96
89
|
fixture_hiera_configs
|
@@ -128,30 +121,6 @@ module RSpec::Puppet
|
|
128
121
|
end
|
129
122
|
end
|
130
123
|
|
131
|
-
def import_str
|
132
|
-
import_str = ''
|
133
|
-
adapter.modulepath.each do |d|
|
134
|
-
if File.exist?(File.join(d, 'manifests', 'init.pp'))
|
135
|
-
path_to_manifest = File.join([
|
136
|
-
d,
|
137
|
-
'manifests',
|
138
|
-
class_name.split('::')[1..]
|
139
|
-
].flatten)
|
140
|
-
import_str = [
|
141
|
-
"import '#{d}/manifests/init.pp'",
|
142
|
-
"import '#{path_to_manifest}.pp'",
|
143
|
-
''
|
144
|
-
].join("\n")
|
145
|
-
break
|
146
|
-
elsif File.exist?(d)
|
147
|
-
import_str = "import '#{adapter.manifest}'\n"
|
148
|
-
break
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
import_str
|
153
|
-
end
|
154
|
-
|
155
124
|
def site_pp_str
|
156
125
|
return '' unless (path = adapter.manifest)
|
157
126
|
|
@@ -177,11 +146,6 @@ module RSpec::Puppet
|
|
177
146
|
else
|
178
147
|
"class { '#{class_name}': #{param_str(opts[:params])} }"
|
179
148
|
end
|
180
|
-
when :application
|
181
|
-
raise ArgumentError, 'You need to provide params for an application' unless opts.key?(:params)
|
182
|
-
|
183
|
-
"site { #{class_name} { #{sanitise_resource_title(title)}: #{param_str(opts[:params])} } }"
|
184
|
-
|
185
149
|
when :define
|
186
150
|
title_str = if title.is_a?(Array)
|
187
151
|
'[' + title.map { |r| sanitise_resource_title(r) }.join(', ') + ']'
|
@@ -207,7 +171,7 @@ module RSpec::Puppet
|
|
207
171
|
def nodename(type)
|
208
172
|
return node if respond_to?(:node)
|
209
173
|
|
210
|
-
if %i[class define function
|
174
|
+
if %i[class define function].include? type
|
211
175
|
Puppet[:certname]
|
212
176
|
else
|
213
177
|
class_name
|
@@ -248,10 +212,18 @@ module RSpec::Puppet
|
|
248
212
|
'hostname' => node.split('.').first,
|
249
213
|
'fqdn' => node,
|
250
214
|
'domain' => node.split('.', 2).last,
|
251
|
-
'clientcert' => node
|
252
|
-
'ipaddress6' => 'FE80:0000:0000:0000:AAAA:AAAA:AAAA'
|
215
|
+
'clientcert' => node
|
253
216
|
}
|
254
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
|
+
|
255
227
|
networking_facts = {
|
256
228
|
'hostname' => node_facts['hostname'],
|
257
229
|
'fqdn' => node_facts['fqdn'],
|
@@ -301,8 +273,6 @@ module RSpec::Puppet
|
|
301
273
|
end
|
302
274
|
|
303
275
|
def trusted_facts_hash(_node_name)
|
304
|
-
return {} unless Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
|
305
|
-
|
306
276
|
extensions = {}
|
307
277
|
|
308
278
|
if RSpec.configuration.default_trusted_facts.any?
|
@@ -314,8 +284,6 @@ module RSpec::Puppet
|
|
314
284
|
end
|
315
285
|
|
316
286
|
def trusted_external_data_hash
|
317
|
-
return {} unless Puppet::Util::Package.versioncmp(Puppet.version, '6.14.0') >= 0
|
318
|
-
|
319
287
|
external_data = {}
|
320
288
|
|
321
289
|
if RSpec.configuration.default_trusted_external_data.any?
|
@@ -335,7 +303,7 @@ module RSpec::Puppet
|
|
335
303
|
# And then add the server name and IP
|
336
304
|
{ 'servername' => 'fqdn',
|
337
305
|
'serverip' => 'ipaddress' }.each do |var, fact|
|
338
|
-
if (value =
|
306
|
+
if (value = Puppet.runtime[:facter].value(fact))
|
339
307
|
server_facts[var] = value
|
340
308
|
else
|
341
309
|
warn "Could not retrieve fact #{fact}"
|
@@ -343,8 +311,8 @@ module RSpec::Puppet
|
|
343
311
|
end
|
344
312
|
|
345
313
|
if server_facts['servername'].nil?
|
346
|
-
host =
|
347
|
-
server_facts['servername'] = if (domain =
|
314
|
+
host = Puppet.runtime[:facter].value(:hostname)
|
315
|
+
server_facts['servername'] = if (domain = Puppet.runtime[:facter].value(:domain))
|
348
316
|
[host, domain].join('.')
|
349
317
|
else
|
350
318
|
host
|
@@ -388,11 +356,6 @@ module RSpec::Puppet
|
|
388
356
|
vardir = Dir.mktmpdir
|
389
357
|
Puppet[:vardir] = vardir
|
390
358
|
|
391
|
-
# Enable app_management by default for Puppet versions that support it
|
392
|
-
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 && Puppet.version.to_i < 5
|
393
|
-
Puppet[:app_management] = !ENV.include?('PUPPET_NOAPP_MANAGMENT')
|
394
|
-
end
|
395
|
-
|
396
359
|
adapter.modulepath.map do |d|
|
397
360
|
Dir["#{d}/*/lib"].entries
|
398
361
|
end.flatten.each do |lib|
|
@@ -404,7 +367,7 @@ module RSpec::Puppet
|
|
404
367
|
|
405
368
|
def with_vardir
|
406
369
|
vardir = setup_puppet
|
407
|
-
|
370
|
+
yield(vardir) if block_given?
|
408
371
|
ensure
|
409
372
|
FileUtils.rm_rf(vardir) if vardir && File.directory?(vardir)
|
410
373
|
end
|
@@ -456,25 +419,23 @@ module RSpec::Puppet
|
|
456
419
|
node_obj = Puppet::Node.new(nodename, { parameters: node_params, facts: node_facts })
|
457
420
|
|
458
421
|
trusted_info = ['remote', nodename, trusted_facts_val]
|
459
|
-
trusted_info.push(trusted_external_data)
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
)
|
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
|
+
)
|
467
429
|
|
468
|
-
|
469
|
-
end
|
430
|
+
node_obj.add_server_facts(server_facts_hash)
|
470
431
|
|
471
432
|
adapter.catalog(node_obj, exported)
|
472
433
|
end
|
473
434
|
|
474
435
|
def stub_facts!(facts)
|
475
436
|
Puppet.settings[:autosign] = false if Puppet.settings.include? :autosign
|
476
|
-
|
477
|
-
facts.each { |k, v|
|
437
|
+
Puppet.runtime[:facter].clear
|
438
|
+
facts.each { |k, v| Puppet.runtime[:facter].add(k, weight: 999) { setcode { v } } }
|
478
439
|
end
|
479
440
|
|
480
441
|
def build_catalog(*args)
|
@@ -504,15 +465,7 @@ module RSpec::Puppet
|
|
504
465
|
end
|
505
466
|
|
506
467
|
def escape_special_chars(string)
|
507
|
-
string.gsub(
|
508
|
-
end
|
509
|
-
|
510
|
-
def rspec_compatibility
|
511
|
-
return unless RSpec::Version::STRING < '3'
|
512
|
-
|
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
|
468
|
+
string.gsub('$', '\\$')
|
516
469
|
end
|
517
470
|
|
518
471
|
def fixture_spec_hiera_conf(mod)
|
data/lib/rspec-puppet/version.rb
CHANGED
data/lib/rspec-puppet.rb
CHANGED
@@ -36,9 +36,7 @@ require 'rspec-puppet/monkey_patches'
|
|
36
36
|
RSpec.configure do |c|
|
37
37
|
c.add_setting :environmentpath, default: Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
|
38
38
|
c.add_setting :module_path, default: nil
|
39
|
-
c.add_setting :manifest_dir, default: nil
|
40
39
|
c.add_setting :manifest, default: nil
|
41
|
-
c.add_setting :template_dir, default: nil
|
42
40
|
c.add_setting :config, default: nil
|
43
41
|
c.add_setting :confdir, default: Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
|
44
42
|
c.add_setting :default_facts, default: {}
|
@@ -47,9 +45,6 @@ RSpec.configure do |c|
|
|
47
45
|
c.add_setting :default_trusted_external_data, default: {}
|
48
46
|
c.add_setting :facter_implementation, default: :facter
|
49
47
|
c.add_setting :hiera_config, default: Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
|
50
|
-
c.add_setting :parser, default: 'current'
|
51
|
-
c.add_setting :trusted_node_data, default: false
|
52
|
-
c.add_setting :ordering, default: 'title-hash'
|
53
48
|
c.add_setting :stringify_facts, default: true
|
54
49
|
c.add_setting :strict_variables, default: false
|
55
50
|
c.add_setting :setup_fixtures, default: true
|
@@ -63,17 +58,6 @@ RSpec.configure do |c|
|
|
63
58
|
c.add_setting :use_fixture_spec_hiera, default: false
|
64
59
|
c.add_setting :fallback_to_default_hiera, default: true
|
65
60
|
|
66
|
-
c.instance_eval do
|
67
|
-
def trusted_server_facts
|
68
|
-
@trusted_server_facts.nil? ? false : @trusted_server_facts
|
69
|
-
end
|
70
|
-
|
71
|
-
def trusted_server_facts=(value)
|
72
|
-
@trusted_server_facts = value
|
73
|
-
adapter&.setup_puppet(RSpec::Puppet.current_example)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
61
|
c.before(:all) do
|
78
62
|
RSpec::Puppet::Setup.safe_setup_directories(nil, false) if RSpec.configuration.setup_fixtures?
|
79
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Sharpe
|
@@ -10,23 +10,26 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-10-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
19
|
+
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
21
|
+
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - "
|
26
|
+
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '0'
|
29
|
-
description:
|
28
|
+
version: '3.0'
|
29
|
+
description: |2
|
30
|
+
RSpec tests for your Puppet manifests.
|
31
|
+
Note: Support for this gem has been moved under a new namespace and as such any future updates from
|
32
|
+
the Puppet team will be released as `puppetlabs-rspec-puppet`.
|
30
33
|
email:
|
31
34
|
- tim@sharpe.id.au
|
32
35
|
- modules-team@puppet.com
|
@@ -45,7 +48,6 @@ files:
|
|
45
48
|
- lib/rspec-puppet/coverage.rb
|
46
49
|
- lib/rspec-puppet/errors.rb
|
47
50
|
- lib/rspec-puppet/example.rb
|
48
|
-
- lib/rspec-puppet/example/application_example_group.rb
|
49
51
|
- lib/rspec-puppet/example/class_example_group.rb
|
50
52
|
- lib/rspec-puppet/example/define_example_group.rb
|
51
53
|
- lib/rspec-puppet/example/function_example_group.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RSpec::Puppet
|
4
|
-
# This module provides support for the application type
|
5
|
-
module ApplicationExampleGroup
|
6
|
-
include RSpec::Puppet::ManifestMatchers
|
7
|
-
include RSpec::Puppet::Support
|
8
|
-
|
9
|
-
def catalogue
|
10
|
-
@catalogue ||= load_catalogue(:application)
|
11
|
-
end
|
12
|
-
|
13
|
-
def exported_resources
|
14
|
-
-> { load_catalogue(:application, true) }
|
15
|
-
end
|
16
|
-
|
17
|
-
def rspec_puppet_cleanup
|
18
|
-
@catalogue = nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|