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,35 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'pathname'
|
|
2
4
|
|
|
3
5
|
# Load this library before enabling the monkey-patches to avoid HI-581
|
|
4
6
|
begin
|
|
5
|
-
require 'hiera/util/win32'
|
|
7
|
+
require 'hiera/util/win32'
|
|
6
8
|
rescue LoadError
|
|
7
9
|
# ignore this on installs without hiera, e.g. puppet 3 gems
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
class RSpec::Puppet::EventListener
|
|
11
13
|
def self.example_started(example)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
else
|
|
19
|
-
@rspec_puppet_example = example.example_group.ancestors.include?(RSpec::Puppet::Support)
|
|
20
|
-
@current_example = example
|
|
21
|
-
end
|
|
14
|
+
@rspec_puppet_example = example.example.example_group.ancestors.include?(RSpec::Puppet::Support)
|
|
15
|
+
@current_example = example.example
|
|
16
|
+
return unless !@current_example.respond_to?(:environment) && @current_example.respond_to?(:example_group_instance)
|
|
17
|
+
|
|
18
|
+
@current_example = @current_example.example_group_instance
|
|
22
19
|
end
|
|
23
20
|
|
|
24
|
-
def self.example_passed(
|
|
21
|
+
def self.example_passed(_example)
|
|
25
22
|
@rspec_puppet_example = false
|
|
26
23
|
end
|
|
27
24
|
|
|
28
|
-
def self.example_pending(
|
|
25
|
+
def self.example_pending(_example)
|
|
29
26
|
@rspec_puppet_example = false
|
|
30
27
|
end
|
|
31
28
|
|
|
32
|
-
def self.example_failed(
|
|
29
|
+
def self.example_failed(_example)
|
|
33
30
|
@rspec_puppet_example = false
|
|
34
31
|
end
|
|
35
32
|
|
|
@@ -37,20 +34,13 @@ class RSpec::Puppet::EventListener
|
|
|
37
34
|
@rspec_puppet_example || false
|
|
38
35
|
end
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
@rspec3 = defined?(RSpec::Core::Notifications)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
@rspec3
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def self.current_example
|
|
49
|
-
@current_example
|
|
37
|
+
class << self
|
|
38
|
+
attr_reader :current_example
|
|
50
39
|
end
|
|
51
40
|
end
|
|
52
41
|
|
|
53
|
-
RSpec.configuration.reporter.register_listener(RSpec::Puppet::EventListener, :example_started, :example_pending,
|
|
42
|
+
RSpec.configuration.reporter.register_listener(RSpec::Puppet::EventListener, :example_started, :example_pending,
|
|
43
|
+
:example_passed, :example_failed)
|
|
54
44
|
|
|
55
45
|
require 'rspec-puppet/monkey_patches/win32/taskscheduler'
|
|
56
46
|
require 'rspec-puppet/monkey_patches/win32/registry'
|
|
@@ -84,24 +74,20 @@ module Puppet
|
|
|
84
74
|
end
|
|
85
75
|
end
|
|
86
76
|
|
|
87
|
-
retval = old_set_default.
|
|
77
|
+
retval = old_set_default.bind_call(self, attr)
|
|
88
78
|
|
|
89
|
-
unless old_posix.nil?
|
|
90
|
-
|
|
91
|
-
end
|
|
92
|
-
unless old_microsoft_windows.nil?
|
|
93
|
-
Puppet.features.add(:microsoft_windows) { old_microsoft_windows }
|
|
94
|
-
end
|
|
79
|
+
Puppet.features.add(:posix) { old_posix } unless old_posix.nil?
|
|
80
|
+
Puppet.features.add(:microsoft_windows) { old_microsoft_windows } unless old_microsoft_windows.nil?
|
|
95
81
|
|
|
96
82
|
retval
|
|
97
83
|
else
|
|
98
|
-
old_set_default.
|
|
84
|
+
old_set_default.bind_call(self, attr)
|
|
99
85
|
end
|
|
100
86
|
end
|
|
101
87
|
end
|
|
102
88
|
|
|
103
89
|
module Parser::Files
|
|
104
|
-
alias
|
|
90
|
+
alias old_find_manifests_in_modules find_manifests_in_modules
|
|
105
91
|
module_function :old_find_manifests_in_modules
|
|
106
92
|
|
|
107
93
|
def find_manifests_in_modules(pattern, environment)
|
|
@@ -113,8 +99,9 @@ module Puppet
|
|
|
113
99
|
RSpec::Puppet::Consts.stub_consts_for(RSpec.configuration.platform)
|
|
114
100
|
end
|
|
115
101
|
|
|
116
|
-
if pretending && pretending != Puppet::Util::Platform.actual_platform
|
|
117
|
-
|
|
102
|
+
if pretending && pretending != Puppet::Util::Platform.actual_platform && environment.respond_to?(:value_cache,
|
|
103
|
+
true)
|
|
104
|
+
environment.send(:value_cache).clear
|
|
118
105
|
end
|
|
119
106
|
output = old_find_manifests_in_modules(pattern, environment)
|
|
120
107
|
|
|
@@ -135,30 +122,30 @@ module Puppet
|
|
|
135
122
|
# Fix for removal of default_env function
|
|
136
123
|
# Bug: https://github.com/rodjek/rspec-puppet/issues/796
|
|
137
124
|
# Upstream: https://github.com/puppetlabs/puppet/commit/94df3c1a3992d89b2d7d5db8a70373c135bdd86b
|
|
138
|
-
|
|
139
|
-
def default_env
|
|
125
|
+
unless respond_to?(:default_env)
|
|
126
|
+
def default_env
|
|
140
127
|
DEFAULT_ENV
|
|
141
128
|
end
|
|
142
129
|
module_function :default_env
|
|
143
130
|
end
|
|
144
131
|
|
|
145
132
|
if respond_to?(:get_env)
|
|
146
|
-
alias
|
|
133
|
+
alias old_get_env get_env
|
|
147
134
|
module_function :old_get_env
|
|
148
135
|
|
|
149
136
|
def get_env(name, mode = default_env)
|
|
150
137
|
if RSpec::Puppet.rspec_puppet_example?
|
|
151
138
|
# use the actual platform, not the pretended
|
|
152
|
-
|
|
139
|
+
old_get_env(name, Platform.actual_platform)
|
|
153
140
|
else
|
|
154
|
-
|
|
141
|
+
old_get_env(name, mode)
|
|
155
142
|
end
|
|
156
143
|
end
|
|
157
144
|
module_function :get_env
|
|
158
145
|
end
|
|
159
146
|
|
|
160
147
|
if respond_to?(:path_to_uri)
|
|
161
|
-
alias
|
|
148
|
+
alias old_path_to_uri path_to_uri
|
|
162
149
|
module_function :old_path_to_uri
|
|
163
150
|
|
|
164
151
|
def path_to_uri(*args)
|
|
@@ -175,12 +162,12 @@ module Puppet
|
|
|
175
162
|
|
|
176
163
|
# Allow rspec-puppet to pretend to be different platforms.
|
|
177
164
|
module Platform
|
|
178
|
-
alias
|
|
165
|
+
alias old_windows? windows?
|
|
179
166
|
module_function :old_windows?
|
|
180
167
|
|
|
181
168
|
def windows?
|
|
182
169
|
if RSpec::Puppet.rspec_puppet_example?
|
|
183
|
-
|
|
170
|
+
pretending? ? pretend_windows? : (actual_platform == :windows)
|
|
184
171
|
else
|
|
185
172
|
old_windows?
|
|
186
173
|
end
|
|
@@ -249,7 +236,7 @@ module Puppet
|
|
|
249
236
|
if RSpec::Puppet.rspec_puppet_example?
|
|
250
237
|
true
|
|
251
238
|
else
|
|
252
|
-
old_pass.
|
|
239
|
+
old_pass.bind_call(self, value)
|
|
253
240
|
end
|
|
254
241
|
end
|
|
255
242
|
end
|
|
@@ -263,43 +250,46 @@ module Puppet
|
|
|
263
250
|
if RSpec::Puppet.rspec_puppet_example?
|
|
264
251
|
true
|
|
265
252
|
else
|
|
266
|
-
old_pass.
|
|
253
|
+
old_pass.bind_call(self, value)
|
|
267
254
|
end
|
|
268
255
|
end
|
|
269
256
|
end
|
|
270
257
|
end
|
|
271
258
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if RSpec
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
return config unless config.nil? && RSpec.configuration.fallback_to_default_hiera
|
|
286
|
-
end
|
|
259
|
+
class Module
|
|
260
|
+
old_hiera_conf_file = instance_method(:hiera_conf_file)
|
|
261
|
+
define_method(:hiera_conf_file) do
|
|
262
|
+
if RSpec::Puppet.rspec_puppet_example?
|
|
263
|
+
if RSpec.configuration.disable_module_hiera
|
|
264
|
+
return nil
|
|
265
|
+
elsif RSpec.configuration.fixture_hiera_configs.key?(name)
|
|
266
|
+
config = RSpec.configuration.fixture_hiera_configs[name]
|
|
267
|
+
config = File.absolute_path(config, path) unless config.nil?
|
|
268
|
+
return config
|
|
269
|
+
elsif RSpec.configuration.use_fixture_spec_hiera
|
|
270
|
+
config = RSpec::Puppet.current_example.fixture_spec_hiera_conf(self)
|
|
271
|
+
return config unless config.nil? && RSpec.configuration.fallback_to_default_hiera
|
|
287
272
|
end
|
|
288
|
-
old_hiera_conf_file.bind(self).call
|
|
289
273
|
end
|
|
274
|
+
old_hiera_conf_file.bind_call(self)
|
|
290
275
|
end
|
|
276
|
+
end
|
|
291
277
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
278
|
+
class Pops::Lookup::ModuleDataProvider
|
|
279
|
+
old_configuration_path = instance_method(:configuration_path)
|
|
280
|
+
define_method(:configuration_path) do |lookup_invocation|
|
|
281
|
+
if RSpec::Puppet.rspec_puppet_example?
|
|
282
|
+
env = lookup_invocation.scope.environment
|
|
283
|
+
mod = env.module(module_name)
|
|
284
|
+
unless mod
|
|
285
|
+
raise Puppet::DataBinding::LookupError,
|
|
286
|
+
format(_("Environment '%<env>s', cannot find module '%<module_name>s'"), env: env.name,
|
|
287
|
+
module_name: module_name)
|
|
300
288
|
end
|
|
301
|
-
|
|
289
|
+
|
|
290
|
+
return Pathname.new(mod.hiera_conf_file)
|
|
302
291
|
end
|
|
292
|
+
old_configuration_path.bind_call(self, lookup_invocation)
|
|
303
293
|
end
|
|
304
294
|
end
|
|
305
295
|
end
|
|
@@ -308,29 +298,26 @@ class Pathname
|
|
|
308
298
|
def rspec_puppet_basename(path)
|
|
309
299
|
raise ArgumentError, 'pathname stubbing not enabled' unless RSpec.configuration.enable_pathname_stubbing
|
|
310
300
|
|
|
311
|
-
|
|
312
|
-
path = path[2..-1]
|
|
313
|
-
end
|
|
301
|
+
path = path[2..-1] if /\A[a-zA-Z]:(#{SEPARATOR_PAT}.*)\z/.match?(path)
|
|
314
302
|
path.split(SEPARATOR_PAT).last || path[/(#{SEPARATOR_PAT})/, 1] || path
|
|
315
303
|
end
|
|
316
304
|
|
|
317
|
-
if instance_methods.include?(
|
|
305
|
+
if instance_methods.include?('chop_basename')
|
|
318
306
|
old_chop_basename = instance_method(:chop_basename)
|
|
319
307
|
|
|
320
308
|
define_method(:chop_basename) do |path|
|
|
321
309
|
if RSpec::Puppet.rspec_puppet_example?
|
|
322
310
|
if RSpec.configuration.enable_pathname_stubbing
|
|
323
311
|
base = rspec_puppet_basename(path)
|
|
324
|
-
if /\A#{SEPARATOR_PAT}?\z/o
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
end
|
|
312
|
+
return nil if /\A#{SEPARATOR_PAT}?\z/o.match?(base)
|
|
313
|
+
|
|
314
|
+
[path[0, path.rindex(base)], base]
|
|
315
|
+
|
|
329
316
|
else
|
|
330
|
-
old_chop_basename.
|
|
317
|
+
old_chop_basename.bind_call(self, path)
|
|
331
318
|
end
|
|
332
319
|
else
|
|
333
|
-
old_chop_basename.
|
|
320
|
+
old_chop_basename.bind_call(self, path)
|
|
334
321
|
end
|
|
335
322
|
end
|
|
336
323
|
end
|
|
@@ -345,10 +332,8 @@ class Puppet::Module
|
|
|
345
332
|
old_match_manifests = instance_method(:match_manifests)
|
|
346
333
|
|
|
347
334
|
define_method(:match_manifests) do |rest|
|
|
348
|
-
result = old_match_manifests.
|
|
349
|
-
if result.length > 1 && File.basename(result[0]) == 'init.pp'
|
|
350
|
-
result.shift
|
|
351
|
-
end
|
|
335
|
+
result = old_match_manifests.bind_call(self, rest)
|
|
336
|
+
result.shift if result.length > 1 && File.basename(result[0]) == 'init.pp'
|
|
352
337
|
result
|
|
353
338
|
end
|
|
354
339
|
end
|
|
@@ -361,7 +346,7 @@ Puppet::Type.type(:file).paramclass(:path).munge do |value|
|
|
|
361
346
|
if RSpec::Puppet.rspec_puppet_example?
|
|
362
347
|
value
|
|
363
348
|
else
|
|
364
|
-
file_path_munge.
|
|
349
|
+
file_path_munge.bind_call(self, value)
|
|
365
350
|
end
|
|
366
351
|
end
|
|
367
352
|
|
|
@@ -373,7 +358,7 @@ Puppet::Type.type(:exec).paramclass(:user).validate do |value|
|
|
|
373
358
|
if RSpec::Puppet.rspec_puppet_example?
|
|
374
359
|
true
|
|
375
360
|
else
|
|
376
|
-
exec_user_validate.
|
|
361
|
+
exec_user_validate.bind_call(self, value)
|
|
377
362
|
end
|
|
378
363
|
end
|
|
379
364
|
|
|
@@ -383,11 +368,11 @@ end
|
|
|
383
368
|
Puppet::Type.type(:file).provide(:windows).class_eval do
|
|
384
369
|
old_supports_acl = instance_method(:supports_acl?) if respond_to?(:supports_acl?)
|
|
385
370
|
|
|
386
|
-
def supports_acl?(
|
|
371
|
+
def supports_acl?(_path)
|
|
387
372
|
if RSpec::Puppet.rspec_puppet_example?
|
|
388
373
|
true
|
|
389
374
|
else
|
|
390
|
-
old_supports_acl.
|
|
375
|
+
old_supports_acl.bind_call(self, value)
|
|
391
376
|
end
|
|
392
377
|
end
|
|
393
378
|
|
|
@@ -397,7 +382,7 @@ Puppet::Type.type(:file).provide(:windows).class_eval do
|
|
|
397
382
|
if RSpec::Puppet.rspec_puppet_example?
|
|
398
383
|
true
|
|
399
384
|
else
|
|
400
|
-
old_manages_symlinks.
|
|
385
|
+
old_manages_symlinks.bind_call(self, value)
|
|
401
386
|
end
|
|
402
387
|
end
|
|
403
388
|
end
|
|
@@ -406,9 +391,11 @@ end
|
|
|
406
391
|
# windows, otherwise it will require other libraries that probably won't be
|
|
407
392
|
# available on non-windows hosts.
|
|
408
393
|
module Kernel
|
|
409
|
-
alias
|
|
394
|
+
alias old_require require
|
|
410
395
|
def require(path)
|
|
411
|
-
return if
|
|
396
|
+
return if ['puppet/util/windows',
|
|
397
|
+
'win32/registry'].include?(path) && RSpec::Puppet.rspec_puppet_example? && Puppet::Util::Platform.pretend_windows?
|
|
398
|
+
|
|
412
399
|
old_require(path)
|
|
413
400
|
end
|
|
414
401
|
end
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rake'
|
|
2
4
|
require 'rspec/core/rake_task'
|
|
3
5
|
|
|
4
|
-
desc
|
|
6
|
+
desc 'Run all RSpec code examples'
|
|
5
7
|
RSpec::Core::RakeTask.new(:rspec) do |t|
|
|
6
|
-
File.exist?('spec/spec.opts') ?
|
|
8
|
+
opts = File.exist?('spec/spec.opts') ? File.read('spec/spec.opts').chomp : ''
|
|
7
9
|
t.rspec_opts = opts
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
SPEC_SUITES = (Dir.entries('spec') - ['.', '..','fixtures']).select {|e| File.directory? "spec/#{e}" }
|
|
12
|
+
SPEC_SUITES = (Dir.entries('spec') - ['.', '..', 'fixtures']).select { |e| File.directory? "spec/#{e}" }
|
|
11
13
|
namespace :rspec do
|
|
12
14
|
SPEC_SUITES.each do |suite|
|
|
13
15
|
desc "Run #{suite} RSpec code examples"
|
|
14
16
|
RSpec::Core::RakeTask.new(suite) do |t|
|
|
15
17
|
t.pattern = "spec/#{suite}/**/*_spec.rb"
|
|
16
|
-
File.exist?('spec/spec.opts') ?
|
|
18
|
+
opts = File.exist?('spec/spec.opts') ? File.read('spec/spec.opts').chomp : ''
|
|
17
19
|
t.rspec_opts = opts
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -1,51 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module RSpec::Puppet
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
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
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
# @return the wrapped value
|
|
13
|
+
def unwrap
|
|
14
|
+
@value
|
|
15
|
+
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
# @return true
|
|
18
|
+
def sensitive?
|
|
19
|
+
true
|
|
20
|
+
end
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
# @return inspect of the wrapped value, inside Sensitive()
|
|
23
|
+
def inspect
|
|
24
|
+
"Sensitive(#{@value.inspect})"
|
|
25
|
+
end
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
# Check for equality with another value.
|
|
28
|
+
# If compared to Puppet Sensitive type, it compares the wrapped values.
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
else
|
|
35
|
-
return unwrap == other.unwrap
|
|
36
|
-
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
|
|
37
35
|
else
|
|
38
|
-
|
|
36
|
+
unwrap == other.unwrap
|
|
39
37
|
end
|
|
38
|
+
else
|
|
39
|
+
super
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
|
-
else
|
|
43
|
-
#:nocov:
|
|
44
|
-
class Sensitive
|
|
45
|
-
def initialize(value)
|
|
46
|
-
raise 'The use of the Sensitive data type is not supported by this Puppet version'
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
#:nocov:
|
|
50
42
|
end
|
|
51
43
|
end
|
data/lib/rspec-puppet/setup.rb
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'English'
|
|
1
4
|
require 'puppet'
|
|
2
5
|
require 'fileutils'
|
|
3
6
|
|
|
@@ -9,17 +12,17 @@ end
|
|
|
9
12
|
|
|
10
13
|
module RSpec::Puppet
|
|
11
14
|
class Setup
|
|
12
|
-
def self.run(module_name=nil)
|
|
15
|
+
def self.run(module_name = nil)
|
|
13
16
|
unless is_module_dir?
|
|
14
|
-
|
|
17
|
+
warn 'Does not appear to be a Puppet module. Aborting'
|
|
15
18
|
return false
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
if control_repo?
|
|
19
|
-
|
|
20
|
-
Unable to find a metadata.json file. If this is a module, please create a
|
|
21
|
-
metadata.json file and try again.
|
|
22
|
-
END
|
|
22
|
+
warn <<~END
|
|
23
|
+
Unable to find a metadata.json file. If this is a module, please create a
|
|
24
|
+
metadata.json file and try again.
|
|
25
|
+
END
|
|
23
26
|
return false
|
|
24
27
|
end
|
|
25
28
|
|
|
@@ -30,16 +33,16 @@ END
|
|
|
30
33
|
safe_create_rakefile
|
|
31
34
|
end
|
|
32
35
|
|
|
33
|
-
def self.safe_setup_directories(module_name=nil, verbose=true)
|
|
36
|
+
def self.safe_setup_directories(module_name = nil, verbose = true)
|
|
34
37
|
if control_repo?
|
|
35
|
-
|
|
38
|
+
warn 'Unable to setup rspec-puppet automatically in a control repo' if verbose
|
|
36
39
|
return false
|
|
37
40
|
end
|
|
38
41
|
|
|
39
42
|
if module_name.nil?
|
|
40
43
|
module_name = get_module_name
|
|
41
44
|
if module_name.nil?
|
|
42
|
-
|
|
45
|
+
warn 'Unable to determine module name. Aborting' if verbose
|
|
43
46
|
return false
|
|
44
47
|
end
|
|
45
48
|
end
|
|
@@ -52,35 +55,35 @@ END
|
|
|
52
55
|
File.join('spec', 'hosts'),
|
|
53
56
|
File.join('spec', 'fixtures'),
|
|
54
57
|
File.join('spec', 'fixtures', 'manifests'),
|
|
55
|
-
File.join('spec', 'fixtures', 'modules')
|
|
58
|
+
File.join('spec', 'fixtures', 'modules')
|
|
56
59
|
].each { |dir| safe_mkdir(dir, verbose) }
|
|
57
60
|
|
|
58
61
|
target = File.join('spec', 'fixtures', 'modules', module_name)
|
|
59
62
|
safe_make_link('.', target, verbose)
|
|
60
63
|
end
|
|
61
64
|
|
|
62
|
-
def self.safe_teardown_links(module_name=nil)
|
|
65
|
+
def self.safe_teardown_links(module_name = nil)
|
|
63
66
|
if module_name.nil?
|
|
64
67
|
module_name = get_module_name
|
|
65
68
|
if module_name.nil?
|
|
66
|
-
|
|
69
|
+
warn 'Unable to determine module name. Aborting'
|
|
67
70
|
return false
|
|
68
71
|
end
|
|
69
72
|
end
|
|
70
73
|
|
|
71
74
|
target = File.join('spec', 'fixtures', 'modules', module_name)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
return unless File.symlink?(target) && File.readlink(target) == File.expand_path('.')
|
|
76
|
+
|
|
77
|
+
File.unlink(target)
|
|
75
78
|
end
|
|
76
|
-
|
|
79
|
+
|
|
77
80
|
def self.control_repo?
|
|
78
81
|
!File.exist?('metadata.json')
|
|
79
82
|
end
|
|
80
83
|
|
|
81
84
|
def self.get_module_name
|
|
82
85
|
module_name = nil
|
|
83
|
-
Dir[
|
|
86
|
+
Dir['manifests/*.pp'].entries.each do |manifest|
|
|
84
87
|
module_name = get_module_name_from_file(manifest)
|
|
85
88
|
break unless module_name.nil?
|
|
86
89
|
end
|
|
@@ -88,35 +91,25 @@ END
|
|
|
88
91
|
end
|
|
89
92
|
|
|
90
93
|
def self.get_module_name_from_file(file)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if Puppet.version.to_f >= 4.0 || RSpec.configuration.parser == 'future'
|
|
94
|
-
require 'puppet/pops'
|
|
95
|
-
p = Puppet::Pops::Parser::Lexer2.new
|
|
96
|
-
else
|
|
97
|
-
p = Puppet::Parser::Lexer.new
|
|
98
|
-
end
|
|
94
|
+
require 'puppet/pops'
|
|
95
|
+
p = Puppet::Pops::Parser::Lexer2.new
|
|
99
96
|
module_name = nil
|
|
100
97
|
p.string = File.read(file)
|
|
101
98
|
tokens = p.fullscan
|
|
102
99
|
|
|
103
|
-
i = tokens.index { |token| [
|
|
104
|
-
unless i.nil?
|
|
105
|
-
module_name = tokens[i + 1].last[:value].split('::').first
|
|
106
|
-
end
|
|
100
|
+
i = tokens.index { |token| %i[CLASS DEFINE].include? token.first }
|
|
101
|
+
module_name = tokens[i + 1].last[:value].split('::').first unless i.nil?
|
|
107
102
|
|
|
108
103
|
module_name
|
|
109
104
|
end
|
|
110
105
|
|
|
111
106
|
def self.is_module_dir?
|
|
112
|
-
Dir[
|
|
107
|
+
Dir['*'].entries.include? 'manifests'
|
|
113
108
|
end
|
|
114
109
|
|
|
115
|
-
def self.safe_mkdir(dir, verbose=true)
|
|
110
|
+
def self.safe_mkdir(dir, verbose = true)
|
|
116
111
|
if File.exist? dir
|
|
117
|
-
unless File.directory? dir
|
|
118
|
-
$stderr.puts "!! #{dir} already exists and is not a directory"
|
|
119
|
-
end
|
|
112
|
+
warn "!! #{dir} already exists and is not a directory" unless File.directory? dir
|
|
120
113
|
else
|
|
121
114
|
begin
|
|
122
115
|
FileUtils.mkdir dir
|
|
@@ -129,9 +122,7 @@ END
|
|
|
129
122
|
|
|
130
123
|
def self.safe_touch(file)
|
|
131
124
|
if File.exist? file
|
|
132
|
-
unless File.file? file
|
|
133
|
-
$stderr.puts "!! #{file} already exists and is not a regular file"
|
|
134
|
-
end
|
|
125
|
+
warn "!! #{file} already exists and is not a regular file" unless File.file? file
|
|
135
126
|
else
|
|
136
127
|
FileUtils.touch file
|
|
137
128
|
puts " + #{file}"
|
|
@@ -141,9 +132,7 @@ END
|
|
|
141
132
|
def self.safe_create_file(filename, content)
|
|
142
133
|
if File.exist? filename
|
|
143
134
|
old_content = File.read(filename)
|
|
144
|
-
if old_content != content
|
|
145
|
-
$stderr.puts "!! #{filename} already exists and differs from template"
|
|
146
|
-
end
|
|
135
|
+
warn "!! #{filename} already exists and differs from template" if old_content != content
|
|
147
136
|
else
|
|
148
137
|
File.open(filename, 'w') do |f|
|
|
149
138
|
f.puts content
|
|
@@ -169,17 +158,17 @@ END
|
|
|
169
158
|
Dir.respond_to?(:junction?) ? Dir.junction?(target) : File.symlink?(target)
|
|
170
159
|
end
|
|
171
160
|
|
|
172
|
-
def self.safe_make_link(source, target, verbose=true)
|
|
161
|
+
def self.safe_make_link(source, target, verbose = true)
|
|
173
162
|
if File.exist?(target) && !link?(target)
|
|
174
|
-
|
|
163
|
+
warn "!! #{target} already exists and is not a symlink"
|
|
175
164
|
return
|
|
176
165
|
end
|
|
177
166
|
|
|
178
167
|
return if link_to_source?(target, source)
|
|
179
168
|
|
|
180
169
|
if Puppet::Util::Platform.windows?
|
|
181
|
-
output = `call mklink /J "#{target.
|
|
182
|
-
unless
|
|
170
|
+
output = `call mklink /J "#{target.tr('/', '\\')}" "#{source}"`
|
|
171
|
+
unless $CHILD_STATUS.success?
|
|
183
172
|
puts output
|
|
184
173
|
abort
|
|
185
174
|
end
|
|
@@ -194,19 +183,19 @@ END
|
|
|
194
183
|
end
|
|
195
184
|
|
|
196
185
|
def self.safe_create_rakefile
|
|
197
|
-
content =
|
|
198
|
-
require 'rspec-puppet/rake_task'
|
|
186
|
+
content = <<~EOF
|
|
187
|
+
require 'rspec-puppet/rake_task'
|
|
199
188
|
|
|
200
|
-
begin
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
rescue Gem::LoadError
|
|
207
|
-
|
|
208
|
-
end
|
|
209
|
-
EOF
|
|
189
|
+
begin
|
|
190
|
+
if Gem::Specification::find_by_name('puppet-lint')
|
|
191
|
+
require 'puppet-lint/tasks/puppet-lint'
|
|
192
|
+
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "vendor/**/*.pp"]
|
|
193
|
+
task :default => [:rspec, :lint]
|
|
194
|
+
end
|
|
195
|
+
rescue Gem::LoadError
|
|
196
|
+
task :default => :rspec
|
|
197
|
+
end
|
|
198
|
+
EOF
|
|
210
199
|
safe_create_file('Rakefile', content)
|
|
211
200
|
end
|
|
212
201
|
end
|