22
22
23
23
gem install rspec-puppet
24
24
25
- > Note for ruby 1.8 users: while rspec-puppet itself supports ruby 1.8, you'll
26
- > need to pin rspec itself to ` ~> 3.1.0 ` , as later rspec versions do not work
27
- > on old rubies anymore.
28
-
29
25
## Starting out with a new module
30
26
31
27
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.
32
28
33
-
34
- ## Configure manifests for Puppet 4
35
-
36
- With Puppet 3, the manifest is set to ` $manifestdir/site.pp ` . However Puppet 4 defaults to an empty value. In order to test manifests you will need to set appropriate settings.
37
-
38
- Puppet configuration reference for ` manifest ` can be found online:
39
-
40
- * Puppet 3: https://docs.puppet.com/puppet/3.8/reference/configuration.html#manifest
41
- * Puppet 4: https://docs.puppet.com/puppet/4.8/reference/configuration.html#manifest
42
-
43
29
Configuration is typically done in a ` spec/spec_helper.rb ` file which each of your spec will require. Example code:
44
30
``` ruby
45
- # /spec
46
- base_dir = File .dirname(File .expand_path(__FILE__ ))
47
-
48
31
RSpec .configure do |c |
49
- c.module_path = File .join(base_dir, ' fixtures' , ' modules' )
50
- c.manifest_dir = File .join(base_dir, ' fixtures' , ' manifests' )
51
- c.manifest = File .join(base_dir, ' fixtures' , ' manifests' , ' site.pp' )
32
+ c.module_path = File .join(File .dirname(File .expand_path(__FILE__ )), ' fixtures' , ' modules' )
52
33
c.environmentpath = File .join(Dir .pwd, ' spec' )
53
-
34
+ c.manifest = File .join( File .dirname( File .expand_path( __FILE__ )), ' fixtures ' , ' manifests ' , ' site.pp ' )
54
35
# Coverage generation
55
36
c.after(:suite ) do
56
37
RSpec ::Puppet ::Coverage .report!
@@ -69,125 +50,83 @@ RSpec.configure do |c|
69
50
end
70
51
```
71
52
72
- #### manifest\_ dir
73
- Type | Default | Puppet Version(s)
74
- ------ | -------- | -----------------
75
- String | Required | 2.x, 3.x
76
-
77
- The path to the directory containing your basic manifests like ` site.pp ` .
78
-
79
53
#### module\_ path
80
54
Type | Default | Puppet Version(s)
81
55
------ | -------- | ------------------
82
- String | Required | 2.x, 3.x, 4.x, 5.x
56
+ String | Required | any
83
57
84
58
The path to the directory containing your Puppet modules.
85
59
86
60
#### default\_ facts
87
61
Type | Default | Puppet Version(s)
88
62
---- | ------- | ------------------
89
- Hash | ` {} ` | 2.x, 3.x, 4.x, 5.x
63
+ Hash | ` {} ` | any
90
64
91
65
A hash of default facts that should be used for all the tests.
92
66
93
67
#### hiera\_ config
94
68
Type | Default | Puppet Version(s)
95
69
------ | ------------- | -----------------
96
- String | ` "/dev/null" ` | 3.x, 4.x, 5.x
70
+ String | ` "/dev/null" ` | any
97
71
98
72
The path to your ` hiera.yaml ` file (if used).
99
73
100
74
#### default\_ node\_ params
101
75
Type | Default | Puppet Version(s)
102
76
---- | ------- | -----------------
103
- Hash | ` {} ` | 4.x, 5.x
77
+ Hash | ` {} ` | any
104
78
105
79
A hash of default node parameters that should be used for all the tests.
106
80
107
81
#### default\_ trusted\_ facts
108
82
Type | Default | Puppet Version(s)
109
83
---- | ------- | -----------------
110
- Hash | ` {} ` | 4.x, 5.x
84
+ Hash | ` {} ` | any
111
85
112
86
A hash of default trusted facts that should be used for all the tests
113
- (available in the manifests as the ` $trusted ` hash). In order to use this, the
114
- ` trusted_node_data ` setting must be set to ` true ` .
87
+ (available in the manifests as the ` $trusted ` hash).
115
88
116
89
#### trusted\_ node\_ data
117
90
Type | Default | Puppet Version(s)
118
91
------- | ------- | -----------------
119
- Boolean | ` false ` | >=3.4, 4.x, 5.x
92
+ Boolean | ` false ` | any
120
93
121
94
Configures rspec-puppet to use the ` $trusted ` hash when compiling the
122
95
catalogues.
123
96
124
97
#### trusted\_ server\_ facts
125
98
Type | Default | Puppet Version(s)
126
99
------- | ------- | -----------------
127
- Boolean | ` false ` | >=4.3, 5.x
100
+ Boolean | ` false ` | any
128
101
129
102
Configures rspec-puppet to use the ` $server_facts ` hash when compiling the
130
103
catalogues.
131
104
132
105
#### confdir
133
106
Type | Default | Puppet Version(s)
134
107
------ | --------------- | ------------------
135
- String | ` "/etc/puppet" ` | 2.x, 3.x, 4.x, 5.x
108
+ String | ` "/etc/puppet" ` | any
136
109
137
110
The path to the main Puppet configuration directory.
138
111
139
112
#### config
140
113
Type | Default | Puppet Version(s)
141
114
------ | ---------------------- | ------------------
142
- String | Puppet's default value | 2.x, 3.x, 4.x, 5.x
115
+ String | Puppet's default value | any
143
116
144
117
The path to ` puppet.conf ` .
145
118
146
- #### manifest
147
- Type | Default | Puppet Version(s)
148
- ------ | ---------------------- | -----------------
149
- String | Puppet's default value | 2.x, 3.x
150
-
151
- The entry-point manifest for Puppet, usually ` $manifest_dir/site.pp ` .
152
-
153
- #### template\_ dir
154
- Type | Default | Puppet Version(s)
155
- ------ | ------- | -----------------
156
- String | ` nil ` | 2.x, 3.x
157
-
158
- The path to the directory that Puppet should search for templates that are
159
- stored outside of modules.
160
-
161
119
#### environmentpath
162
120
Type | Default | Puppet Version(s)
163
121
------ | ------------------------------------- | -----------------
164
- String | ` "/etc/puppetlabs/code/environments" ` | 4.x, 5.x
122
+ String | ` "/etc/puppetlabs/code/environments" ` | any
165
123
166
124
The search path for environment directories.
167
125
168
- #### parser
169
- Type | Default | Puppet Version(s)
170
- ------ | ----------- | -----------------
171
- String | ` "current" ` | >= 3.2
172
-
173
- This switches between the 3.x (` current ` ) and 4.x (` future ` ) parsers.
174
-
175
- #### ordering
176
- Type | Default | Puppet Version(s)
177
- ------ | -------------- | -----------------
178
- String | ` "title-hash" ` | >= 3.3, 4.x, 5.x
179
-
180
- How unrelated resources should be ordered when applying a catalogue.
181
- * ` manifest ` - Use the order in which the resources are declared in the
182
- manifest.
183
- * ` title-hash ` - Order the resources randomly, but in a consistent manner
184
- across runs (the order will only change if the manifest changes).
185
- * ` random ` - Order the resources randomly.
186
-
187
126
#### strict\_ variables
188
127
Type | Default | Puppet Version(s)
189
128
------- | ------- | -----------------
190
- Boolean | ` false ` | >= 3.5, 4.x, 5.x
129
+ Boolean | ` false ` | any
191
130
192
131
Makes Puppet raise an error when it tries to reference a variable that hasn't
193
132
been defined (not including variables that have been explicitly set to
@@ -196,15 +135,15 @@ been defined (not including variables that have been explicitly set to
196
135
#### stringify\_ facts
197
136
Type | Default | Puppet Version(s)
198
137
------- | ------- | -----------------
199
- Boolean | ` true ` | >= 3.3, 4.x, 5.x
138
+ Boolean | ` true ` | any
200
139
201
140
Makes rspec-puppet coerce all the fact values into strings (matching the
202
141
behaviour of older versions of Puppet).
203
142
204
143
#### enable\_ pathname\_ stubbing
205
144
Type | Default | Puppet Version(s)
206
145
------- | ------- | ------------------
207
- Boolean |` false ` | 2.x, 3.x, 4.x, 5.x
146
+ Boolean |` false ` | any
208
147
209
148
Configures rspec-puppet to stub out ` Pathname#absolute? ` with it's own
210
149
implementation. This should only be enabled if you're running into an issue
@@ -214,15 +153,15 @@ functions, etc) that use `Pathname#absolute?`.
214
153
#### setup\_ fixtures
215
154
Type | Default | Puppet Version(s)
216
155
------- | ------- | ------------------
217
- Boolean | ` true ` | 2.x, 3.x, 4.x, 5.x
156
+ Boolean | ` true ` | any
218
157
219
158
Configures rspec-puppet to automatically create a link from the root of your
220
159
module to ` spec/fixtures/<module name> ` at the beginning of the test run.
221
160
222
161
#### derive\_ node\_ facts\_ from\_ nodename
223
162
Type | Default | Puppet Version(s)
224
163
------- | ------- | -----------------
225
- Boolean | ` true ` | 2.x, 3.x, 4.x, 5.x
164
+ Boolean | ` true ` | any
226
165
227
166
If ` true ` , rspec-puppet will override the ` fdqn ` , ` hostname ` , and ` domain `
228
167
facts with values that it derives from the node name (specified with
@@ -235,7 +174,7 @@ setting to `false`.
235
174
#### facter\_ implementation
236
175
Type | Default | Puppet Version(s)
237
176
------- | -------- | -----------------
238
- String | ` facter ` | 6.25+, 7.12+
177
+ String | ` facter ` | any
239
178
240
179
Configures rspec-puppet to use a specific Facter implementation for running
241
180
unit tests. If the ` rspec ` implementation is set and Puppet does not support
@@ -699,8 +638,6 @@ RSpec.configure do |c|
699
638
end
700
639
```
701
640
702
- ** NOTE** Setting top-scope variables is not supported in Puppet < 3.0.
703
-
704
641
#### Specifying extra code to load (pre-conditions)
705
642
706
643
If the manifest being tested relies on another class or variables to be set, these can be added via
@@ -752,7 +689,7 @@ let(:module_path) { '/path/to/your/module/dir' }
752
689
753
690
#### Specifying trusted facts
754
691
755
- When testing with Puppet >= 4.3 the trusted facts hash will have the standard trusted fact keys
692
+ The trusted facts hash will have the standard trusted fact keys
756
693
(certname, domain, and hostname) populated based on the node name (as set with ` :node ` ).
757
694
758
695
By default, the test environment contains no custom trusted facts (as usually obtained
777
714
778
715
#### Specifying trusted external data
779
716
780
- When testing with Puppet >= 6.14, the trusted facts hash will have an additional ` external `
781
- key for trusted external data.
717
+ The trusted facts hash will have an ` external ` key for trusted external data.
782
718
783
719
By default, the test environment contains no trusted external data (as usually obtained from
784
720
trusted external commands and found in the ` external ` key). If you need to test against specific
0 commit comments