rspec-puppet 2.10.0 → 2.11.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 +7 -1
- data/README.md +14 -0
- data/lib/rspec-puppet/adapters.rb +59 -0
- data/lib/rspec-puppet/facter_impl.rb +49 -0
- data/lib/rspec-puppet/support.rb +5 -5
- data/lib/rspec-puppet.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a8f890c54b412a4d326895c3c3cd0ecae65f915049c69b9cb75c0a5c2811365
|
4
|
+
data.tar.gz: 39407acdeb509d98797e23cdcb7e71c378d89186039538fba4cc25c6c1eb0bf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1105e0778581b90855d2d43511b1016cd0193fb088c0b4fbe7bf8de4947e3043a6a005bf1894fed0ac9fbdf87b283b9075997f47c2530ba82038db9c23d43e2f
|
7
|
+
data.tar.gz: 719205730a4e0f4bd0b17378872e134de10eedf3e623f9584aaf85577665033ea36d393d5a3619a0b5eb9fd091530bc6071d394291d7d48094aad11d00836585
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
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.11.0]
|
6
|
+
|
7
|
+
### Added
|
8
|
+
* Add setting to use custom Facter implementation ([GH-16](https://github.com/puppetlabs/rspec-puppet/pull/16))
|
9
|
+
|
5
10
|
## [2.10.0]
|
6
11
|
The release sees rspec-puppet move into the puppetlabs namespace
|
7
12
|
|
@@ -560,7 +565,8 @@ Thanks to Adrien Thebo, Alex Harvey, Brian, Dan Bode, Dominic Cleal, Javier Pala
|
|
560
565
|
## 1.0.1 and earlier
|
561
566
|
For changelog of versions 1.0.1 and earlier, see http://rspec-puppet.com/changelog/
|
562
567
|
|
563
|
-
[2.x]: https://github.com/puppetlabs/rspec-puppet/compare/v2.
|
568
|
+
[2.x]: https://github.com/puppetlabs/rspec-puppet/compare/v2.11.0...master
|
569
|
+
[2.11.0]: https://github.com/puppetlabs/rspec-puppet/compare/v2.10.0...v2.11.0
|
564
570
|
[2.10.0]: https://github.com/puppetlabs/rspec-puppet/compare/v2.9.0...v2.10.0
|
565
571
|
[2.9.0]: https://github.com/puppetlabs/rspec-puppet/compare/v2.8.0...v2.9.0
|
566
572
|
[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,17 @@ 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.
|
117
|
+
# The method noops if the constant is already set
|
118
|
+
#
|
119
|
+
# @param impl [Object]
|
120
|
+
def set_facter_impl(impl)
|
121
|
+
Object.send(:const_set, :FacterImpl, impl) unless defined? FacterImpl
|
122
|
+
end
|
123
|
+
|
111
124
|
def setup_puppet(example_group)
|
112
125
|
super
|
113
126
|
|
@@ -186,6 +199,12 @@ module RSpec::Puppet
|
|
186
199
|
end
|
187
200
|
|
188
201
|
class Adapter4X < Adapter40
|
202
|
+
def setup_puppet(example_group)
|
203
|
+
super
|
204
|
+
|
205
|
+
set_facter_impl(Facter)
|
206
|
+
end
|
207
|
+
|
189
208
|
def settings_map
|
190
209
|
super.concat([
|
191
210
|
[:trusted_server_facts, :trusted_server_facts]
|
@@ -194,6 +213,46 @@ module RSpec::Puppet
|
|
194
213
|
end
|
195
214
|
|
196
215
|
class Adapter6X < Adapter40
|
216
|
+
#
|
217
|
+
# @api private
|
218
|
+
#
|
219
|
+
# Check to see if Facter runtime implementations are supported in the
|
220
|
+
# current Puppet version
|
221
|
+
#
|
222
|
+
# @return [Boolean] true if runtime implementations are supported
|
223
|
+
def supports_facter_runtime?
|
224
|
+
unless defined?(@supports_facter_runtime)
|
225
|
+
begin
|
226
|
+
Puppet.runtime[:facter]
|
227
|
+
@supports_facter_runtime = true
|
228
|
+
rescue
|
229
|
+
@supports_facter_runtime = false
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
@supports_facter_runtime
|
234
|
+
end
|
235
|
+
|
236
|
+
def setup_puppet(example_group)
|
237
|
+
case RSpec.configuration.facter_implementation.to_sym
|
238
|
+
when :rspec
|
239
|
+
if supports_facter_runtime?
|
240
|
+
Puppet.runtime[:facter] = proc { RSpec::Puppet::FacterTestImpl.new }
|
241
|
+
set_facter_impl(Puppet.runtime[:facter])
|
242
|
+
else
|
243
|
+
warn "Facter runtime implementations are not supported in Puppet #{Puppet.version}, continuing with facter_implementation 'facter'"
|
244
|
+
RSpec.configuration.facter_implementation = 'facter'
|
245
|
+
set_facter_impl(Facter)
|
246
|
+
end
|
247
|
+
when :facter
|
248
|
+
set_facter_impl(Facter)
|
249
|
+
else
|
250
|
+
raise "Unsupported facter_implementation '#{RSpec.configuration.facter_implementation}'"
|
251
|
+
end
|
252
|
+
|
253
|
+
super
|
254
|
+
end
|
255
|
+
|
197
256
|
def settings_map
|
198
257
|
super.concat([
|
199
258
|
[: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
|
+
|
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.11.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: 2021-
|
13
|
+
date: 2021-11-10 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
|