rspec-puppet 2.10.0 → 2.12.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 +19 -1
- data/README.md +14 -0
- data/lib/rspec-puppet/adapters.rb +65 -0
- data/lib/rspec-puppet/facter_impl.rb +49 -0
- data/lib/rspec-puppet/matchers/create_generic.rb +2 -0
- data/lib/rspec-puppet/matchers/run.rb +2 -0
- data/lib/rspec-puppet/support.rb +5 -5
- data/lib/rspec-puppet.rb +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0983cc8fe444bc2035b1e58df39027ab7589cbeae175ace159a384dea8ef2cf
|
4
|
+
data.tar.gz: 8d91008e48102d7053911236a0173daa8daf64e94274a5f6046a45656770c8fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c2a790b3d4e4f7dc14dce67ba3c1e2c635534962acfa8523390aa2b07389c216c7ffb1cbddccd5ebd0e627372267dad4f07c59293e5fd36ce3d659b9d0c35bd
|
7
|
+
data.tar.gz: 7c9d11d0c5047af4ad2dd7a7743c2e5ff341257f9f2036beabd4b23a88294bf22e8d7e282f1a95cef230a66e7b6e5e5f2c429fb95a265116dd341bc38698aaa7
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,22 @@
|
|
2
2
|
All notable changes to this project will be documented in this file. This
|
3
3
|
project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [2.12.0]
|
6
|
+
|
7
|
+
### Added
|
8
|
+
* Handle nil autorequire results ([#22](https://github.com/puppetlabs/rspec-puppet/pull/22))
|
9
|
+
* Add the ability to use kind_of matchers ([#24](https://github.com/puppetlabs/rspec-puppet/pull/24))
|
10
|
+
|
11
|
+
## [2.11.1]
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
* Ensure FacterImpl consistency between example groups ([#19](https://github.com/puppetlabs/rspec-puppet/pull/19))
|
15
|
+
|
16
|
+
## [2.11.0]
|
17
|
+
|
18
|
+
### Added
|
19
|
+
* Add setting to use custom Facter implementation ([GH-16](https://github.com/puppetlabs/rspec-puppet/pull/16))
|
20
|
+
|
5
21
|
## [2.10.0]
|
6
22
|
The release sees rspec-puppet move into the puppetlabs namespace
|
7
23
|
|
@@ -560,7 +576,9 @@ Thanks to Adrien Thebo, Alex Harvey, Brian, Dan Bode, Dominic Cleal, Javier Pala
|
|
560
576
|
## 1.0.1 and earlier
|
561
577
|
For changelog of versions 1.0.1 and earlier, see http://rspec-puppet.com/changelog/
|
562
578
|
|
563
|
-
[2.x]: https://github.com/puppetlabs/rspec-puppet/compare/v2.
|
579
|
+
[2.x]: https://github.com/puppetlabs/rspec-puppet/compare/v2.11.1...master
|
580
|
+
[2.11.1]: https://github.com/puppetlabs/rspec-puppet/compare/v2.11.0..v2.11.1
|
581
|
+
[2.11.0]: https://github.com/puppetlabs/rspec-puppet/compare/v2.10.0...v2.11.0
|
564
582
|
[2.10.0]: https://github.com/puppetlabs/rspec-puppet/compare/v2.9.0...v2.10.0
|
565
583
|
[2.9.0]: https://github.com/puppetlabs/rspec-puppet/compare/v2.8.0...v2.9.0
|
566
584
|
[2.8.0]: https://github.com/puppetlabs/rspec-puppet/compare/v2.7.10...v2.8.0
|
data/README.md
CHANGED
@@ -230,6 +230,20 @@ In some circumstances (e.g. where your nodename/certname is not the same as
|
|
230
230
|
your FQDN), this behaviour is undesirable and can be disabled by changing this
|
231
231
|
setting to `false`.
|
232
232
|
|
233
|
+
#### facter\_implementation
|
234
|
+
Type | Default | Puppet Version(s)
|
235
|
+
------- | -------- | -----------------
|
236
|
+
String | `facter` | 6.25+, 7.12+
|
237
|
+
|
238
|
+
Configures rspec-puppet to use a specific Facter implementation for running
|
239
|
+
unit tests. If the `rspec` implementation is set and Puppet does not support
|
240
|
+
it, rspec-puppet will warn and fall back to the `facter` implementation.
|
241
|
+
Setting an unsupported option will make rspec-puppet raise an error.
|
242
|
+
|
243
|
+
* `facter` - Use the default implementation, honoring the Facter version specified in the Gemfile
|
244
|
+
* `rspec` - Use a custom hash-based implementation of Facter defined in
|
245
|
+
rspec-puppet (this provides a considerable gain in speed if tests are run with Facter 4)
|
246
|
+
|
233
247
|
## Naming conventions
|
234
248
|
|
235
249
|
For clarity and consistency, I recommend that you use the following directory
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rspec-puppet/facter_impl'
|
2
|
+
|
1
3
|
module RSpec::Puppet
|
2
4
|
module Adapters
|
3
5
|
|
@@ -108,6 +110,21 @@ module RSpec::Puppet
|
|
108
110
|
end
|
109
111
|
|
110
112
|
class Adapter40 < Base
|
113
|
+
#
|
114
|
+
# @api private
|
115
|
+
#
|
116
|
+
# Set the FacterImpl constant to the given Facter implementation or noop
|
117
|
+
# if the constant is already set. If a proc is given, it will only be
|
118
|
+
# called if FacterImpl is not defined.
|
119
|
+
#
|
120
|
+
# @param impl [Object, Proc] An object or a proc that implements the Facter API
|
121
|
+
def set_facter_impl(impl)
|
122
|
+
return if defined?(FacterImpl)
|
123
|
+
|
124
|
+
impl = impl.call if impl.is_a?(Proc)
|
125
|
+
Object.send(:const_set, :FacterImpl, impl)
|
126
|
+
end
|
127
|
+
|
111
128
|
def setup_puppet(example_group)
|
112
129
|
super
|
113
130
|
|
@@ -186,6 +203,12 @@ module RSpec::Puppet
|
|
186
203
|
end
|
187
204
|
|
188
205
|
class Adapter4X < Adapter40
|
206
|
+
def setup_puppet(example_group)
|
207
|
+
super
|
208
|
+
|
209
|
+
set_facter_impl(Facter)
|
210
|
+
end
|
211
|
+
|
189
212
|
def settings_map
|
190
213
|
super.concat([
|
191
214
|
[:trusted_server_facts, :trusted_server_facts]
|
@@ -194,6 +217,48 @@ module RSpec::Puppet
|
|
194
217
|
end
|
195
218
|
|
196
219
|
class Adapter6X < Adapter40
|
220
|
+
#
|
221
|
+
# @api private
|
222
|
+
#
|
223
|
+
# Check to see if Facter runtime implementations are supported in the
|
224
|
+
# current Puppet version
|
225
|
+
#
|
226
|
+
# @return [Boolean] true if runtime implementations are supported
|
227
|
+
def supports_facter_runtime?
|
228
|
+
unless defined?(@supports_facter_runtime)
|
229
|
+
begin
|
230
|
+
Puppet.runtime[:facter]
|
231
|
+
@supports_facter_runtime = true
|
232
|
+
rescue
|
233
|
+
@supports_facter_runtime = false
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
@supports_facter_runtime
|
238
|
+
end
|
239
|
+
|
240
|
+
def setup_puppet(example_group)
|
241
|
+
case RSpec.configuration.facter_implementation.to_sym
|
242
|
+
when :rspec
|
243
|
+
if supports_facter_runtime?
|
244
|
+
# Lazily instantiate FacterTestImpl here to optimize memory
|
245
|
+
# allocation, as the proc will only be called if FacterImpl is unset
|
246
|
+
set_facter_impl(proc { RSpec::Puppet::FacterTestImpl.new })
|
247
|
+
Puppet.runtime[:facter] = FacterImpl
|
248
|
+
else
|
249
|
+
warn "Facter runtime implementations are not supported in Puppet #{Puppet.version}, continuing with facter_implementation 'facter'"
|
250
|
+
RSpec.configuration.facter_implementation = :facter
|
251
|
+
set_facter_impl(Facter)
|
252
|
+
end
|
253
|
+
when :facter
|
254
|
+
set_facter_impl(Facter)
|
255
|
+
else
|
256
|
+
raise "Unsupported facter_implementation '#{RSpec.configuration.facter_implementation}'"
|
257
|
+
end
|
258
|
+
|
259
|
+
super
|
260
|
+
end
|
261
|
+
|
197
262
|
def settings_map
|
198
263
|
super.concat([
|
199
264
|
[:basemodulepath, :basemodulepath],
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module RSpec::Puppet
|
2
|
+
|
3
|
+
# Implements a simple hash-based version of Facter to be used in module tests
|
4
|
+
# that use rspec-puppet.
|
5
|
+
class FacterTestImpl
|
6
|
+
def initialize
|
7
|
+
@facts = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def value(fact_name)
|
11
|
+
@facts[fact_name.to_s]
|
12
|
+
end
|
13
|
+
|
14
|
+
def clear
|
15
|
+
@facts.clear
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
@facts
|
20
|
+
end
|
21
|
+
|
22
|
+
def add(name, options = {}, &block)
|
23
|
+
raise 'Facter.add expects a block' unless block_given?
|
24
|
+
@facts[name.to_s] = instance_eval(&block)
|
25
|
+
end
|
26
|
+
|
27
|
+
# noop methods
|
28
|
+
def debugging(arg); end
|
29
|
+
|
30
|
+
def reset; end
|
31
|
+
|
32
|
+
def search(*paths); end
|
33
|
+
|
34
|
+
def setup_logging; end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def setcode(string = nil, &block)
|
39
|
+
if block_given?
|
40
|
+
value = block.call
|
41
|
+
else
|
42
|
+
value = string
|
43
|
+
end
|
44
|
+
|
45
|
+
value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -313,6 +313,8 @@ module RSpec::Puppet
|
|
313
313
|
if resource.resource_type.respond_to?(func)
|
314
314
|
resource.resource_type.send(func) do |t, b|
|
315
315
|
Array(resource.to_ral.instance_eval(&b)).each do |dep|
|
316
|
+
next if dep.nil?
|
317
|
+
|
316
318
|
res = "#{t.to_s.capitalize}[#{dep}]"
|
317
319
|
if r = relationship_refs(res, type, visited)
|
318
320
|
results << res
|
@@ -35,6 +35,8 @@ module RSpec::Puppet
|
|
35
35
|
case @expected_return
|
36
36
|
when Regexp
|
37
37
|
return !!(@actual_return =~ @expected_return)
|
38
|
+
when RSpec::Mocks::ArgumentMatchers::KindOf, RSpec::Matchers::AliasedMatcher
|
39
|
+
return @expected_return === @actual_return
|
38
40
|
else
|
39
41
|
return @actual_return == @expected_return
|
40
42
|
end
|
data/lib/rspec-puppet/support.rb
CHANGED
@@ -337,7 +337,7 @@ module RSpec::Puppet
|
|
337
337
|
{"servername" => "fqdn",
|
338
338
|
"serverip" => "ipaddress"
|
339
339
|
}.each do |var, fact|
|
340
|
-
if value =
|
340
|
+
if value = FacterImpl.value(fact)
|
341
341
|
server_facts[var] = value
|
342
342
|
else
|
343
343
|
warn "Could not retrieve fact #{fact}"
|
@@ -345,8 +345,8 @@ module RSpec::Puppet
|
|
345
345
|
end
|
346
346
|
|
347
347
|
if server_facts["servername"].nil?
|
348
|
-
host =
|
349
|
-
if domain =
|
348
|
+
host = FacterImpl.value(:hostname)
|
349
|
+
if domain = FacterImpl.value(:domain)
|
350
350
|
server_facts["servername"] = [host, domain].join(".")
|
351
351
|
else
|
352
352
|
server_facts["servername"] = host
|
@@ -478,8 +478,8 @@ module RSpec::Puppet
|
|
478
478
|
|
479
479
|
def stub_facts!(facts)
|
480
480
|
Puppet.settings[:autosign] = false if Puppet.settings.include? :autosign
|
481
|
-
|
482
|
-
facts.each { |k, v|
|
481
|
+
FacterImpl.clear
|
482
|
+
facts.each { |k, v| FacterImpl.add(k, :weight => 999) { setcode { v } } }
|
483
483
|
end
|
484
484
|
|
485
485
|
def build_catalog(*args)
|
data/lib/rspec-puppet.rb
CHANGED
@@ -43,6 +43,7 @@ RSpec.configure do |c|
|
|
43
43
|
c.add_setting :default_node_params, :default => {}
|
44
44
|
c.add_setting :default_trusted_facts, :default => {}
|
45
45
|
c.add_setting :default_trusted_external_data, :default => {}
|
46
|
+
c.add_setting :facter_implementation, :default => :facter
|
46
47
|
c.add_setting :hiera_config, :default => Puppet::Util::Platform.actually_windows? ? 'c:/nul/' : '/dev/null'
|
47
48
|
c.add_setting :parser, :default => 'current'
|
48
49
|
c.add_setting :trusted_node_data, :default => false
|
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: 2.
|
4
|
+
version: 2.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Sharpe
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/rspec-puppet/example/provider_example_group.rb
|
54
54
|
- lib/rspec-puppet/example/type_alias_example_group.rb
|
55
55
|
- lib/rspec-puppet/example/type_example_group.rb
|
56
|
+
- lib/rspec-puppet/facter_impl.rb
|
56
57
|
- lib/rspec-puppet/matchers.rb
|
57
58
|
- lib/rspec-puppet/matchers/allow_value.rb
|
58
59
|
- lib/rspec-puppet/matchers/compile.rb
|
@@ -95,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
96
|
- !ruby/object:Gem::Version
|
96
97
|
version: '0'
|
97
98
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.7.6.2
|
99
|
+
rubygems_version: 3.1.6
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: RSpec tests for your Puppet manifests
|