chef 12.4.3 → 12.5.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -2
- data/lib/chef.rb +1 -1
- data/lib/chef/application/solo.rb +1 -1
- data/lib/chef/application/windows_service_manager.rb +17 -12
- data/lib/chef/chef_class.rb +7 -0
- data/lib/chef/chef_fs/config.rb +22 -24
- data/lib/chef/chef_fs/file_pattern.rb +4 -15
- data/lib/chef/chef_fs/file_system/cookbook_dir.rb +1 -0
- data/lib/chef/chef_fs/knife.rb +35 -7
- data/lib/chef/chef_fs/path_utils.rb +65 -34
- data/lib/chef/constants.rb +27 -0
- data/lib/chef/delayed_evaluator.rb +21 -0
- data/lib/chef/dsl/recipe.rb +20 -2
- data/lib/chef/event_dispatch/base.rb +40 -16
- data/lib/chef/event_dispatch/dsl.rb +64 -0
- data/lib/chef/exceptions.rb +6 -1
- data/lib/chef/formatters/doc.rb +3 -1
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -1
- data/lib/chef/http/http_request.rb +1 -1
- data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
- data/lib/chef/knife/ssl_check.rb +3 -2
- data/lib/chef/knife/user_edit.rb +1 -2
- data/lib/chef/mixin/params_validate.rb +362 -135
- data/lib/chef/node.rb +19 -0
- data/lib/chef/platform/handler_map.rb +0 -5
- data/lib/chef/platform/rebooter.rb +1 -1
- data/lib/chef/property.rb +539 -0
- data/lib/chef/provider.rb +129 -12
- data/lib/chef/provider/deploy.rb +3 -5
- data/lib/chef/provider/lwrp_base.rb +1 -75
- data/lib/chef/provider/package.rb +1 -1
- data/lib/chef/provider/powershell_script.rb +32 -19
- data/lib/chef/provider/registry_key.rb +5 -5
- data/lib/chef/provider/service/macosx.rb +5 -1
- data/lib/chef/recipe.rb +1 -8
- data/lib/chef/resource.rb +499 -84
- data/lib/chef/resource/file/verification.rb +7 -1
- data/lib/chef/resource/lwrp_base.rb +1 -7
- data/lib/chef/run_context.rb +404 -83
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/registry.rb +10 -2
- data/lib/chef/workstation_config_loader.rb +3 -158
- data/spec/data/run_context/cookbooks/include/recipes/default.rb +24 -0
- data/spec/data/run_context/cookbooks/include/recipes/includee.rb +3 -0
- data/spec/functional/rebooter_spec.rb +1 -1
- data/spec/functional/resource/{powershell_spec.rb → powershell_script_spec.rb} +3 -3
- data/spec/functional/win32/registry_helper_spec.rb +12 -0
- data/spec/functional/win32/service_manager_spec.rb +2 -2
- data/spec/integration/knife/chef_repo_path_spec.rb +13 -11
- data/spec/integration/recipes/recipe_dsl_spec.rb +0 -15
- data/spec/integration/recipes/resource_action_spec.rb +343 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/shared/functional/win32_service.rb +2 -1
- data/spec/unit/application/solo_spec.rb +4 -3
- data/spec/unit/chef_class_spec.rb +23 -0
- data/spec/unit/chef_fs/path_util_spec.rb +108 -0
- data/spec/unit/event_dispatch/dsl_spec.rb +87 -0
- data/spec/unit/json_compat_spec.rb +4 -3
- data/spec/unit/knife/ssl_check_spec.rb +4 -0
- data/spec/unit/mixin/params_validate_spec.rb +4 -2
- data/spec/unit/node_spec.rb +7 -0
- data/spec/unit/property/state_spec.rb +506 -0
- data/spec/unit/property/validation_spec.rb +658 -0
- data/spec/unit/property_spec.rb +968 -0
- data/spec/unit/provider/{powershell_spec.rb → powershell_script_spec.rb} +0 -0
- data/spec/unit/provider/registry_key_spec.rb +12 -0
- data/spec/unit/provider/service/macosx_spec.rb +4 -4
- data/spec/unit/provider_spec.rb +1 -3
- data/spec/unit/recipe_spec.rb +0 -4
- data/spec/unit/registry_helper_spec.rb +15 -1
- data/spec/unit/resource/file/verification_spec.rb +33 -5
- data/spec/unit/resource/{powershell_spec.rb → powershell_script_spec.rb} +0 -0
- data/spec/unit/resource_spec.rb +2 -2
- data/spec/unit/run_context/child_run_context_spec.rb +133 -0
- data/spec/unit/run_context_spec.rb +7 -0
- metadata +25 -25
- data/spec/unit/workstation_config_loader_spec.rb +0 -283
@@ -0,0 +1,658 @@
|
|
1
|
+
require 'support/shared/integration/integration_helper'
|
2
|
+
|
3
|
+
describe "Chef::Resource.property validation" do
|
4
|
+
include IntegrationSupport
|
5
|
+
|
6
|
+
module Namer
|
7
|
+
@i = 0
|
8
|
+
def self.next_resource_name
|
9
|
+
"chef_resource_property_spec_#{@i += 1}"
|
10
|
+
end
|
11
|
+
def self.reset_index
|
12
|
+
@current_index = 0
|
13
|
+
end
|
14
|
+
def self.current_index
|
15
|
+
@current_index
|
16
|
+
end
|
17
|
+
def self.next_index
|
18
|
+
@current_index += 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def lazy(&block)
|
23
|
+
Chef::DelayedEvaluator.new(&block)
|
24
|
+
end
|
25
|
+
|
26
|
+
before do
|
27
|
+
Namer.reset_index
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.new_resource_name
|
31
|
+
Namer.next_resource_name
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:resource_class) do
|
35
|
+
new_resource_name = self.class.new_resource_name
|
36
|
+
Class.new(Chef::Resource) do
|
37
|
+
resource_name new_resource_name
|
38
|
+
def blah
|
39
|
+
Namer.next_index
|
40
|
+
end
|
41
|
+
def self.blah
|
42
|
+
"class#{Namer.next_index}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
let(:resource) do
|
48
|
+
resource_class.new("blah")
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.english_join(values)
|
52
|
+
return '<nothing>' if values.size == 0
|
53
|
+
return values[0].inspect if values.size == 1
|
54
|
+
"#{values[0..-2].map { |v| v.inspect }.join(", ")} and #{values[-1].inspect}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.with_property(*properties, &block)
|
58
|
+
tags_index = properties.find_index { |p| !p.is_a?(String)}
|
59
|
+
if tags_index
|
60
|
+
properties, tags = properties[0..tags_index-1], properties[tags_index..-1]
|
61
|
+
else
|
62
|
+
tags = []
|
63
|
+
end
|
64
|
+
properties = properties.map { |property| "property #{property}" }
|
65
|
+
context "With properties #{english_join(properties)}", *tags do
|
66
|
+
before do
|
67
|
+
properties.each do |property_str|
|
68
|
+
resource_class.class_eval(property_str, __FILE__, __LINE__)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
instance_eval(&block)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.validation_test(validation, success_values, failure_values, getter_values=[], *tags)
|
76
|
+
with_property ":x, #{validation}", *tags do
|
77
|
+
it "gets nil when retrieving the initial (non-set) value" do
|
78
|
+
expect(resource.x).to be_nil
|
79
|
+
end
|
80
|
+
success_values.each do |v|
|
81
|
+
it "value #{v.inspect} is valid" do
|
82
|
+
resource.instance_eval { @x = 'default' }
|
83
|
+
expect(resource.x v).to eq v
|
84
|
+
expect(resource.x).to eq v
|
85
|
+
end
|
86
|
+
end
|
87
|
+
failure_values.each do |v|
|
88
|
+
it "value #{v.inspect} is invalid" do
|
89
|
+
expect { resource.x v }.to raise_error Chef::Exceptions::ValidationFailed
|
90
|
+
resource.instance_eval { @x = 'default' }
|
91
|
+
expect { resource.x v }.to raise_error Chef::Exceptions::ValidationFailed
|
92
|
+
end
|
93
|
+
end
|
94
|
+
getter_values.each do |v|
|
95
|
+
it "setting value to #{v.inspect} does not change the value" do
|
96
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
97
|
+
resource.instance_eval { @x = 'default' }
|
98
|
+
expect(resource.x v).to eq 'default'
|
99
|
+
expect(resource.x).to eq 'default'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "basic get, set, and nil set" do
|
106
|
+
with_property ":x, kind_of: String" do
|
107
|
+
context "when the variable already has a value" do
|
108
|
+
before do
|
109
|
+
resource.instance_eval { @x = 'default' }
|
110
|
+
end
|
111
|
+
it "get succeeds" do
|
112
|
+
expect(resource.x).to eq 'default'
|
113
|
+
end
|
114
|
+
it "set to valid value succeeds" do
|
115
|
+
expect(resource.x 'str').to eq 'str'
|
116
|
+
expect(resource.x).to eq 'str'
|
117
|
+
end
|
118
|
+
it "set to invalid value raises ValidationFailed" do
|
119
|
+
expect { resource.x 10 }.to raise_error Chef::Exceptions::ValidationFailed
|
120
|
+
end
|
121
|
+
it "set to nil emits a deprecation warning and does a get" do
|
122
|
+
expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError
|
123
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
124
|
+
resource.x 'str'
|
125
|
+
expect(resource.x nil).to eq 'str'
|
126
|
+
expect(resource.x).to eq 'str'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
context "when the variable does not have an initial value" do
|
130
|
+
it "get succeeds" do
|
131
|
+
expect(resource.x).to be_nil
|
132
|
+
end
|
133
|
+
it "set to valid value succeeds" do
|
134
|
+
expect(resource.x 'str').to eq 'str'
|
135
|
+
expect(resource.x).to eq 'str'
|
136
|
+
end
|
137
|
+
it "set to invalid value raises ValidationFailed" do
|
138
|
+
expect { resource.x 10 }.to raise_error Chef::Exceptions::ValidationFailed
|
139
|
+
end
|
140
|
+
it "set to nil emits a deprecation warning and does a get" do
|
141
|
+
expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError
|
142
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
143
|
+
resource.x 'str'
|
144
|
+
expect(resource.x nil).to eq 'str'
|
145
|
+
expect(resource.x).to eq 'str'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
with_property ":x, [ String, nil ]" do
|
150
|
+
context "when the variable already has a value" do
|
151
|
+
before do
|
152
|
+
resource.instance_eval { @x = 'default' }
|
153
|
+
end
|
154
|
+
it "get succeeds" do
|
155
|
+
expect(resource.x).to eq 'default'
|
156
|
+
end
|
157
|
+
it "set(nil) sets the value" do
|
158
|
+
expect(resource.x nil).to be_nil
|
159
|
+
expect(resource.x).to be_nil
|
160
|
+
end
|
161
|
+
it "set to valid value succeeds" do
|
162
|
+
expect(resource.x 'str').to eq 'str'
|
163
|
+
expect(resource.x).to eq 'str'
|
164
|
+
end
|
165
|
+
it "set to invalid value raises ValidationFailed" do
|
166
|
+
expect { resource.x 10 }.to raise_error Chef::Exceptions::ValidationFailed
|
167
|
+
end
|
168
|
+
end
|
169
|
+
context "when the variable does not have an initial value" do
|
170
|
+
it "get succeeds" do
|
171
|
+
expect(resource.x).to be_nil
|
172
|
+
end
|
173
|
+
it "set(nil) sets the value" do
|
174
|
+
expect(resource.x nil).to be_nil
|
175
|
+
expect(resource.x).to be_nil
|
176
|
+
end
|
177
|
+
it "set to valid value succeeds" do
|
178
|
+
expect(resource.x 'str').to eq 'str'
|
179
|
+
expect(resource.x).to eq 'str'
|
180
|
+
end
|
181
|
+
it "set to invalid value raises ValidationFailed" do
|
182
|
+
expect { resource.x 10 }.to raise_error Chef::Exceptions::ValidationFailed
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# Bare types
|
189
|
+
context "bare types" do
|
190
|
+
validation_test 'String',
|
191
|
+
[ 'hi' ],
|
192
|
+
[ 10 ],
|
193
|
+
[ nil ]
|
194
|
+
|
195
|
+
validation_test ':a',
|
196
|
+
[ :a ],
|
197
|
+
[ :b ],
|
198
|
+
[ nil ]
|
199
|
+
|
200
|
+
validation_test ':a, is: :b',
|
201
|
+
[ :a, :b ],
|
202
|
+
[ :c ],
|
203
|
+
[ nil ]
|
204
|
+
|
205
|
+
validation_test ':a, is: [ :b, :c ]',
|
206
|
+
[ :a, :b, :c ],
|
207
|
+
[ :d ],
|
208
|
+
[ nil ]
|
209
|
+
|
210
|
+
validation_test '[ :a, :b ], is: :c',
|
211
|
+
[ :a, :b, :c ],
|
212
|
+
[ :d ],
|
213
|
+
[ nil ]
|
214
|
+
|
215
|
+
validation_test '[ :a, :b ], is: [ :c, :d ]',
|
216
|
+
[ :a, :b, :c, :d ],
|
217
|
+
[ :e ],
|
218
|
+
[ nil ]
|
219
|
+
|
220
|
+
validation_test 'nil',
|
221
|
+
[ nil ],
|
222
|
+
[ :a ]
|
223
|
+
|
224
|
+
validation_test '[ nil ]',
|
225
|
+
[ nil ],
|
226
|
+
[ :a ]
|
227
|
+
|
228
|
+
validation_test '[]',
|
229
|
+
[],
|
230
|
+
[ :a ],
|
231
|
+
[ nil ]
|
232
|
+
end
|
233
|
+
|
234
|
+
# is
|
235
|
+
context "is" do
|
236
|
+
# Class
|
237
|
+
validation_test 'is: String',
|
238
|
+
[ 'a', '' ],
|
239
|
+
[ :a, 1 ],
|
240
|
+
[ nil ]
|
241
|
+
|
242
|
+
# Value
|
243
|
+
validation_test 'is: :a',
|
244
|
+
[ :a ],
|
245
|
+
[ :b ],
|
246
|
+
[ nil ]
|
247
|
+
|
248
|
+
validation_test 'is: [ :a, :b ]',
|
249
|
+
[ :a, :b ],
|
250
|
+
[ [ :a, :b ] ],
|
251
|
+
[ nil ]
|
252
|
+
|
253
|
+
validation_test 'is: [ [ :a, :b ] ]',
|
254
|
+
[ [ :a, :b ] ],
|
255
|
+
[ :a, :b ],
|
256
|
+
[ nil ]
|
257
|
+
|
258
|
+
# Regex
|
259
|
+
validation_test 'is: /abc/',
|
260
|
+
[ 'abc', 'wowabcwow' ],
|
261
|
+
[ '', 'abac' ],
|
262
|
+
[ nil ]
|
263
|
+
|
264
|
+
# Property
|
265
|
+
validation_test 'is: Chef::Property.new(is: :a)',
|
266
|
+
[ :a ],
|
267
|
+
[ :b, nil ]
|
268
|
+
|
269
|
+
# RSpec Matcher
|
270
|
+
class Globalses
|
271
|
+
extend RSpec::Matchers
|
272
|
+
end
|
273
|
+
|
274
|
+
validation_test "is: Globalses.eq(10)",
|
275
|
+
[ 10 ],
|
276
|
+
[ 1 ],
|
277
|
+
[ nil ]
|
278
|
+
|
279
|
+
# Proc
|
280
|
+
validation_test 'is: proc { |x| x }',
|
281
|
+
[ true, 1 ],
|
282
|
+
[ false ],
|
283
|
+
[ nil ]
|
284
|
+
|
285
|
+
validation_test 'is: proc { |x| x > blah }',
|
286
|
+
[ 10 ],
|
287
|
+
[ -1 ]
|
288
|
+
|
289
|
+
validation_test 'is: nil',
|
290
|
+
[ nil ],
|
291
|
+
[ 'a' ]
|
292
|
+
|
293
|
+
validation_test 'is: [ String, nil ]',
|
294
|
+
[ 'a', nil ],
|
295
|
+
[ :b ]
|
296
|
+
|
297
|
+
validation_test 'is: []',
|
298
|
+
[],
|
299
|
+
[ :a ],
|
300
|
+
[ nil ]
|
301
|
+
end
|
302
|
+
|
303
|
+
# Combination
|
304
|
+
context "combination" do
|
305
|
+
validation_test 'kind_of: String, equal_to: "a"',
|
306
|
+
[ 'a' ],
|
307
|
+
[ 'b' ],
|
308
|
+
[ nil ]
|
309
|
+
end
|
310
|
+
|
311
|
+
# equal_to
|
312
|
+
context "equal_to" do
|
313
|
+
# Value
|
314
|
+
validation_test 'equal_to: :a',
|
315
|
+
[ :a ],
|
316
|
+
[ :b ],
|
317
|
+
[ nil ]
|
318
|
+
|
319
|
+
validation_test 'equal_to: [ :a, :b ]',
|
320
|
+
[ :a, :b ],
|
321
|
+
[ [ :a, :b ] ],
|
322
|
+
[ nil ]
|
323
|
+
|
324
|
+
validation_test 'equal_to: [ [ :a, :b ] ]',
|
325
|
+
[ [ :a, :b ] ],
|
326
|
+
[ :a, :b ],
|
327
|
+
[ nil ]
|
328
|
+
|
329
|
+
validation_test 'equal_to: nil',
|
330
|
+
[ ],
|
331
|
+
[ 'a' ],
|
332
|
+
[ nil ]
|
333
|
+
|
334
|
+
validation_test 'equal_to: [ "a", nil ]',
|
335
|
+
[ 'a' ],
|
336
|
+
[ 'b' ],
|
337
|
+
[ nil ]
|
338
|
+
|
339
|
+
validation_test 'equal_to: [ nil, "a" ]',
|
340
|
+
[ 'a' ],
|
341
|
+
[ 'b' ],
|
342
|
+
[ nil ]
|
343
|
+
|
344
|
+
validation_test 'equal_to: []',
|
345
|
+
[],
|
346
|
+
[ :a ],
|
347
|
+
[ nil ]
|
348
|
+
end
|
349
|
+
|
350
|
+
# kind_of
|
351
|
+
context "kind_of" do
|
352
|
+
validation_test 'kind_of: String',
|
353
|
+
[ 'a' ],
|
354
|
+
[ :b ],
|
355
|
+
[ nil ]
|
356
|
+
|
357
|
+
validation_test 'kind_of: [ String, Symbol ]',
|
358
|
+
[ 'a', :b ],
|
359
|
+
[ 1 ],
|
360
|
+
[ nil ]
|
361
|
+
|
362
|
+
validation_test 'kind_of: [ Symbol, String ]',
|
363
|
+
[ 'a', :b ],
|
364
|
+
[ 1 ],
|
365
|
+
[ nil ]
|
366
|
+
|
367
|
+
validation_test 'kind_of: NilClass',
|
368
|
+
[ ],
|
369
|
+
[ 'a' ],
|
370
|
+
[ nil ]
|
371
|
+
|
372
|
+
validation_test 'kind_of: [ NilClass, String ]',
|
373
|
+
[ 'a' ],
|
374
|
+
[ :a ],
|
375
|
+
[ nil ]
|
376
|
+
|
377
|
+
validation_test 'kind_of: []',
|
378
|
+
[],
|
379
|
+
[ :a ],
|
380
|
+
[ nil ]
|
381
|
+
|
382
|
+
validation_test 'kind_of: nil',
|
383
|
+
[],
|
384
|
+
[ :a ],
|
385
|
+
[ nil ]
|
386
|
+
end
|
387
|
+
|
388
|
+
# regex
|
389
|
+
context "regex" do
|
390
|
+
validation_test 'regex: /abc/',
|
391
|
+
[ 'xabcy' ],
|
392
|
+
[ 'gbh', 123 ],
|
393
|
+
[ nil ]
|
394
|
+
|
395
|
+
validation_test 'regex: [ /abc/, /z/ ]',
|
396
|
+
[ 'xabcy', 'aza' ],
|
397
|
+
[ 'gbh', 123 ],
|
398
|
+
[ nil ]
|
399
|
+
|
400
|
+
validation_test 'regex: [ /z/, /abc/ ]',
|
401
|
+
[ 'xabcy', 'aza' ],
|
402
|
+
[ 'gbh', 123 ],
|
403
|
+
[ nil ]
|
404
|
+
|
405
|
+
validation_test 'regex: []',
|
406
|
+
[],
|
407
|
+
[ :a ],
|
408
|
+
[ nil ]
|
409
|
+
|
410
|
+
validation_test 'regex: nil',
|
411
|
+
[],
|
412
|
+
[ :a ],
|
413
|
+
[ nil ]
|
414
|
+
end
|
415
|
+
|
416
|
+
# callbacks
|
417
|
+
context "callbacks" do
|
418
|
+
validation_test 'callbacks: { "a" => proc { |x| x > 10 }, "b" => proc { |x| x%2 == 0 } }',
|
419
|
+
[ 12 ],
|
420
|
+
[ 11, 4 ]
|
421
|
+
|
422
|
+
validation_test 'callbacks: { "a" => proc { |x| x%2 == 0 }, "b" => proc { |x| x > 10 } }',
|
423
|
+
[ 12 ],
|
424
|
+
[ 11, 4 ]
|
425
|
+
|
426
|
+
validation_test 'callbacks: { "a" => proc { |x| x.nil? } }',
|
427
|
+
[ ],
|
428
|
+
[ 'a' ],
|
429
|
+
[ nil ]
|
430
|
+
|
431
|
+
validation_test 'callbacks: {}',
|
432
|
+
[ :a ],
|
433
|
+
[],
|
434
|
+
[ nil ]
|
435
|
+
end
|
436
|
+
|
437
|
+
# respond_to
|
438
|
+
context "respond_to" do
|
439
|
+
validation_test 'respond_to: :split',
|
440
|
+
[ 'hi' ],
|
441
|
+
[ 1 ],
|
442
|
+
[ nil ]
|
443
|
+
|
444
|
+
validation_test 'respond_to: "split"',
|
445
|
+
[ 'hi' ],
|
446
|
+
[ 1 ],
|
447
|
+
[ nil ]
|
448
|
+
|
449
|
+
validation_test 'respond_to: :to_s',
|
450
|
+
[ :a ],
|
451
|
+
[],
|
452
|
+
[ nil ]
|
453
|
+
|
454
|
+
validation_test 'respond_to: [ :split, :to_s ]',
|
455
|
+
[ 'hi' ],
|
456
|
+
[ 1 ],
|
457
|
+
[ nil ]
|
458
|
+
|
459
|
+
validation_test 'respond_to: %w(split to_s)',
|
460
|
+
[ 'hi' ],
|
461
|
+
[ 1 ],
|
462
|
+
[ nil ]
|
463
|
+
|
464
|
+
validation_test 'respond_to: [ :to_s, :split ]',
|
465
|
+
[ 'hi' ],
|
466
|
+
[ 1, ],
|
467
|
+
[ nil ]
|
468
|
+
|
469
|
+
validation_test 'respond_to: []',
|
470
|
+
[ :a ],
|
471
|
+
[],
|
472
|
+
[ nil ]
|
473
|
+
|
474
|
+
validation_test 'respond_to: nil',
|
475
|
+
[ :a ],
|
476
|
+
[],
|
477
|
+
[ nil ]
|
478
|
+
end
|
479
|
+
|
480
|
+
context "cannot_be" do
|
481
|
+
validation_test 'cannot_be: :empty',
|
482
|
+
[ 1, [1,2], { a: 10 } ],
|
483
|
+
[ [] ],
|
484
|
+
[ nil ]
|
485
|
+
|
486
|
+
validation_test 'cannot_be: "empty"',
|
487
|
+
[ 1, [1,2], { a: 10 } ],
|
488
|
+
[ [] ],
|
489
|
+
[ nil ]
|
490
|
+
|
491
|
+
validation_test 'cannot_be: [ :empty, :nil ]',
|
492
|
+
[ 1, [1,2], { a: 10 } ],
|
493
|
+
[ [] ],
|
494
|
+
[ nil ]
|
495
|
+
|
496
|
+
validation_test 'cannot_be: [ "empty", "nil" ]',
|
497
|
+
[ 1, [1,2], { a: 10 } ],
|
498
|
+
[ [] ],
|
499
|
+
[ nil ]
|
500
|
+
|
501
|
+
validation_test 'cannot_be: [ :nil, :empty ]',
|
502
|
+
[ 1, [1,2], { a: 10 } ],
|
503
|
+
[ [] ],
|
504
|
+
[ nil ]
|
505
|
+
|
506
|
+
validation_test 'cannot_be: [ :empty, :nil, :blahblah ]',
|
507
|
+
[ 1, [1,2], { a: 10 } ],
|
508
|
+
[ [] ],
|
509
|
+
[ nil ]
|
510
|
+
|
511
|
+
validation_test 'cannot_be: []',
|
512
|
+
[ :a ],
|
513
|
+
[],
|
514
|
+
[ nil ]
|
515
|
+
|
516
|
+
validation_test 'cannot_be: nil',
|
517
|
+
[ :a ],
|
518
|
+
[],
|
519
|
+
[ nil ]
|
520
|
+
|
521
|
+
end
|
522
|
+
|
523
|
+
context "required" do
|
524
|
+
with_property ':x, required: true' do
|
525
|
+
it "if x is not specified, retrieval fails" do
|
526
|
+
expect { resource.x }.to raise_error Chef::Exceptions::ValidationFailed
|
527
|
+
end
|
528
|
+
it "value 1 is valid" do
|
529
|
+
expect(resource.x 1).to eq 1
|
530
|
+
expect(resource.x).to eq 1
|
531
|
+
end
|
532
|
+
it "value nil emits a deprecation warning and does a get" do
|
533
|
+
expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError
|
534
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
535
|
+
resource.x 1
|
536
|
+
expect(resource.x nil).to eq 1
|
537
|
+
expect(resource.x).to eq 1
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
with_property ':x, [String, nil], required: true' do
|
542
|
+
it "if x is not specified, retrieval fails" do
|
543
|
+
expect { resource.x }.to raise_error Chef::Exceptions::ValidationFailed
|
544
|
+
end
|
545
|
+
it "value nil is valid" do
|
546
|
+
expect(resource.x nil).to be_nil
|
547
|
+
expect(resource.x).to be_nil
|
548
|
+
end
|
549
|
+
it "value '1' is valid" do
|
550
|
+
expect(resource.x '1').to eq '1'
|
551
|
+
expect(resource.x).to eq '1'
|
552
|
+
end
|
553
|
+
it "value 1 is invalid" do
|
554
|
+
expect { resource.x 1 }.to raise_error Chef::Exceptions::ValidationFailed
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
with_property ':x, name_property: true, required: true' do
|
559
|
+
it "if x is not specified, the name property is returned" do
|
560
|
+
expect(resource.x).to eq 'blah'
|
561
|
+
end
|
562
|
+
it "value 1 is valid" do
|
563
|
+
expect(resource.x 1).to eq 1
|
564
|
+
expect(resource.x).to eq 1
|
565
|
+
end
|
566
|
+
it "value nil emits a deprecation warning and does a get" do
|
567
|
+
expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError
|
568
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
569
|
+
resource.x 1
|
570
|
+
expect(resource.x nil).to eq 1
|
571
|
+
expect(resource.x).to eq 1
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
with_property ':x, default: 10, required: true' do
|
576
|
+
it "if x is not specified, the default is returned" do
|
577
|
+
expect(resource.x).to eq 10
|
578
|
+
end
|
579
|
+
it "value 1 is valid" do
|
580
|
+
expect(resource.x 1).to eq 1
|
581
|
+
expect(resource.x).to eq 1
|
582
|
+
end
|
583
|
+
it "value nil is invalid" do
|
584
|
+
expect { resource.x nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError
|
585
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
586
|
+
resource.x 1
|
587
|
+
expect(resource.x nil).to eq 1
|
588
|
+
expect(resource.x).to eq 1
|
589
|
+
end
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
context "custom validators (def _pv_blarghle)" do
|
594
|
+
before do
|
595
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
596
|
+
end
|
597
|
+
|
598
|
+
with_property ':x, blarghle: 1' do
|
599
|
+
context "and a class that implements _pv_blarghle" do
|
600
|
+
before do
|
601
|
+
resource_class.class_eval do
|
602
|
+
def _pv_blarghle(opts, key, value)
|
603
|
+
if _pv_opts_lookup(opts, key) != value
|
604
|
+
raise Chef::Exceptions::ValidationFailed, "ouch"
|
605
|
+
end
|
606
|
+
end
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
it "value 1 is valid" do
|
611
|
+
expect(resource.x 1).to eq 1
|
612
|
+
expect(resource.x).to eq 1
|
613
|
+
end
|
614
|
+
|
615
|
+
it "value '1' is invalid" do
|
616
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
617
|
+
expect { resource.x '1' }.to raise_error Chef::Exceptions::ValidationFailed
|
618
|
+
end
|
619
|
+
|
620
|
+
it "value nil does a get" do
|
621
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
622
|
+
resource.x 1
|
623
|
+
resource.x nil
|
624
|
+
expect(resource.x).to eq 1
|
625
|
+
end
|
626
|
+
end
|
627
|
+
end
|
628
|
+
|
629
|
+
with_property ':x, blarghle: 1' do
|
630
|
+
context "and a class that implements _pv_blarghle" do
|
631
|
+
before do
|
632
|
+
resource_class.class_eval do
|
633
|
+
def _pv_blarghle(opts, key, value)
|
634
|
+
if _pv_opts_lookup(opts, key) != value
|
635
|
+
raise Chef::Exceptions::ValidationFailed, "ouch"
|
636
|
+
end
|
637
|
+
end
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
it "value 1 is valid" do
|
642
|
+
expect(resource.x 1).to eq 1
|
643
|
+
expect(resource.x).to eq 1
|
644
|
+
end
|
645
|
+
|
646
|
+
it "value '1' is invalid" do
|
647
|
+
expect { resource.x '1' }.to raise_error Chef::Exceptions::ValidationFailed
|
648
|
+
end
|
649
|
+
|
650
|
+
it "value nil does a get" do
|
651
|
+
resource.x 1
|
652
|
+
resource.x nil
|
653
|
+
expect(resource.x).to eq 1
|
654
|
+
end
|
655
|
+
end
|
656
|
+
end
|
657
|
+
end
|
658
|
+
end
|