rspec-puppet 2.6.0 → 2.7.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 +7 -0
- data/CHANGELOG.md +228 -0
- data/README.md +67 -35
- data/lib/rspec-puppet/adapters.rb +62 -5
- data/lib/rspec-puppet/consts.rb +57 -0
- data/lib/rspec-puppet/coverage.rb +84 -35
- data/lib/rspec-puppet/matchers/compile.rb +0 -2
- data/lib/rspec-puppet/matchers/count_generic.rb +18 -14
- data/lib/rspec-puppet/matchers/create_generic.rb +1 -3
- data/lib/rspec-puppet/matchers/parameter_matcher.rb +22 -2
- data/lib/rspec-puppet/monkey_patches/win32/registry.rb +79 -0
- data/lib/rspec-puppet/monkey_patches/win32/taskscheduler.rb +118 -0
- data/lib/rspec-puppet/monkey_patches/windows/taskschedulerconstants.rb +271 -0
- data/lib/rspec-puppet/monkey_patches.rb +244 -54
- data/lib/rspec-puppet/setup.rb +62 -20
- data/lib/rspec-puppet/support.rb +94 -39
- data/lib/rspec-puppet/tasks/release_test.rb +145 -0
- data/lib/rspec-puppet.rb +50 -6
- metadata +36 -35
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: fe98cc153715d0f4a7ea74302e22db11b27f256b
|
|
4
|
+
data.tar.gz: 0ff2d613a201b5b50779674bc126904555203c66
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 24db31229795fcfd326243a0b2fc20a17c78b6ee772f28092f9afd917534a3dd307d688c3934ef590c857027944c6fc9432baea652c7c4ecfbd40e563eb89dd1
|
|
7
|
+
data.tar.gz: 50fa9b5882460e10e4148c4b78372b3f366178738fe5fa92dfee522e8b4811a5378156623e0f6d13e030c912f9a5560d6f4051e0cd7aa7a249c59600a55fe20f
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,234 @@
|
|
|
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.7.0]
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
* Official Puppet 6 support added.
|
|
9
|
+
* When testing resource parameter values, the values received from Puppet are
|
|
10
|
+
now reencoded before testing to ensure that the line endings (if present)
|
|
11
|
+
match the platform being tested.
|
|
12
|
+
* `vendormoduledir` and `basemodulepath` settings (introduced in Puppet 6) are
|
|
13
|
+
now configurable in rspec-puppet.
|
|
14
|
+
|
|
15
|
+
## [2.6.15]
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
* Added a Puppet 6.x adapter so that rspec-puppet does not try to set removed
|
|
20
|
+
Puppet settings (specifically `trusted_server_facts`) when running tests
|
|
21
|
+
against the upcoming Puppet 6.0.0 release.
|
|
22
|
+
|
|
23
|
+
## [2.6.14]
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
* If present, `Win32::Dir` will be used to managed the fixtures directory
|
|
28
|
+
junction on Windows as the builtin `File` module does not have complete
|
|
29
|
+
support for directory junctions on Ruby <= 2.1.
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
* Resource coverage results are now exposed to the configured RSpec reporter
|
|
34
|
+
rather than only being printed to STDOUT.
|
|
35
|
+
* If running with parallel\_tests, resource coverage data is stored in
|
|
36
|
+
per-process temp files and merged at the end of the final rspec process,
|
|
37
|
+
allowing for a complete coverage report to be generated when splitting
|
|
38
|
+
a test suite across multiple rspec processes.
|
|
39
|
+
|
|
40
|
+
## [2.6.13]
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
* rspec-puppet no longer attempts to set the `trusted_server_facts` Puppet
|
|
45
|
+
setting on Puppet 4.0.0, as the setting was only introduced in Puppet 4.1.0.
|
|
46
|
+
* Automatic `Selinux` stubbing introduced in 2.6.12 no longer assumes the use
|
|
47
|
+
of rspec-mocks. If rspec-mocks is not available, it will fall back to mocha
|
|
48
|
+
and finally fall back to doing nothing if neither is available.
|
|
49
|
+
|
|
50
|
+
## [2.6.12]
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
|
|
54
|
+
* Updated `Win32::TaskScheduler` stubs to match the latest release of
|
|
55
|
+
`win32-taskscheduler`.
|
|
56
|
+
* The `os` structured fact is now correctly treated as a Hash when determining
|
|
57
|
+
the platform that rspec-puppet pretends to be.
|
|
58
|
+
* The default resources that Puppet adds to the catalogue (`Class[main]`,
|
|
59
|
+
`Class[Settings]`, etc) are now filtered out of the catalogue when using the
|
|
60
|
+
`have_resource_count` matcher, rather than simply subtracted from the
|
|
61
|
+
resource count. This allows the `have_resource_count` matcher to be used on
|
|
62
|
+
subsects of the catalogue (`exported_resources` for example).
|
|
63
|
+
* When running on Windows, rspec-puppet will now convert Puppet configuration
|
|
64
|
+
settings from `/dev/null` to `NUL`, preventing Puppet from automatically
|
|
65
|
+
creating directories like `C:\dev` when running tests on Windows as an
|
|
66
|
+
Administrator.
|
|
67
|
+
* When overriding fact values, rspec-puppet will now assign the stub facts
|
|
68
|
+
a weight of 1000 to ensure that they override the generated fact values from
|
|
69
|
+
Facter 3.x.
|
|
70
|
+
* `Selinux.is_selinux_enabled` is now automatically stubbed to return 0 to
|
|
71
|
+
disable any SELinux related apply-time validation of resources.
|
|
72
|
+
* When testing against Puppet 3.x, rspec-puppet will now honour the
|
|
73
|
+
`RSpec.configuration.parser` value when determining the module name to set
|
|
74
|
+
up the fixture symlink.
|
|
75
|
+
* When testing for the absence of a parameter using `only_with(:parameter_name
|
|
76
|
+
=> nil`), this will no longer incorrectly affect the expected parameter
|
|
77
|
+
count.
|
|
78
|
+
|
|
79
|
+
## [2.6.11]
|
|
80
|
+
|
|
81
|
+
### Fixed
|
|
82
|
+
|
|
83
|
+
* The `server_facts` hash is now only built if
|
|
84
|
+
`RSpec.configuration.trusted_server_facts` is `true`. Previously, this was
|
|
85
|
+
always built but only used when enabled.
|
|
86
|
+
|
|
87
|
+
## [2.6.10]
|
|
88
|
+
|
|
89
|
+
### Fixed
|
|
90
|
+
|
|
91
|
+
* Replaced deprecated `File.exists?` calls in `rspec-puppet-init` with
|
|
92
|
+
`File.exist?`, which behaves much more reliably in respect to symlinks.
|
|
93
|
+
* Stubbed out `Puppet::Util::Windows::Security.supports_acl?` when compiling
|
|
94
|
+
the catalogue as this check only make sense when applying the resources to
|
|
95
|
+
a host and prevents testing Windows File resources on non-Windows hosts.
|
|
96
|
+
* The cached default provider for native types is now reset before compiling
|
|
97
|
+
a new catalogue.
|
|
98
|
+
* Resource titles that contain single quotes are now rendered correctly,
|
|
99
|
+
allowing them to be tested.
|
|
100
|
+
* When pretending to be a different platform, the methods in
|
|
101
|
+
`Puppet::Util::Platform` are now stubbed after the catalogue has been
|
|
102
|
+
compiled, allowing path related logic in custom facts to behave as expected.
|
|
103
|
+
* A mock version of `Win32::TaskScheduler` has been added to rspec-puppet.
|
|
104
|
+
This will be loaded when running rspec-puppet on a non-Windows host in order
|
|
105
|
+
to allow testing of catalogues containing Scheduled\_task resources.
|
|
106
|
+
* Stubbed out the `manages_symlinks` feature on
|
|
107
|
+
`Puppet::Type::File::ProviderWindows` as this can only be evaluated at apply
|
|
108
|
+
time and prevents testing Windows File resources that manage symlinks on
|
|
109
|
+
non-Windows hosts.
|
|
110
|
+
* Fixed unhandled exception when testing resource parameters where the
|
|
111
|
+
expected value is an Array or a Hash and the actual value is a different
|
|
112
|
+
data type.
|
|
113
|
+
* A mock version of `Win32::Registry` has been added to rspec-puppet. This
|
|
114
|
+
will be loaded when running rspec-puppet on a non-Windows host in order to
|
|
115
|
+
allow testing of catalogues that contain Exec resources that use the
|
|
116
|
+
`powershell` provider from the `puppetlabs/puppetlabs-powershell` module.
|
|
117
|
+
* Fixed a case where the order in which tests are run can cause a resource
|
|
118
|
+
that is being tested to be falsely reported as untested in the coverage
|
|
119
|
+
report.
|
|
120
|
+
|
|
121
|
+
### Changed
|
|
122
|
+
|
|
123
|
+
* The tests for the `compile` matcher have been updated to support the new
|
|
124
|
+
error message format introduced in Puppet 5.3.4.
|
|
125
|
+
* The builtin `$server_facts` hash is now populated on versions of Puppet that
|
|
126
|
+
support it (Puppet >= 4.3). This is not currently enabled by default, but
|
|
127
|
+
can be enabled by setting `RSpec.configuration.trusted_server_facts` to
|
|
128
|
+
`true`.
|
|
129
|
+
* `$facts['os']['family']` and `$facts['os']['name']` are now checked when
|
|
130
|
+
determining if rspec-puppet needs to pretend to be running on a different
|
|
131
|
+
platform (previously only `$facts['operatingsystem']` and
|
|
132
|
+
`$facts['osfamily']` were used).
|
|
133
|
+
|
|
134
|
+
## [2.6.9]
|
|
135
|
+
|
|
136
|
+
### Fixed
|
|
137
|
+
|
|
138
|
+
* Initialise Hiera 3 before loading any monkey patches to ensure that the
|
|
139
|
+
correct code is loaded for the actual platform running the tests.
|
|
140
|
+
|
|
141
|
+
## [2.6.8]
|
|
142
|
+
|
|
143
|
+
### Fixed
|
|
144
|
+
|
|
145
|
+
* Performance regression with Puppet < 4.0.0 due to overly agressive cache
|
|
146
|
+
invalidation.
|
|
147
|
+
* Clarified rspec-puppet-init output when run inside a directory that does not
|
|
148
|
+
contain a `metadata.json` file.
|
|
149
|
+
|
|
150
|
+
## [2.6.7]
|
|
151
|
+
|
|
152
|
+
### Fixed
|
|
153
|
+
|
|
154
|
+
* An issue where the optional minimum resource coverage check would throw an
|
|
155
|
+
exception when the coverage wasn't 100%.
|
|
156
|
+
|
|
157
|
+
## [2.6.6]
|
|
158
|
+
|
|
159
|
+
### Fixed
|
|
160
|
+
|
|
161
|
+
* Fixed an issue caused by `Puppet::Util.get_env` when pretending to be a
|
|
162
|
+
Windows host.
|
|
163
|
+
|
|
164
|
+
## [2.6.5]
|
|
165
|
+
|
|
166
|
+
### Changed
|
|
167
|
+
|
|
168
|
+
* `derive_node_facts_from_nodename` setting added to disable the overriding of
|
|
169
|
+
`fqdn`, `hostname`, and `domain` facts with values derived from the node
|
|
170
|
+
name specified with `let(:node)`.
|
|
171
|
+
|
|
172
|
+
### Fixed
|
|
173
|
+
|
|
174
|
+
* The `trusted_facts` hash now accepts symbol keys, matching the behaviour of
|
|
175
|
+
the `facts` hash.
|
|
176
|
+
* The modifications made to Puppet internals are now contained to rspec-puppet
|
|
177
|
+
examples, preventing them from bleeding out into other examples in the same
|
|
178
|
+
RSpec process (like Ruby unit tests).
|
|
179
|
+
* rspec-puppet no longer attempts to configure settings for Puppet 3.x
|
|
180
|
+
releases that they do not support.
|
|
181
|
+
|
|
182
|
+
## [2.6.4]
|
|
183
|
+
|
|
184
|
+
### Fixed
|
|
185
|
+
|
|
186
|
+
* A regression that prevented environment names to be specified as a symbol.
|
|
187
|
+
* A regression that prevented the `environmentpath` setting from taking
|
|
188
|
+
effect.
|
|
189
|
+
* Stubbed out the automatic confines created by resource providers on their
|
|
190
|
+
specified commands, which was preventing the correct provider from being
|
|
191
|
+
assigned to a resource when performing cross-platform testing.
|
|
192
|
+
|
|
193
|
+
## [2.6.3]
|
|
194
|
+
|
|
195
|
+
### Fixed
|
|
196
|
+
|
|
197
|
+
* Facts derived from the node name now only get merged on top of the facts
|
|
198
|
+
specified by `RSpec.configuration.default_facts` and `let(:facts)` if the
|
|
199
|
+
node name has been manually specified with `let(:node)`.
|
|
200
|
+
|
|
201
|
+
## [2.6.2]
|
|
202
|
+
|
|
203
|
+
### Changed
|
|
204
|
+
|
|
205
|
+
* Puppet 5.0.x added to the CI test matrices.
|
|
206
|
+
* The automatic setup code now checks for the presence of `metadata.json` in
|
|
207
|
+
the working directory. If not present, it assumes that rspec-puppet is
|
|
208
|
+
running from inside a control repo instead of a module and skips creating
|
|
209
|
+
the `spec/fixtures` directory structure and link.
|
|
210
|
+
|
|
211
|
+
### Added
|
|
212
|
+
|
|
213
|
+
* A new configuration option has been added
|
|
214
|
+
(`RSpec.configuration.setup_fixtures`) that controls whether rspec-puppet
|
|
215
|
+
will manage the `spec/fixtures` link.
|
|
216
|
+
|
|
217
|
+
### Fixed
|
|
218
|
+
|
|
219
|
+
* A race condition when running rspec-puppet under parallel\_tests causing
|
|
220
|
+
errors when creating the `spec/fixtures` link.
|
|
221
|
+
* The contents of the `networking` fact hash is no longer cleared when merging
|
|
222
|
+
in the facts derived from the node name.
|
|
223
|
+
|
|
224
|
+
## [2.6.1]
|
|
225
|
+
|
|
226
|
+
### Fixed
|
|
227
|
+
|
|
228
|
+
* 2.6.0 introduced a change to how resource titles are rendered in the test
|
|
229
|
+
manifest which caused them to get rendered as double quoted strings. This
|
|
230
|
+
caused a failure for tests of defined types that contained `$` characters
|
|
231
|
+
as Puppet would try and interpolate the values in the title as variable(s).
|
|
232
|
+
|
|
5
233
|
## [2.6.0]
|
|
6
234
|
|
|
7
235
|
The Windows parity release. rspec-puppet now officially supports Windows. A lot
|
data/README.md
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
## Starting out with a new module
|
|
14
14
|
|
|
15
|
-
When you start out on a new module, run `rspec-puppet-init` to create the necessary files to configure rspec-puppet for your module's tests.
|
|
15
|
+
When you start out on a new module, create a metadata.json file for your module and then run `rspec-puppet-init` to create the necessary files to configure rspec-puppet for your module's tests.
|
|
16
|
+
|
|
16
17
|
|
|
17
18
|
## Configure manifests for Puppet 4
|
|
18
19
|
|
|
@@ -61,36 +62,36 @@ The path to the directory containing your basic manifests like `site.pp`.
|
|
|
61
62
|
|
|
62
63
|
#### module\_path
|
|
63
64
|
Type | Default | Puppet Version(s)
|
|
64
|
-
------ | -------- |
|
|
65
|
-
String | Required | 2.x, 3.x, 4.x
|
|
65
|
+
------ | -------- | ------------------
|
|
66
|
+
String | Required | 2.x, 3.x, 4.x, 5.x
|
|
66
67
|
|
|
67
68
|
The path to the directory containing your Puppet modules.
|
|
68
69
|
|
|
69
70
|
#### default\_facts
|
|
70
71
|
Type | Default | Puppet Version(s)
|
|
71
|
-
---- | ------- |
|
|
72
|
-
Hash | `{}` | 2.x, 3.x, 4.x
|
|
72
|
+
---- | ------- | ------------------
|
|
73
|
+
Hash | `{}` | 2.x, 3.x, 4.x, 5.x
|
|
73
74
|
|
|
74
75
|
A hash of default facts that should be used for all the tests.
|
|
75
76
|
|
|
76
77
|
#### hiera\_config
|
|
77
78
|
Type | Default | Puppet Version(s)
|
|
78
79
|
------ | ------------- | -----------------
|
|
79
|
-
String | `"/dev/null"` | 3.x, 4.x
|
|
80
|
+
String | `"/dev/null"` | 3.x, 4.x, 5.x
|
|
80
81
|
|
|
81
82
|
The path to your `hiera.yaml` file (if used).
|
|
82
83
|
|
|
83
84
|
#### default\_node\_params
|
|
84
85
|
Type | Default | Puppet Version(s)
|
|
85
86
|
---- | ------- | -----------------
|
|
86
|
-
Hash | `{}` | 4.x
|
|
87
|
+
Hash | `{}` | 4.x, 5.x
|
|
87
88
|
|
|
88
89
|
A hash of default node parameters that should be used for all the tests.
|
|
89
90
|
|
|
90
91
|
#### default\_trusted\_facts
|
|
91
92
|
Type | Default | Puppet Version(s)
|
|
92
93
|
---- | ------- | -----------------
|
|
93
|
-
Hash | `{}` | 4.x
|
|
94
|
+
Hash | `{}` | 4.x, 5.x
|
|
94
95
|
|
|
95
96
|
A hash of default trusted facts that should be used for all the tests
|
|
96
97
|
(available in the manifests as the `$trusted` hash). In order to use this, the
|
|
@@ -99,22 +100,30 @@ A hash of default trusted facts that should be used for all the tests
|
|
|
99
100
|
#### trusted\_node\_data
|
|
100
101
|
Type | Default | Puppet Version(s)
|
|
101
102
|
------- | ------- | -----------------
|
|
102
|
-
Boolean | `false` | 3.
|
|
103
|
+
Boolean | `false` | >=3.4, 4.x, 5.x
|
|
103
104
|
|
|
104
105
|
Configures rspec-puppet to use the `$trusted` hash when compiling the
|
|
105
106
|
catalogues.
|
|
106
107
|
|
|
108
|
+
#### trusted\_server\_facts
|
|
109
|
+
Type | Default | Puppet Version(s)
|
|
110
|
+
------- | ------- | -----------------
|
|
111
|
+
Boolean | `false` | >=4.3, 5.x
|
|
112
|
+
|
|
113
|
+
Configures rspec-puppet to use the `$server_facts` hash when compiling the
|
|
114
|
+
catalogues.
|
|
115
|
+
|
|
107
116
|
#### confdir
|
|
108
117
|
Type | Default | Puppet Version(s)
|
|
109
|
-
------ | --------------- |
|
|
110
|
-
String | `"/etc/puppet"` | 2.x, 3.x, 4.x
|
|
118
|
+
------ | --------------- | ------------------
|
|
119
|
+
String | `"/etc/puppet"` | 2.x, 3.x, 4.x, 5.x
|
|
111
120
|
|
|
112
121
|
The path to the main Puppet configuration directory.
|
|
113
122
|
|
|
114
123
|
#### config
|
|
115
124
|
Type | Default | Puppet Version(s)
|
|
116
|
-
------ | ---------------------- |
|
|
117
|
-
String | Puppet's default value | 2.x, 3.x, 4.x
|
|
125
|
+
------ | ---------------------- | ------------------
|
|
126
|
+
String | Puppet's default value | 2.x, 3.x, 4.x, 5.x
|
|
118
127
|
|
|
119
128
|
The path to `puppet.conf`.
|
|
120
129
|
|
|
@@ -136,21 +145,21 @@ stored outside of modules.
|
|
|
136
145
|
#### environmentpath
|
|
137
146
|
Type | Default | Puppet Version(s)
|
|
138
147
|
------ | ------------------------------------- | -----------------
|
|
139
|
-
String | `"/etc/puppetlabs/code/environments"` | 4.x
|
|
148
|
+
String | `"/etc/puppetlabs/code/environments"` | 4.x, 5.x
|
|
140
149
|
|
|
141
150
|
The search path for environment directories.
|
|
142
151
|
|
|
143
152
|
#### parser
|
|
144
153
|
Type | Default | Puppet Version(s)
|
|
145
154
|
------ | ----------- | -----------------
|
|
146
|
-
String | `"current"` | 3.
|
|
155
|
+
String | `"current"` | >= 3.2
|
|
147
156
|
|
|
148
157
|
This switches between the 3.x (`current`) and 4.x (`future`) parsers.
|
|
149
158
|
|
|
150
159
|
#### ordering
|
|
151
160
|
Type | Default | Puppet Version(s)
|
|
152
161
|
------ | -------------- | -----------------
|
|
153
|
-
String | `"title-hash"` | 3.
|
|
162
|
+
String | `"title-hash"` | >= 3.3, 4.x, 5.x
|
|
154
163
|
|
|
155
164
|
How unrelated resources should be ordered when applying a catalogue.
|
|
156
165
|
* `manifest` - Use the order in which the resources are declared in the
|
|
@@ -162,7 +171,7 @@ How unrelated resources should be ordered when applying a catalogue.
|
|
|
162
171
|
#### strict\_variables
|
|
163
172
|
Type | Default | Puppet Version(s)
|
|
164
173
|
------- | ------- | -----------------
|
|
165
|
-
Boolean | `false` | 3.
|
|
174
|
+
Boolean | `false` | >= 3.5, 4.x, 5.x
|
|
166
175
|
|
|
167
176
|
Makes Puppet raise an error when it tries to reference a variable that hasn't
|
|
168
177
|
been defined (not including variables that have been explicitly set to
|
|
@@ -171,21 +180,42 @@ been defined (not including variables that have been explicitly set to
|
|
|
171
180
|
#### stringify\_facts
|
|
172
181
|
Type | Default | Puppet Version(s)
|
|
173
182
|
------- | ------- | -----------------
|
|
174
|
-
Boolean | `true` | 3.
|
|
183
|
+
Boolean | `true` | >= 3.3, 4.x, 5.x
|
|
175
184
|
|
|
176
185
|
Makes rspec-puppet coerce all the fact values into strings (matching the
|
|
177
186
|
behaviour of older versions of Puppet).
|
|
178
187
|
|
|
179
188
|
#### enable\_pathname\_stubbing
|
|
180
189
|
Type | Default | Puppet Version(s)
|
|
181
|
-
------- | ------- |
|
|
182
|
-
Boolean |`false` | 2.x, 3.x, 4.x
|
|
190
|
+
------- | ------- | ------------------
|
|
191
|
+
Boolean |`false` | 2.x, 3.x, 4.x, 5.x
|
|
183
192
|
|
|
184
193
|
Configures rspec-puppet to stub out `Pathname#absolute?` with it's own
|
|
185
194
|
implementation. This should only be enabled if you're running into an issue
|
|
186
195
|
running cross-platform tests where you have Ruby code (types, providers,
|
|
187
196
|
functions, etc) that use `Pathname#absolute?`.
|
|
188
197
|
|
|
198
|
+
#### setup\_fixtures
|
|
199
|
+
Type | Default | Puppet Version(s)
|
|
200
|
+
------- | ------- | ------------------
|
|
201
|
+
Boolean | `true` | 2.x, 3.x, 4.x, 5.x
|
|
202
|
+
|
|
203
|
+
Configures rspec-puppet to automatically create a link from the root of your
|
|
204
|
+
module to `spec/fixtures/<module name>` at the beginning of the test run.
|
|
205
|
+
|
|
206
|
+
#### derive\_node\_facts\_from\_nodename
|
|
207
|
+
Type | Default | Puppet Version(s)
|
|
208
|
+
------- | ------- | -----------------
|
|
209
|
+
Boolean | `true` | 2.x, 3.x, 4.x, 5.x
|
|
210
|
+
|
|
211
|
+
If `true`, rspec-puppet will override the `fdqn`, `hostname`, and `domain`
|
|
212
|
+
facts with values that it derives from the node name (specified with
|
|
213
|
+
`let(:node)`.
|
|
214
|
+
|
|
215
|
+
In some circumstances (e.g. where your nodename/certname is not the same as
|
|
216
|
+
your FQDN), this behaviour is undesirable and can be disabled by changing this
|
|
217
|
+
setting to `false`.
|
|
218
|
+
|
|
189
219
|
## Naming conventions
|
|
190
220
|
|
|
191
221
|
For clarity and consistency, I recommend that you use the following directory
|
|
@@ -531,7 +561,7 @@ We can write the following testcase (in `spec/defines/sysctl_spec.rb`)
|
|
|
531
561
|
```ruby
|
|
532
562
|
describe 'sysctl' do
|
|
533
563
|
let(:title) { 'baz' }
|
|
534
|
-
let(:params) { {
|
|
564
|
+
let(:params) { { 'value' => 'foo' } }
|
|
535
565
|
|
|
536
566
|
it { is_expected.to contain_exec('sysctl/reload').with_command("/sbin/sysctl -p /etc/sysctl.conf") }
|
|
537
567
|
end
|
|
@@ -549,21 +579,21 @@ Parameters of a defined type, class or application can be passed defining `:para
|
|
|
549
579
|
and passing it a hash as seen below.
|
|
550
580
|
|
|
551
581
|
```ruby
|
|
552
|
-
let(:params) { {
|
|
582
|
+
let(:params) { {'ensure' => 'present', ...} }
|
|
553
583
|
```
|
|
554
584
|
|
|
555
585
|
For passing Puppet's `undef` as a paremeter value, you can simply use `:undef` and it will
|
|
556
586
|
be translated to `undef` when compiling. For example:
|
|
557
587
|
|
|
558
588
|
```ruby
|
|
559
|
-
let(:params) { {
|
|
589
|
+
let(:params) { {'user' => :undef, ...} }
|
|
560
590
|
```
|
|
561
591
|
|
|
562
592
|
For references to nodes or resources as seen when using `require` or `before` properties,
|
|
563
593
|
or an `application` resource you can pass the string as an argument to the `ref` helper:
|
|
564
594
|
|
|
565
595
|
```ruby
|
|
566
|
-
let(:params) {
|
|
596
|
+
let(:params) { 'require' => ref('Package', 'sudoku') }
|
|
567
597
|
```
|
|
568
598
|
|
|
569
599
|
Which translates to:
|
|
@@ -575,7 +605,7 @@ mydefine { 'mytitle': require => Package['sudoku'] }
|
|
|
575
605
|
Another example, for an application setup (when using `app_management`):
|
|
576
606
|
|
|
577
607
|
```ruby
|
|
578
|
-
let(:params) { {
|
|
608
|
+
let(:params) { { 'nodes' => { ref('Node', 'dbnode') => ref('Myapp::Mycomponent', 'myapp') } } }
|
|
579
609
|
```
|
|
580
610
|
|
|
581
611
|
Will translate to:
|
|
@@ -608,7 +638,7 @@ By default, the test environment contains no facts for your manifest to use.
|
|
|
608
638
|
You can set them with a hash
|
|
609
639
|
|
|
610
640
|
```ruby
|
|
611
|
-
let(:facts) { {
|
|
641
|
+
let(:facts) { {'operatingsystem' => 'Debian', 'kernel' => 'Linux', ...} }
|
|
612
642
|
```
|
|
613
643
|
|
|
614
644
|
Facts may be expressed as a value (shown in the previous example) or a structure. Fact keys
|
|
@@ -616,7 +646,7 @@ may be expressed as either symbols or strings. A key will be converted to a low
|
|
|
616
646
|
string to align with the Facter standard
|
|
617
647
|
|
|
618
648
|
```ruby
|
|
619
|
-
let(:facts) { {
|
|
649
|
+
let(:facts) { {'os' => { 'family' => 'RedHat', 'release' => { 'major' => '7', 'minor' => '1', 'full' => '7.1.1503' } } } }
|
|
620
650
|
```
|
|
621
651
|
|
|
622
652
|
You can also create a set of default facts provided to all specs in your spec_helper:
|
|
@@ -624,7 +654,7 @@ You can also create a set of default facts provided to all specs in your spec_he
|
|
|
624
654
|
``` ruby
|
|
625
655
|
RSpec.configure do |c|
|
|
626
656
|
c.default_facts = {
|
|
627
|
-
|
|
657
|
+
'operatingsystem' => 'Ubuntu'
|
|
628
658
|
}
|
|
629
659
|
end
|
|
630
660
|
```
|
|
@@ -638,7 +668,7 @@ You can create top-scope variables much in the same way as an ENC.
|
|
|
638
668
|
|
|
639
669
|
|
|
640
670
|
```ruby
|
|
641
|
-
let(:node_params) { {
|
|
671
|
+
let(:node_params) { { 'hostgroup' => 'webservers', 'rack' => 'KK04', 'status' => 'maintenance' } }
|
|
642
672
|
```
|
|
643
673
|
|
|
644
674
|
You can also create a set of default top-scope variables provided to all specs in your spec_helper:
|
|
@@ -646,9 +676,9 @@ You can also create a set of default top-scope variables provided to all specs i
|
|
|
646
676
|
``` ruby
|
|
647
677
|
RSpec.configure do |c|
|
|
648
678
|
c.default_node_params = {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
679
|
+
'owner' => 'itprod',
|
|
680
|
+
'site' => 'ams4',
|
|
681
|
+
'status' => 'live'
|
|
652
682
|
}
|
|
653
683
|
end
|
|
654
684
|
```
|
|
@@ -765,7 +795,7 @@ describe 'orch_app' do
|
|
|
765
795
|
let(:title) { 'my_awesome_app' }
|
|
766
796
|
let(:params) do
|
|
767
797
|
{
|
|
768
|
-
|
|
798
|
+
'nodes' => {
|
|
769
799
|
ref('Node', node) => ref('Orch_app::Db', title),
|
|
770
800
|
}
|
|
771
801
|
}
|
|
@@ -957,7 +987,7 @@ user:
|
|
|
957
987
|
|
|
958
988
|
```ruby
|
|
959
989
|
ntpserver = hiera.lookup('ntpserver', nil, nil)
|
|
960
|
-
let(:params) {
|
|
990
|
+
let(:params) { 'ntpserver' => ntpserver }
|
|
961
991
|
```
|
|
962
992
|
|
|
963
993
|
### Enabling hiera lookups
|
|
@@ -1025,7 +1055,9 @@ be excluded from the coverage report.
|
|
|
1025
1055
|
* [puppetlabs_spec_helper](https://github.com/puppetlabs/puppetlabs_spec_helper): shared spec helpers to setup puppet
|
|
1026
1056
|
* [rspec-puppet-augeas](https://github.com/domcleal/rspec-puppet-augeas): RSpec tests for Augeas resources inside Puppet manifests
|
|
1027
1057
|
* [jimdo-rspec-puppet-helpers](https://github.com/Jimdo/jimdo-rspec-puppet-helpers): Tests the contents of a file with a source
|
|
1028
|
-
|
|
1058
|
+
* Ease development of specs
|
|
1059
|
+
* [puppet-catalog_rspec](https://github.com/enterprisemodules/puppet-catalog_rspec): Dump the Puppet Catalog as RSpec code at compile time
|
|
1060
|
+
* [create_specs](https://github.com/alexharv074/create_specs.git): A different implementation that takes a compiled catalog and writes out RSpec code with various options
|
|
1029
1061
|
* Fact providers
|
|
1030
1062
|
* [rspec-puppet-facts](https://github.com/mcanevet/rspec-puppet-facts): Simplify your unit tests by looping on every supported Operating System and populating facts.
|
|
1031
1063
|
* [rspec-puppet-osmash](https://github.com/Aethylred/rspec-puppet-osmash): Provides Operation System hashes and validations for rspec-puppet
|
|
@@ -47,9 +47,15 @@ module RSpec::Puppet
|
|
|
47
47
|
default_hash.merge!(Puppet::Test::TestHelper.send(:app_defaults_for_tests))
|
|
48
48
|
end
|
|
49
49
|
settings_hash = default_hash.merge(Hash[*settings])
|
|
50
|
+
settings_hash.inject(settings_hash) { |h, (k, v)| h[k] = (v == '/dev/null') ? 'c:/nul/' : v; h } if Gem.win_platform?
|
|
50
51
|
|
|
51
52
|
if Puppet.settings.respond_to?(:initialize_app_defaults)
|
|
52
53
|
Puppet.settings.initialize_app_defaults(settings_hash)
|
|
54
|
+
|
|
55
|
+
# Forcefully apply the environmentpath setting instead of relying on
|
|
56
|
+
# the application defaults as Puppet::Test::TestHelper automatically
|
|
57
|
+
# sets this value as well, overriding our application default
|
|
58
|
+
Puppet.settings[:environmentpath] = settings_hash[:environmentpath] if settings_hash.key?(:environmentpath)
|
|
53
59
|
else
|
|
54
60
|
# Set settings the old way for Puppet 2.x, because that's how
|
|
55
61
|
# they're defaulted in that version of Puppet::Test::TestHelper and
|
|
@@ -101,7 +107,7 @@ module RSpec::Puppet
|
|
|
101
107
|
end
|
|
102
108
|
end
|
|
103
109
|
|
|
104
|
-
class
|
|
110
|
+
class Adapter40 < Base
|
|
105
111
|
def setup_puppet(example_group)
|
|
106
112
|
super
|
|
107
113
|
|
|
@@ -178,17 +184,62 @@ module RSpec::Puppet
|
|
|
178
184
|
end
|
|
179
185
|
end
|
|
180
186
|
|
|
181
|
-
class
|
|
187
|
+
class Adapter4X < Adapter40
|
|
188
|
+
def settings_map
|
|
189
|
+
super.concat([
|
|
190
|
+
[:trusted_server_facts, :trusted_server_facts]
|
|
191
|
+
])
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
class Adapter6X < Adapter40
|
|
196
|
+
def settings_map
|
|
197
|
+
super.concat([
|
|
198
|
+
[:basemodulepath, :basemodulepath],
|
|
199
|
+
[:vendormoduledir, :vendormoduledir],
|
|
200
|
+
])
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
class Adapter30 < Base
|
|
182
205
|
def settings_map
|
|
183
206
|
super.concat([
|
|
184
207
|
[:manifestdir, :manifest_dir],
|
|
185
208
|
[:manifest, :manifest],
|
|
186
209
|
[:templatedir, :template_dir],
|
|
187
210
|
[:hiera_config, :hiera_config],
|
|
211
|
+
])
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
class Adapter32 < Adapter30
|
|
216
|
+
def settings_map
|
|
217
|
+
super.concat([
|
|
188
218
|
[:parser, :parser],
|
|
189
|
-
|
|
219
|
+
])
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
class Adapter33 < Adapter32
|
|
224
|
+
def settings_map
|
|
225
|
+
super.concat([
|
|
190
226
|
[:ordering, :ordering],
|
|
191
227
|
[:stringify_facts, :stringify_facts],
|
|
228
|
+
])
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
class Adapter34 < Adapter33
|
|
233
|
+
def settings_map
|
|
234
|
+
super.concat([
|
|
235
|
+
[:trusted_node_data, :trusted_node_data],
|
|
236
|
+
])
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
class Adapter35 < Adapter34
|
|
241
|
+
def settings_map
|
|
242
|
+
super.concat([
|
|
192
243
|
[:strict_variables, :strict_variables],
|
|
193
244
|
])
|
|
194
245
|
end
|
|
@@ -206,8 +257,14 @@ module RSpec::Puppet
|
|
|
206
257
|
|
|
207
258
|
def self.get
|
|
208
259
|
[
|
|
209
|
-
['
|
|
210
|
-
['
|
|
260
|
+
['6.0', Adapter6X],
|
|
261
|
+
['4.1', Adapter4X],
|
|
262
|
+
['4.0', Adapter40],
|
|
263
|
+
['3.5', Adapter35],
|
|
264
|
+
['3.4', Adapter34],
|
|
265
|
+
['3.3', Adapter33],
|
|
266
|
+
['3.2', Adapter32],
|
|
267
|
+
['3.0', Adapter30],
|
|
211
268
|
['2.7', Adapter27]
|
|
212
269
|
].each do |(version, klass)|
|
|
213
270
|
if Puppet::Util::Package.versioncmp(Puppet.version, version) >= 0
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module RSpec::Puppet::Consts
|
|
2
|
+
STUBBED_CONSTS = {
|
|
3
|
+
:posix => {
|
|
4
|
+
'File::PATH_SEPARATOR' => ':',
|
|
5
|
+
'File::ALT_SEPARATOR' => nil,
|
|
6
|
+
'Pathname::SEPARATOR_PAT' => /#{Regexp.quote('/')}/,
|
|
7
|
+
},
|
|
8
|
+
:windows => {
|
|
9
|
+
'File::PATH_SEPARATOR' => ';',
|
|
10
|
+
'File::ALT_SEPARATOR' => "\\",
|
|
11
|
+
'Pathname::SEPARATOR_PAT' => /[#{Regexp.quote("\\")}#{Regexp.quote('/')}]/,
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
FEATURES = {
|
|
16
|
+
:posix => {
|
|
17
|
+
:posix => true,
|
|
18
|
+
:microsoft_windows => false,
|
|
19
|
+
},
|
|
20
|
+
:windows => {
|
|
21
|
+
:posix => false,
|
|
22
|
+
:microsoft_windows => true,
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def self.stub_consts_for(platform)
|
|
27
|
+
STUBBED_CONSTS[platform].each do |const_name, const_value|
|
|
28
|
+
stub_const_wrapper(const_name, const_value)
|
|
29
|
+
end
|
|
30
|
+
Puppet::Util::Platform.pretend_to_be(platform)
|
|
31
|
+
FEATURES[platform].each do |feature_name, feature_value|
|
|
32
|
+
Puppet.features.add(feature_name) { feature_value }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.stub_const_wrapper(const, value)
|
|
37
|
+
klass_name, const_name = const.split('::', 2)
|
|
38
|
+
klass = Object.const_get(klass_name)
|
|
39
|
+
klass.send(:remove_const, const_name) if klass.const_defined?(const_name)
|
|
40
|
+
klass.const_set(const_name, value)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.restore_consts
|
|
44
|
+
stub_consts_for(RSpec.configuration.platform)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.without_stubs
|
|
48
|
+
if Puppet::Util::Platform.pretending?
|
|
49
|
+
pretend_platform = Puppet::Util::Platform.pretend_platform
|
|
50
|
+
restore_consts
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
yield
|
|
54
|
+
ensure
|
|
55
|
+
stub_consts_for(pretend_platform) if pretend_platform
|
|
56
|
+
end
|
|
57
|
+
end
|