chef-resource 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +23 -0
  3. data/LICENSE +201 -0
  4. data/README.md +264 -0
  5. data/Rakefile +8 -0
  6. data/files/lib/chef_resource.rb +24 -0
  7. data/files/lib/chef_resource/camel_case.rb +23 -0
  8. data/files/lib/chef_resource/chef.rb +102 -0
  9. data/files/lib/chef_resource/chef_dsl/chef_cookbook_compiler.rb +44 -0
  10. data/files/lib/chef_resource/chef_dsl/chef_recipe.rb +10 -0
  11. data/files/lib/chef_resource/chef_dsl/chef_recipe_dsl_extensions.rb +84 -0
  12. data/files/lib/chef_resource/chef_dsl/chef_resource_base.rb +12 -0
  13. data/files/lib/chef_resource/chef_dsl/chef_resource_class_extensions.rb +30 -0
  14. data/files/lib/chef_resource/chef_dsl/chef_resource_extensions.rb +224 -0
  15. data/files/lib/chef_resource/chef_dsl/chef_resource_log.rb +54 -0
  16. data/files/lib/chef_resource/chef_dsl/resource_container_module.rb +80 -0
  17. data/files/lib/chef_resource/chef_dsl/resource_definition_dsl.rb +128 -0
  18. data/files/lib/chef_resource/constants.rb +8 -0
  19. data/files/lib/chef_resource/errors.rb +31 -0
  20. data/files/lib/chef_resource/lazy_proc.rb +82 -0
  21. data/files/lib/chef_resource/output/nested_converge.rb +91 -0
  22. data/files/lib/chef_resource/output/nested_converge/open_resource.rb +113 -0
  23. data/files/lib/chef_resource/output/region_stream.rb +145 -0
  24. data/files/lib/chef_resource/output/simple_output.rb +83 -0
  25. data/files/lib/chef_resource/resource.rb +428 -0
  26. data/files/lib/chef_resource/resource/resource_log.rb +197 -0
  27. data/files/lib/chef_resource/resource/resource_type.rb +74 -0
  28. data/files/lib/chef_resource/resource/struct_property.rb +39 -0
  29. data/files/lib/chef_resource/resource/struct_property_type.rb +185 -0
  30. data/files/lib/chef_resource/resource/struct_resource.rb +410 -0
  31. data/files/lib/chef_resource/resource/struct_resource_base.rb +11 -0
  32. data/files/lib/chef_resource/resource/struct_resource_type.rb +275 -0
  33. data/files/lib/chef_resource/simple_struct.rb +121 -0
  34. data/files/lib/chef_resource/type.rb +371 -0
  35. data/files/lib/chef_resource/types.rb +4 -0
  36. data/files/lib/chef_resource/types/boolean.rb +16 -0
  37. data/files/lib/chef_resource/types/byte_size.rb +10 -0
  38. data/files/lib/chef_resource/types/date_time_type.rb +18 -0
  39. data/files/lib/chef_resource/types/date_type.rb +18 -0
  40. data/files/lib/chef_resource/types/float_type.rb +28 -0
  41. data/files/lib/chef_resource/types/integer_type.rb +53 -0
  42. data/files/lib/chef_resource/types/interval.rb +21 -0
  43. data/files/lib/chef_resource/types/path.rb +39 -0
  44. data/files/lib/chef_resource/types/pathname_type.rb +34 -0
  45. data/files/lib/chef_resource/types/string_type.rb +16 -0
  46. data/files/lib/chef_resource/types/symbol_type.rb +18 -0
  47. data/files/lib/chef_resource/types/uri_type.rb +37 -0
  48. data/files/lib/chef_resource/version.rb +3 -0
  49. data/spec/integration/chef.rb +81 -0
  50. data/spec/integration/struct_spec.rb +611 -0
  51. data/spec/integration/struct_state_spec.rb +538 -0
  52. data/spec/integration/type_spec.rb +1123 -0
  53. data/spec/integration/validation_spec.rb +207 -0
  54. data/spec/support/spec_support.rb +7 -0
  55. metadata +167 -0
@@ -0,0 +1,538 @@
1
+ require 'support/spec_support'
2
+ require 'chef_resource/resource/struct_resource_base'
3
+
4
+ describe "StructResource behavior in different states" do
5
+ def self.with_struct(name, &block)
6
+ before :each do
7
+ Object.send(:remove_const, name) if Object.const_defined?(name, false)
8
+ eval "class ::#{name} < ChefResource::Resource::StructResourceBase; end"
9
+ Object.const_get(name).class_eval(&block)
10
+ end
11
+ after :each do
12
+ end
13
+ end
14
+
15
+ describe :resource_state do
16
+ context "When MyResource has set properties, default properties, load_value and values set by load" do
17
+ with_struct(:MyResource) do
18
+ property :identity_set,
19
+ identity: true,
20
+ default: "identity_set DEFAULT"
21
+ property :identity_set_same_as_default,
22
+ identity: true,
23
+ default: "identity_set_same_as_default"
24
+ property :identity_set_same_as_load_value,
25
+ identity: true,
26
+ default: "identity_set_same_as_default DEFAULT",
27
+ load_value: ChefResource::LazyProc.new { @num_load_values = num_load_values + 1; "identity_set_same_as_load_value" }
28
+ property :identity_set_same_as_load,
29
+ identity: true,
30
+ required: false,
31
+ default: "identity_set_same_as_default DEFAULT_VALUE"
32
+ property :identity_default,
33
+ identity: true,
34
+ default: "identity_default"
35
+ property :identity_load_value,
36
+ identity: true,
37
+ default: "identity_load_value DEFAULT",
38
+ load_value: ChefResource::LazyProc.new { @num_load_values = num_load_values + 1; "identity_load_value" }
39
+ property :identity_load,
40
+ identity: true,
41
+ default: "identity_load DEFAULT"
42
+
43
+ property :normal_set,
44
+ default: "normal_set DEFAULT"
45
+ property :normal_set_same_as_default,
46
+ default: "normal_set_same_as_default"
47
+ property :normal_set_same_as_load_value,
48
+ default: "normal_set_same_as_load_value DEFAULT",
49
+ load_value: ChefResource::LazyProc.new { @num_load_values = num_load_values + 1; "normal_set_same_as_load_value" }
50
+ property :normal_set_same_as_load,
51
+ default: "normal_set_same_as_load LOAD"
52
+ property :normal_default,
53
+ default: "normal_default"
54
+ property :normal_load_value,
55
+ default: "normal_load_value DEFAULT",
56
+ load_value: ChefResource::LazyProc.new { @num_load_values = num_load_values + 1; "normal_load_value" }
57
+ property :normal_load,
58
+ default: "normal_load DEFAULT"
59
+
60
+ def load
61
+ identity_set "identity_set LOAD"
62
+ identity_set_same_as_load "identity_set_same_as_load"
63
+ identity_load "identity_load"
64
+ normal_set "normal_set LOAD"
65
+ normal_set_same_as_load "normal_set_same_as_load"
66
+ normal_load "normal_load"
67
+ @num_loads = num_loads + 1
68
+ end
69
+
70
+ def num_loads
71
+ @num_loads ||= 0
72
+ end
73
+
74
+ def num_load_values
75
+ @num_load_values ||= 0
76
+ end
77
+ end
78
+
79
+ def initial_loads
80
+ r
81
+ @initial_loads || 0
82
+ end
83
+
84
+ def initial_load_values
85
+ r
86
+ @initial_load_values || 0
87
+ end
88
+
89
+ ALL_PROPERTIES = %w(
90
+ identity_set
91
+ identity_set_same_as_default
92
+ identity_set_same_as_load_value
93
+ identity_set_same_as_load
94
+ identity_default
95
+ identity_load_value
96
+ identity_load
97
+ normal_set
98
+ normal_set_same_as_default
99
+ normal_set_same_as_load_value
100
+ normal_set_same_as_load
101
+ normal_default
102
+ normal_load_value
103
+ normal_load
104
+ )
105
+
106
+ def expect_loads(expected_loads: nil, expected_load_values: nil)
107
+ expected_loads = initial_loads if initial_loads > expected_loads
108
+ expected_load_values = initial_load_values if initial_load_values > expected_load_values
109
+ num_loads = r.instance_eval { @current_resource } ? r.current_resource.num_loads : 0
110
+ num_load_values = r.instance_eval { @current_resource } ? r.current_resource.num_load_values : 0
111
+ expect(num_loads).to eq expected_loads
112
+ expect(num_load_values >= initial_load_values && num_load_values <= (initial_load_values + expected_load_values)).to be_truthy
113
+ end
114
+
115
+ shared_context "All values can be read" do
116
+ ALL_PROPERTIES.each do |name|
117
+ if name.index('_set')
118
+ it "#{name} == '#{name}'" do
119
+ expect(r.public_send(name)).to eq name
120
+ expect_loads(expected_loads: 0, expected_load_values: 0)
121
+ end
122
+ elsif name.index('_load_value')
123
+ it "#{name} == '#{name}' and triggers load_value" do
124
+ expect(r.public_send(name)).to eq name
125
+ expect_loads(expected_loads: 1, expected_load_values: 1)
126
+ end
127
+ else
128
+ it "#{name} == '#{name}' and triggers load" do
129
+ expect(r.public_send(name)).to eq name
130
+ expect_loads(expected_loads: 1, expected_load_values: 0)
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ shared_context "to_h(:all) returns correct data" do
137
+ it "to_h(:all) returns everything including defaults and load is called" do
138
+ expect(r.to_h(:all)).
139
+ to eq ALL_PROPERTIES.
140
+ inject({}) { |h,name| h[name.to_sym] = name; h }
141
+ expect_loads(expected_loads: 1, expected_load_values: 2)
142
+ end
143
+
144
+ it "to_h(:only_changed) returns everything that isn't modified from its default / actual value and load is called" do
145
+ expect(r.to_h(:only_changed)).to eq ({
146
+ identity_set: "identity_set",
147
+ normal_set: "normal_set"
148
+ })
149
+ expect_loads(expected_loads: 1, expected_load_values: 1)
150
+ end
151
+
152
+ it "to_h(:only_explicit) returns only explicitly opened values (no default or loaded values) and load is not called" do
153
+ expect(r.to_h(:only_explicit)).
154
+ to eq ALL_PROPERTIES.
155
+ select { |name| name.start_with?('identity_set') || name.start_with?('normal_set') }.
156
+ inject({}) { |h,name| h[name.to_sym] = name; h }
157
+ expect_loads(expected_loads: 0, expected_load_values: 0)
158
+ end
159
+ end
160
+
161
+ let(:current_resource) do
162
+ resource = MyResource.open(
163
+ identity_set: "identity_set",
164
+ identity_set_same_as_default: "identity_set_same_as_default",
165
+ identity_set_same_as_load_value: "identity_set_same_as_load_value",
166
+ identity_set_same_as_load: "identity_set_same_as_load"
167
+ )
168
+ resource.normal_set "normal_set"
169
+ resource.normal_set_same_as_default "normal_set_same_as_default"
170
+ resource.normal_set_same_as_load_value "normal_set_same_as_load_value"
171
+ resource.normal_set_same_as_load "normal_set_same_as_load"
172
+ resource
173
+ end
174
+
175
+ context "When the resource is open and no values have been read" do
176
+ let(:r) { current_resource }
177
+
178
+ context "Only normal values can be set" do
179
+ ALL_PROPERTIES.each do |name|
180
+ if name.start_with?('identity_')
181
+ it "#{name} = 'hi' fails with ChefResource::PropertyDefinedError" do
182
+ expect { eval("r.#{name} = 'hi'") }.to raise_error ChefResource::PropertyDefinedError
183
+ expect { eval("r.#{name} 'hi'")}.to raise_error ChefResource::PropertyDefinedError
184
+ end
185
+ else
186
+ it "#{name} = 'hi' succeeds" do
187
+ eval("r.#{name} = 'hi'")
188
+ expect(eval("r.#{name}")).to eq 'hi'
189
+ expect_loads(expected_loads: 0, expected_load_values: 0)
190
+ end
191
+ it "#{name} 'hi' succeeds" do
192
+ eval("r.#{name} 'hi'")
193
+ expect(eval("r.#{name}")).to eq 'hi'
194
+ expect_loads(expected_loads: 0, expected_load_values: 0)
195
+ end
196
+ end
197
+ end
198
+ end
199
+
200
+ it_behaves_like "to_h(:all) returns correct data"
201
+ end
202
+
203
+ context "When the resource is open and all values have been read" do
204
+ let(:r) { current_resource}
205
+ before :each do
206
+ ALL_PROPERTIES.each do |name|
207
+ expect(r.public_send(name)).to eq name
208
+ end
209
+ @initial_loads = 1
210
+ @initial_load_values = 2
211
+ end
212
+
213
+ it_behaves_like "to_h(:all) returns correct data"
214
+ end
215
+
216
+ context "When the resource is defined and no values have been read" do
217
+ let(:r) { current_resource }
218
+ before :each do
219
+ r.resource_fully_defined
220
+ end
221
+
222
+ context "Values cannot be set" do
223
+ ALL_PROPERTIES.each do |name|
224
+ it "#{name} = 'hi' fails with ChefResource::PropertyDefinedError" do
225
+ expect { eval("r.#{name} = 'hi'") }.to raise_error ChefResource::PropertyDefinedError
226
+ expect { eval("r.#{name} 'hi'")}.to raise_error ChefResource::PropertyDefinedError
227
+ end
228
+ end
229
+ end
230
+
231
+ it_behaves_like "All values can be read"
232
+ it_behaves_like "to_h(:all) returns correct data"
233
+ end
234
+
235
+ context "When the resource is defined and load decides the value does not exist" do
236
+ let(:r) do
237
+ current_resource
238
+ end
239
+ before :each do
240
+ MyResource.class_eval do
241
+ def load
242
+ resource_exists false
243
+ @num_loads = num_loads + 1
244
+ end
245
+ end
246
+ r.resource_fully_defined
247
+ end
248
+
249
+ it "to_h(:all) returns default values instead of actual" do
250
+ expect(r.to_h(:all)).to eq({
251
+ identity_set: 'identity_set',
252
+ identity_set_same_as_default: 'identity_set_same_as_default',
253
+ identity_set_same_as_load_value: 'identity_set_same_as_load_value',
254
+ identity_set_same_as_load: 'identity_set_same_as_load',
255
+ identity_default: 'identity_default',
256
+ identity_load_value: 'identity_load_value DEFAULT',
257
+ identity_load: 'identity_load DEFAULT',
258
+ normal_set: 'normal_set',
259
+ normal_set_same_as_default: 'normal_set_same_as_default',
260
+ normal_set_same_as_load_value: 'normal_set_same_as_load_value',
261
+ normal_set_same_as_load: 'normal_set_same_as_load',
262
+ normal_default: 'normal_default',
263
+ normal_load_value: 'normal_load_value DEFAULT',
264
+ normal_load: 'normal_load DEFAULT',
265
+ })
266
+ end
267
+ end
268
+
269
+ context "When the resource is updated and no values have been read" do
270
+ let(:r) { current_resource }
271
+ before :each do
272
+ r.resource_fully_defined
273
+ end
274
+
275
+ context "Values cannot be set" do
276
+ ALL_PROPERTIES.each do |name|
277
+ it "#{name} = 'hi' fails with ChefResource::PropertyDefinedError" do
278
+ expect { eval("r.#{name} = 'hi'") }.to raise_error ChefResource::PropertyDefinedError
279
+ expect { eval("r.#{name} 'hi'")}.to raise_error ChefResource::PropertyDefinedError
280
+ end
281
+ end
282
+ end
283
+
284
+ it_behaves_like "All values can be read"
285
+ it_behaves_like "to_h(:all) returns correct data"
286
+ end
287
+
288
+ context "When the resource is created (identity is not yet defined)" do
289
+ let(:r) do
290
+ resource = MyResource.new
291
+ resource.identity_set "identity_set"
292
+ resource.identity_set_same_as_default "identity_set_same_as_default"
293
+ resource.identity_set_same_as_load_value "identity_set_same_as_load_value"
294
+ resource.identity_set_same_as_load "identity_set_same_as_load"
295
+ resource.normal_set "normal_set"
296
+ resource.normal_set_same_as_default "normal_set_same_as_default"
297
+ resource.normal_set_same_as_load_value "normal_set_same_as_load_value"
298
+ resource.normal_set_same_as_load "normal_set_same_as_load"
299
+ resource
300
+ end
301
+
302
+ context "All properties can be set" do
303
+ ALL_PROPERTIES.each do |name|
304
+ it "#{name} = 'hi' succeeds" do
305
+ eval("r.#{name} = 'hi'")
306
+ expect(eval("r.#{name}")).to eq 'hi'
307
+ expect_loads(expected_loads: 0, expected_load_values: 0)
308
+ end
309
+ it "#{name} 'hi' succeeds" do
310
+ eval("r.#{name} 'hi'")
311
+ expect(eval("r.#{name}")).to eq 'hi'
312
+ expect_loads(expected_loads: 0, expected_load_values: 0)
313
+ end
314
+ end
315
+ end
316
+
317
+ context "Only explicitly set values can be read" do
318
+ ALL_PROPERTIES.select do |name|
319
+ # Properties whose desired identity has been set can be retrieved when
320
+ # in new state. Other properties cannot (because they require pulling
321
+ # on current_resource).
322
+ if name.index('_set')
323
+ it "#{name} == '#{name}'" do
324
+ expect(eval("r.#{name}")).to eq name
325
+ expect_loads(expected_loads: 0, expected_load_values: 0)
326
+ end
327
+ else
328
+ it "#{name} fails with a ChefResource::ResourceStateError" do
329
+ expect { eval("r.#{name}") }.to raise_error ChefResource::ResourceStateError
330
+ end
331
+ end
332
+ end
333
+ end
334
+
335
+ it "to_h(:all) fails with a ChefResource::ResourceStateError" do
336
+ expect { r.to_h(:all) }.to raise_error(ChefResource::ResourceStateError)
337
+ end
338
+
339
+ it "to_h(:only_changed) fails with a a ResourceStateError" do
340
+ expect { r.to_h(:only_changed) }.to raise_error(ChefResource::ResourceStateError)
341
+ end
342
+
343
+ it "to_h(:only_explicit) returns only explicitly opened values (no default or loaded values) and load is not called" do
344
+ expect(r.to_h(:only_explicit)).
345
+ to eq ALL_PROPERTIES.
346
+ select { |name| name.index('_set') }.
347
+ inject({}) { |h,name| h[name.to_sym] = name; h }
348
+ expect_loads(expected_loads: 0, expected_load_values: 0)
349
+ end
350
+ end
351
+
352
+ context "When the resource is open and all values have been set (but actual value has not been read)" do
353
+ let(:r) do
354
+ resource = MyResource.open(
355
+ identity_set: "identity_set",
356
+ identity_set_same_as_default: "identity_set_same_as_default",
357
+ identity_set_same_as_load_value: "identity_set_same_as_load_value",
358
+ identity_set_same_as_load: "identity_set_same_as_load",
359
+ identity_default: "identity_default",
360
+ identity_load_value: "identity_load_value",
361
+ identity_load: "identity_load"
362
+ )
363
+ resource.normal_set "normal_set"
364
+ resource.normal_set_same_as_default "normal_set_same_as_default"
365
+ resource.normal_set_same_as_load_value "normal_set_same_as_load_value"
366
+ resource.normal_set_same_as_load "normal_set_same_as_load"
367
+ resource.normal_default "normal_default"
368
+ resource.normal_load_value "normal_load_value"
369
+ resource.normal_load "normal_load"
370
+ resource
371
+ end
372
+
373
+ context "All values can be read" do
374
+ ALL_PROPERTIES.each do |name|
375
+ it "#{name} == '#{name}'" do
376
+ expect(r.public_send(name)).to eq name
377
+ expect_loads(expected_loads: 0, expected_load_values: 0)
378
+ end
379
+ end
380
+ end
381
+
382
+ it "to_h(:all) returns all data and does not call load" do
383
+ expect(r.to_h(:all)).to eq ALL_PROPERTIES.inject({}) { |h,name| h[name.to_sym] = name; h }
384
+ expect_loads(expected_loads: 0, expected_load_values: 0)
385
+ end
386
+
387
+ it "to_h(:only_changed) returns only changed data and calls load" do
388
+ expect(r.to_h(:only_changed)).to eq ({
389
+ identity_set: "identity_set",
390
+ normal_set: "normal_set"
391
+ })
392
+ expect_loads(expected_loads: 1, expected_load_values: 2)
393
+ end
394
+
395
+ it "to_h(:only_explicit) returns all data and does not call load" do
396
+ expect(r.to_h(:only_explicit)).to eq ALL_PROPERTIES.inject({}) { |h,name| h[name.to_sym] = name; h }
397
+ expect_loads(expected_loads: 0, expected_load_values: 0)
398
+ end
399
+ end
400
+
401
+ context :reset do
402
+ SET_VALUE = {
403
+ identity_set: 'identity_set SET',
404
+ identity_set_same_as_default: 'identity_set_same_as_default SET',
405
+ identity_set_same_as_load_value: 'identity_set_same_as_load_value SET',
406
+ identity_set_same_as_load: 'identity_set_same_as_load SET',
407
+ identity_default: 'identity_default',
408
+ identity_load_value: 'identity_load_value',
409
+ identity_load: 'identity_load',
410
+ normal_set: 'normal_set SET',
411
+ normal_set_same_as_default: 'normal_set_same_as_default SET',
412
+ normal_set_same_as_load_value: 'normal_set_same_as_load_value SET',
413
+ normal_set_same_as_load: 'normal_set_same_as_load SET',
414
+ normal_default: 'normal_default',
415
+ normal_load_value: 'normal_load_value',
416
+ normal_load: 'normal_load'
417
+ }
418
+ RESET_VALUE = {
419
+ identity_set: 'identity_set LOAD',
420
+ identity_set_same_as_default: 'identity_set_same_as_default',
421
+ identity_set_same_as_load_value: 'identity_set_same_as_load_value',
422
+ identity_set_same_as_load: 'identity_set_same_as_load',
423
+ identity_default: 'identity_default',
424
+ identity_load_value: 'identity_load_value',
425
+ identity_load: 'identity_load',
426
+ normal_set: 'normal_set LOAD',
427
+ normal_set_same_as_default: 'normal_set_same_as_default',
428
+ normal_set_same_as_load_value: 'normal_set_same_as_load_value',
429
+ normal_set_same_as_load: 'normal_set_same_as_load',
430
+ normal_default: 'normal_default',
431
+ normal_load_value: 'normal_load_value',
432
+ normal_load: 'normal_load'
433
+ }
434
+ FULL_RESET_VALUE = {
435
+ identity_set: 'identity_set SET',
436
+ identity_set_same_as_default: 'identity_set_same_as_default SET',
437
+ identity_set_same_as_load_value: 'identity_set_same_as_load_value SET',
438
+ identity_set_same_as_load: 'identity_set_same_as_load SET',
439
+ identity_default: 'identity_default',
440
+ identity_load_value: 'identity_load_value',
441
+ identity_load: 'identity_load',
442
+ normal_set: 'normal_set LOAD',
443
+ normal_set_same_as_default: 'normal_set_same_as_default',
444
+ normal_set_same_as_load_value: 'normal_set_same_as_load_value',
445
+ normal_set_same_as_load: 'normal_set_same_as_load',
446
+ normal_default: 'normal_default',
447
+ normal_load_value: 'normal_load_value',
448
+ normal_load: 'normal_load'
449
+ }
450
+
451
+ context "When the resource is open and no values have been read" do
452
+ let(:r) do
453
+ resource = MyResource.open(
454
+ identity_set: "identity_set SET",
455
+ identity_set_same_as_default: "identity_set_same_as_default SET",
456
+ identity_set_same_as_load_value: "identity_set_same_as_load_value SET",
457
+ identity_set_same_as_load: "identity_set_same_as_load SET"
458
+ )
459
+ resource.normal_set "normal_set SET"
460
+ resource.normal_set_same_as_default "normal_set_same_as_default SET"
461
+ resource.normal_set_same_as_load_value "normal_set_same_as_load_value SET"
462
+ resource.normal_set_same_as_load "normal_set_same_as_load SET"
463
+ resource
464
+ end
465
+
466
+ it "reset succeeds when no values have been read" do
467
+ expect_loads(expected_loads: 0, expected_load_values: 0)
468
+ r.reset
469
+ expect_loads(expected_loads: 0, expected_load_values: 0)
470
+ expect(r.to_h(:all)).to eq FULL_RESET_VALUE
471
+ expect_loads(expected_loads: 1, expected_load_values: 3)
472
+ end
473
+
474
+ it "reset succeeds after all values have been read" do
475
+ ALL_PROPERTIES.each do |name|
476
+ expect(r.public_send(name)).to eq SET_VALUE[name.to_sym]
477
+ end
478
+ expect_loads(expected_loads: 1, expected_load_values: 2)
479
+ r.reset
480
+ expect(r.to_h(:all)).to eq FULL_RESET_VALUE
481
+ end
482
+
483
+ ALL_PROPERTIES.each do |name|
484
+ if name.start_with?('identity_')
485
+ it "reset(:#{name}) fails with ChefResource::PropertyDefinedError" do
486
+ expect { r.reset(name.to_sym) }.to raise_error ChefResource::PropertyDefinedError
487
+ end
488
+ else
489
+ it "reset(:#{name}) succeeds" do
490
+ r.reset(name.to_sym)
491
+ expected = SET_VALUE.dup
492
+ expected[name.to_sym] = RESET_VALUE[name.to_sym]
493
+ expect(r.to_h(:all)).to eq expected
494
+ end
495
+ end
496
+ end
497
+ end
498
+
499
+ context "When the resource is new (not yet opened) and no values have been read" do
500
+ let(:r) do
501
+ resource = MyResource.new
502
+ resource.identity_set = "identity_set SET"
503
+ resource.identity_set_same_as_default = "identity_set_same_as_default SET"
504
+ resource.identity_set_same_as_load_value = "identity_set_same_as_load_value SET"
505
+ resource.identity_set_same_as_load = "identity_set_same_as_load SET"
506
+ resource.normal_set = "normal_set SET"
507
+ resource.normal_set_same_as_default = "normal_set_same_as_default SET"
508
+ resource.normal_set_same_as_load_value = "normal_set_same_as_load_value SET"
509
+ resource.normal_set_same_as_load = "normal_set_same_as_load SET"
510
+ resource
511
+ end
512
+
513
+
514
+ it "has the right values to start" do
515
+ r.resource_identity_defined
516
+ expect(r.to_h(:all)).to eq SET_VALUE
517
+ end
518
+
519
+ it "reset succeeds" do
520
+ r.reset
521
+ r.resource_identity_defined
522
+ expect(r.to_h(:all)).to eq FULL_RESET_VALUE
523
+ end
524
+
525
+ ALL_PROPERTIES.each do |name|
526
+ it "reset(:#{name}) succeeds" do
527
+ r.reset(name.to_sym)
528
+ expected = SET_VALUE.dup
529
+ expected[name.to_sym] = RESET_VALUE[name.to_sym]
530
+ r.resource_identity_defined
531
+ expect(r.to_h(:all)).to eq expected
532
+ end
533
+ end
534
+ end
535
+ end
536
+ end
537
+ end
538
+ end