chef-resource 0.2.2

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.
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,1123 @@
1
+ require 'support/spec_support'
2
+ require 'chef_resource/resource/struct_resource_base'
3
+ require 'chef_resource/lazy_proc'
4
+
5
+ describe ChefResource::Type do
6
+ def self.with_property(type=NOT_PASSED, **args, &block)
7
+ args[:nullable] = :validate if !args.has_key?(:nullable)
8
+ with_struct do
9
+ property :prop, type, **args, &block
10
+ end
11
+ end
12
+
13
+ def self.with_struct(&block)
14
+ before :each do
15
+ Object.send(:remove_const, :MyStruct) if Object.const_defined?(:MyStruct)
16
+ eval "class ::MyStruct < ChefResource::Resource::StructResourceBase; end"
17
+ ::MyStruct.class_eval(&block)
18
+ end
19
+ end
20
+
21
+ def self.add_property(*args, &block)
22
+ ::MyStruct.class_eval do
23
+ property :prop, *args, &block
24
+ end
25
+ end
26
+
27
+ let(:struct) { MyStruct.open }
28
+
29
+ describe ChefResource::Types::Boolean do
30
+ context "With a Boolean property" do
31
+ with_property ChefResource::Types::Boolean
32
+
33
+ it "can be set to true" do
34
+ struct.prop = true
35
+ expect(struct.prop).to eq true
36
+ end
37
+ it "can be set to false" do
38
+ struct.prop = false
39
+ expect(struct.prop).to eq false
40
+ end
41
+ it "can be set to nil" do
42
+ struct.prop = nil
43
+ expect(struct.prop).to be_nil
44
+ end
45
+ it "cannot be set to {}" do
46
+ expect { struct.prop = {} }.to raise_error ChefResource::ValidationError
47
+ end
48
+ it "cannot be set to 'true'" do
49
+ expect { struct.prop = 'true' }.to raise_error ChefResource::ValidationError
50
+ end
51
+ end
52
+ end
53
+
54
+ describe ChefResource::Types::FloatType do
55
+ context "With a Float property" do
56
+ with_property Float
57
+
58
+ it "can be set to 1" do
59
+ struct.prop = 1
60
+ expect(struct.prop).to eq 1.0
61
+ end
62
+ it "can be set to 1.0" do
63
+ struct.prop = 1.0
64
+ expect(struct.prop).to eq 1.0
65
+ end
66
+ it "can be set to '1.0'" do
67
+ struct.prop = '1.0'
68
+ expect(struct.prop).to eq 1.0
69
+ end
70
+ it "can be set to nil" do
71
+ struct.prop = nil
72
+ expect(struct.prop).to be_nil
73
+ end
74
+ it "cannot be set to {}" do
75
+ expect { struct.prop = {} }.to raise_error ChefResource::ValidationError
76
+ end
77
+ it "cannot be set to 'blargh'" do
78
+ expect { struct.prop = 'true' }.to raise_error ChefResource::ValidationError
79
+ end
80
+ end
81
+ end
82
+
83
+ describe ChefResource::Types::IntegerType do
84
+ context "With an Integer property" do
85
+ with_property Integer
86
+
87
+ it "can be set to 1" do
88
+ struct.prop = 1
89
+ expect(struct.prop).to eq 1
90
+ end
91
+ it "cannot be set to 1.0" do
92
+ expect { struct.prop = 1.0 }.to raise_error ChefResource::ValidationError
93
+ end
94
+ it "can be set to '1'" do
95
+ struct.prop = '1'
96
+ expect(struct.prop).to eq 1
97
+ end
98
+ it "can be set to nil" do
99
+ struct.prop = nil
100
+ expect(struct.prop).to be_nil
101
+ end
102
+ it "cannot be set to ''" do
103
+ expect { struct.prop = '' }.to raise_error ChefResource::ValidationError
104
+ end
105
+ it "cannot be set to '1 '" do
106
+ expect { struct.prop = '1 ' }.to raise_error ChefResource::ValidationError
107
+ end
108
+ it "cannot be set to {}" do
109
+ expect { struct.prop = {} }.to raise_error ChefResource::ValidationError
110
+ end
111
+ it "cannot be set to 'blargh'" do
112
+ expect { struct.prop = 'blargh' }.to raise_error ChefResource::ValidationError
113
+ end
114
+ end
115
+
116
+ context "With Integer, base: 8" do
117
+ with_property Integer, base: 8
118
+
119
+ it "can be set to '11'" do
120
+ struct.prop = '11'
121
+ expect(struct.prop).to eq 011
122
+ end
123
+
124
+ it "cannot be set to '8'" do
125
+ expect { struct.prop = '8' }.to raise_error ChefResource::ValidationError
126
+ end
127
+ end
128
+
129
+ context "With Integer, base: 16" do
130
+ with_property Integer, base: 16
131
+
132
+ it "can be set to '11'" do
133
+ struct.prop = '11'
134
+ expect(struct.prop).to eq 0x11
135
+ end
136
+
137
+ it "can be set to 'FF'" do
138
+ struct.prop = 'FF'
139
+ expect(struct.prop).to eq 0xff
140
+ end
141
+
142
+ it "can be set to 'ff'" do
143
+ struct.prop = 'ff'
144
+ expect(struct.prop).to eq 0xff
145
+ end
146
+
147
+ it "cannot be set to 'g'" do
148
+ expect { struct.prop = 'g' }.to raise_error ChefResource::ValidationError
149
+ end
150
+ end
151
+ end
152
+
153
+ describe ChefResource::Types::Path do
154
+ context "With a Path property" do
155
+ with_property ChefResource::Types::Path
156
+
157
+ it "can be set to nil" do
158
+ struct.prop = nil
159
+ expect(struct.prop).to be_nil
160
+ end
161
+ it "can be set to '/x/y'" do
162
+ struct.prop = '/x/y'
163
+ expect(struct.prop).to eq '/x/y'
164
+ end
165
+ it "can be set to '/x/y/'" do
166
+ struct.prop = '/x/y/'
167
+ expect(struct.prop).to eq '/x/y/'
168
+ end
169
+ it "can be set to 'x/y'" do
170
+ struct.prop = 'x/y'
171
+ expect(struct.prop).to eq 'x/y'
172
+ end
173
+ it "can be set to 'x/y/'" do
174
+ struct.prop = 'x/y/'
175
+ expect(struct.prop).to eq 'x/y/'
176
+ end
177
+ it "can be set to 'x'" do
178
+ struct.prop = 'x'
179
+ expect(struct.prop).to eq 'x'
180
+ end
181
+ it "can be set to 'x/'" do
182
+ struct.prop = 'x/'
183
+ expect(struct.prop).to eq 'x/'
184
+ end
185
+ it "can be set to '//x/y/'" do
186
+ struct.prop = '//x/y/'
187
+ expect(struct.prop).to eq '//x/y/'
188
+ end
189
+ it "can be set to '/x//y/'" do
190
+ struct.prop = '/x//y/'
191
+ expect(struct.prop).to eq '/x//y/'
192
+ end
193
+ it "can be set to '/x/y//'" do
194
+ struct.prop = '/x/y//'
195
+ expect(struct.prop).to eq '/x/y//'
196
+ end
197
+ end
198
+
199
+ context "With a Path property with default: '/a/b'" do
200
+ with_property ChefResource::Types::Path, default: '/a/b'
201
+ it "Defaults to /a/b" do
202
+ expect(struct.prop).to eq '/a/b'
203
+ end
204
+ end
205
+
206
+ context "Lazy" do
207
+ context "With a Path property with attr_default=c/d and default: ChefResource::LazyProc.new { attr_default }" do
208
+ with_struct do
209
+ property :attr_default, ChefResource::Types::Path
210
+ property :prop, ChefResource::Types::Path, default: ChefResource::LazyProc.new { attr_default }
211
+ end
212
+ before :each do
213
+ struct.attr_default 'c/d'
214
+ end
215
+ it "Defaults to c/d" do
216
+ expect(struct.prop).to eq 'c/d'
217
+ end
218
+ end
219
+
220
+ context "With a Path property with rel=/a/b and relative_to: ChefResource::LazyProc.new { rel }" do
221
+ with_struct do
222
+ property :rel, ChefResource::Types::Path
223
+ property :prop, ChefResource::Types::Path, relative_to: ChefResource::LazyProc.new { rel }
224
+ end
225
+ before :each do
226
+ struct.rel = '/a/b'
227
+ end
228
+ it "Defaults to nil" do
229
+ expect(struct.prop).to be_nil
230
+ end
231
+ it "Relativizes c/d" do
232
+ struct.prop = 'c/d'
233
+ expect(struct.prop).to eq '/a/b/c/d'
234
+ end
235
+ end
236
+
237
+ context "With a Path property attr_default=c/d, rel=/a/b and relative_to: ChefResource::LazyProc.new { rel }, and default: ChefResource::LazyProc.new { attr_default }" do
238
+ with_struct do
239
+ property :attr_default, ChefResource::Types::Path
240
+ property :rel, ChefResource::Types::Path
241
+ property :prop, ChefResource::Types::Path, relative_to: ChefResource::LazyProc.new { rel }, default: ChefResource::LazyProc.new { attr_default }
242
+ end
243
+ before :each do
244
+ struct.attr_default 'c/d'
245
+ struct.rel '/a/b'
246
+ end
247
+ it "Defaults to /a/b/c/d" do
248
+ expect(struct.prop).to eq '/a/b/c/d'
249
+ end
250
+ it "Relativizes foo/bar" do
251
+ struct.prop = 'foo/bar'
252
+ expect(struct.prop).to eq '/a/b/foo/bar'
253
+ end
254
+ end
255
+ end
256
+
257
+ context "With a Path property relative to /a/b" do
258
+ with_property ChefResource::Types::Path, relative_to: '/a/b'
259
+
260
+ it "Defaults to nil" do
261
+ expect(struct.prop).to be_nil
262
+ end
263
+ it "can be set to nil" do
264
+ struct.prop = nil
265
+ expect(struct.prop).to be_nil
266
+ end
267
+ it "can be set to '/x/y'" do
268
+ struct.prop = '/x/y'
269
+ expect(struct.prop).to eq '/x/y'
270
+ end
271
+ it "can be set to '/x/y/'" do
272
+ struct.prop = '/x/y/'
273
+ expect(struct.prop).to eq '/x/y/'
274
+ end
275
+ it "can be set to 'x/y'" do
276
+ struct.prop = 'x/y'
277
+ expect(struct.prop).to eq '/a/b/x/y'
278
+ end
279
+ it "can be set to 'x/y/'" do
280
+ struct.prop = 'x/y/'
281
+ expect(struct.prop).to eq '/a/b/x/y/'
282
+ end
283
+ it "can be set to 'x'" do
284
+ struct.prop = 'x'
285
+ expect(struct.prop).to eq '/a/b/x'
286
+ end
287
+ it "can be set to 'x/'" do
288
+ struct.prop = 'x/'
289
+ expect(struct.prop).to eq '/a/b/x/'
290
+ end
291
+ it "can be set to '//x/y/'" do
292
+ struct.prop = '//x/y/'
293
+ expect(struct.prop).to eq '//x/y/'
294
+ end
295
+ it "can be set to 'x//y/'" do
296
+ struct.prop = 'x//y/'
297
+ expect(struct.prop).to eq '/a/b/x//y/'
298
+ end
299
+ it "can be set to 'x/y//'" do
300
+ struct.prop = 'x/y//'
301
+ expect(struct.prop).to eq '/a/b/x/y//'
302
+ end
303
+ end
304
+
305
+ context "With a Path property relative to a/b" do
306
+ with_property ChefResource::Types::Path, relative_to: 'a/b'
307
+
308
+ it "Defaults to nil" do
309
+ expect(struct.prop).to be_nil
310
+ end
311
+ it "can be set to nil" do
312
+ struct.prop = nil
313
+ expect(struct.prop).to be_nil
314
+ end
315
+ it "can be set to '/x/y'" do
316
+ struct.prop = '/x/y'
317
+ expect(struct.prop).to eq '/x/y'
318
+ end
319
+ it "can be set to '/x/y/'" do
320
+ struct.prop = '/x/y/'
321
+ expect(struct.prop).to eq '/x/y/'
322
+ end
323
+ it "can be set to 'x/y'" do
324
+ struct.prop = 'x/y'
325
+ expect(struct.prop).to eq 'a/b/x/y'
326
+ end
327
+ it "can be set to 'x/y/'" do
328
+ struct.prop = 'x/y/'
329
+ expect(struct.prop).to eq 'a/b/x/y/'
330
+ end
331
+ it "can be set to 'x'" do
332
+ struct.prop = 'x'
333
+ expect(struct.prop).to eq 'a/b/x'
334
+ end
335
+ it "can be set to 'x/'" do
336
+ struct.prop = 'x/'
337
+ expect(struct.prop).to eq 'a/b/x/'
338
+ end
339
+ it "can be set to '//x/y/'" do
340
+ struct.prop = '//x/y/'
341
+ expect(struct.prop).to eq '//x/y/'
342
+ end
343
+ it "can be set to 'x//y/'" do
344
+ struct.prop = 'x//y/'
345
+ expect(struct.prop).to eq 'a/b/x//y/'
346
+ end
347
+ it "can be set to 'x/y//'" do
348
+ struct.prop = 'x/y//'
349
+ expect(struct.prop).to eq 'a/b/x/y//'
350
+ end
351
+ end
352
+
353
+ context "With a Path property relative to a/b/" do
354
+ with_property ChefResource::Types::Path, relative_to: 'a/b/'
355
+
356
+ it "Defaults to nil" do
357
+ expect(struct.prop).to be_nil
358
+ end
359
+ it "can be set to nil" do
360
+ struct.prop = nil
361
+ expect(struct.prop).to be_nil
362
+ end
363
+ it "can be set to '/x/y'" do
364
+ struct.prop = '/x/y'
365
+ expect(struct.prop).to eq '/x/y'
366
+ end
367
+ it "can be set to '/x/y/'" do
368
+ struct.prop = '/x/y/'
369
+ expect(struct.prop).to eq '/x/y/'
370
+ end
371
+ it "can be set to 'x/y'" do
372
+ struct.prop = 'x/y'
373
+ expect(struct.prop).to eq 'a/b/x/y'
374
+ end
375
+ it "can be set to 'x/y/'" do
376
+ struct.prop = 'x/y/'
377
+ expect(struct.prop).to eq 'a/b/x/y/'
378
+ end
379
+ it "can be set to 'x'" do
380
+ struct.prop = 'x'
381
+ expect(struct.prop).to eq 'a/b/x'
382
+ end
383
+ it "can be set to 'x/'" do
384
+ struct.prop = 'x/'
385
+ expect(struct.prop).to eq 'a/b/x/'
386
+ end
387
+ it "can be set to '//x/y/'" do
388
+ struct.prop = '//x/y/'
389
+ expect(struct.prop).to eq '//x/y/'
390
+ end
391
+ it "can be set to 'x//y/'" do
392
+ struct.prop = 'x//y/'
393
+ expect(struct.prop).to eq 'a/b/x//y/'
394
+ end
395
+ it "can be set to 'x/y//'" do
396
+ struct.prop = 'x/y//'
397
+ expect(struct.prop).to eq 'a/b/x/y//'
398
+ end
399
+ end
400
+
401
+ context "With a Path property relative to a" do
402
+ with_property ChefResource::Types::Path, relative_to: 'a'
403
+
404
+ it "Defaults to nil" do
405
+ expect(struct.prop).to be_nil
406
+ end
407
+ it "can be set to nil" do
408
+ struct.prop = nil
409
+ expect(struct.prop).to be_nil
410
+ end
411
+ it "can be set to '/x/y'" do
412
+ struct.prop = '/x/y'
413
+ expect(struct.prop).to eq '/x/y'
414
+ end
415
+ it "can be set to '/x/y/'" do
416
+ struct.prop = '/x/y/'
417
+ expect(struct.prop).to eq '/x/y/'
418
+ end
419
+ it "can be set to 'x/y'" do
420
+ struct.prop = 'x/y'
421
+ expect(struct.prop).to eq 'a/x/y'
422
+ end
423
+ it "can be set to 'x/y/'" do
424
+ struct.prop = 'x/y/'
425
+ expect(struct.prop).to eq 'a/x/y/'
426
+ end
427
+ it "can be set to 'x'" do
428
+ struct.prop = 'x'
429
+ expect(struct.prop).to eq 'a/x'
430
+ end
431
+ it "can be set to 'x/'" do
432
+ struct.prop = 'x/'
433
+ expect(struct.prop).to eq 'a/x/'
434
+ end
435
+ it "can be set to '//x/y/'" do
436
+ struct.prop = '//x/y/'
437
+ expect(struct.prop).to eq '//x/y/'
438
+ end
439
+ it "can be set to 'x//y/'" do
440
+ struct.prop = 'x//y/'
441
+ expect(struct.prop).to eq 'a/x//y/'
442
+ end
443
+ it "can be set to 'x/y//'" do
444
+ struct.prop = 'x/y//'
445
+ expect(struct.prop).to eq 'a/x/y//'
446
+ end
447
+ end
448
+ end
449
+
450
+ describe ChefResource::Types::PathnameType do
451
+ context "With a Pathname property" do
452
+ with_property Pathname
453
+
454
+ it "can be set to nil" do
455
+ struct.prop = nil
456
+ expect(struct.prop).to be_nil
457
+ end
458
+ it "can be set to '/x/y'" do
459
+ struct.prop = '/x/y'
460
+ expect(struct.prop.to_s).to eq '/x/y'
461
+ end
462
+ it "can be set to '/x/y/'" do
463
+ struct.prop = '/x/y/'
464
+ expect(struct.prop.to_s).to eq '/x/y/'
465
+ end
466
+ it "can be set to 'x/y'" do
467
+ struct.prop = 'x/y'
468
+ expect(struct.prop.to_s).to eq 'x/y'
469
+ end
470
+ it "can be set to 'x/y/'" do
471
+ struct.prop = 'x/y/'
472
+ expect(struct.prop.to_s).to eq 'x/y/'
473
+ end
474
+ it "can be set to 'x'" do
475
+ struct.prop = 'x'
476
+ expect(struct.prop.to_s).to eq 'x'
477
+ end
478
+ it "can be set to 'x/'" do
479
+ struct.prop = 'x/'
480
+ expect(struct.prop.to_s).to eq 'x/'
481
+ end
482
+ it "can be set to '//x/y/'" do
483
+ struct.prop = '//x/y/'
484
+ expect(struct.prop.to_s).to eq '//x/y/'
485
+ end
486
+ it "can be set to '/x//y/'" do
487
+ struct.prop = '/x//y/'
488
+ expect(struct.prop.to_s).to eq '/x//y/'
489
+ end
490
+ it "can be set to '/x/y//'" do
491
+ struct.prop = '/x/y//'
492
+ expect(struct.prop.to_s).to eq '/x/y//'
493
+ end
494
+ end
495
+
496
+ context "Lazy" do
497
+ context "With a Pathname property with attr_default=c/d and default: ChefResource::LazyProc.new { attr_default }" do
498
+ with_struct do
499
+ property :attr_default, Pathname
500
+ property :prop, Pathname, default: ChefResource::LazyProc.new { attr_default }
501
+ end
502
+ before :each do
503
+ struct.attr_default 'c/d'
504
+ end
505
+ it "Defaults to c/d" do
506
+ expect(struct.prop).to eq Pathname.new('c/d')
507
+ end
508
+ end
509
+
510
+ context "With a Pathname property with rel=/a/b and relative_to: ChefResource::LazyProc.new { rel }" do
511
+ with_struct do
512
+ property :rel, Pathname
513
+ property :prop, Pathname, relative_to: ChefResource::LazyProc.new { rel }
514
+ end
515
+ before :each do
516
+ struct.rel = '/a/b'
517
+ end
518
+ it "Defaults to nil" do
519
+ expect(struct.prop).to be_nil
520
+ end
521
+ it "Relativizes c/d" do
522
+ struct.prop = 'c/d'
523
+ expect(struct.prop).to eq Pathname.new('/a/b/c/d')
524
+ end
525
+ end
526
+
527
+ context "With a Pathname property attr_default=c/d, rel=/a/b and relative_to: ChefResource::LazyProc.new { rel }, and default: ChefResource::LazyProc.new { attr_default }" do
528
+ with_struct do
529
+ property :attr_default, Pathname
530
+ property :rel, Pathname
531
+ property :prop, Pathname, relative_to: ChefResource::LazyProc.new { rel }, default: ChefResource::LazyProc.new { attr_default }
532
+ end
533
+ before :each do
534
+ struct.attr_default 'c/d'
535
+ struct.rel '/a/b'
536
+ end
537
+ it "Defaults to /a/b/c/d" do
538
+ expect(struct.prop).to eq Pathname.new('/a/b/c/d')
539
+ end
540
+ it "Relativizes foo/bar" do
541
+ struct.prop = 'foo/bar'
542
+ expect(struct.prop).to eq Pathname.new('/a/b/foo/bar')
543
+ end
544
+ end
545
+ end
546
+
547
+ context "With a Pathname property relative to /a/b" do
548
+ with_property Pathname, relative_to: '/a/b'
549
+
550
+ it "Defaults to nil" do
551
+ expect(struct.prop).to be_nil
552
+ end
553
+ it "can be set to nil" do
554
+ struct.prop = nil
555
+ expect(struct.prop).to be_nil
556
+ end
557
+ it "can be set to '/x/y'" do
558
+ struct.prop = '/x/y'
559
+ expect(struct.prop.to_s).to eq '/x/y'
560
+ end
561
+ it "can be set to '/x/y/'" do
562
+ struct.prop = '/x/y/'
563
+ expect(struct.prop.to_s).to eq '/x/y/'
564
+ end
565
+ it "can be set to 'x/y'" do
566
+ struct.prop = 'x/y'
567
+ expect(struct.prop.to_s).to eq '/a/b/x/y'
568
+ end
569
+ it "can be set to 'x/y/'" do
570
+ struct.prop = 'x/y/'
571
+ expect(struct.prop.to_s).to eq '/a/b/x/y/'
572
+ end
573
+ it "can be set to 'x'" do
574
+ struct.prop = 'x'
575
+ expect(struct.prop.to_s).to eq '/a/b/x'
576
+ end
577
+ it "can be set to 'x/'" do
578
+ struct.prop = 'x/'
579
+ expect(struct.prop.to_s).to eq '/a/b/x/'
580
+ end
581
+ it "can be set to '//x/y/'" do
582
+ struct.prop = '//x/y/'
583
+ expect(struct.prop.to_s).to eq '//x/y/'
584
+ end
585
+ it "can be set to 'x//y/'" do
586
+ struct.prop = 'x//y/'
587
+ expect(struct.prop.to_s).to eq '/a/b/x//y/'
588
+ end
589
+ it "can be set to 'x/y//'" do
590
+ struct.prop = 'x/y//'
591
+ expect(struct.prop.to_s).to eq '/a/b/x/y//'
592
+ end
593
+ end
594
+
595
+ context "With a Pathname property relative to a/b" do
596
+ with_property Pathname, relative_to: 'a/b'
597
+
598
+ it "Defaults to nil" do
599
+ expect(struct.prop).to be_nil
600
+ end
601
+ it "can be set to nil" do
602
+ struct.prop = nil
603
+ expect(struct.prop).to be_nil
604
+ end
605
+ it "can be set to '/x/y'" do
606
+ struct.prop = '/x/y'
607
+ expect(struct.prop.to_s).to eq '/x/y'
608
+ end
609
+ it "can be set to '/x/y/'" do
610
+ struct.prop = '/x/y/'
611
+ expect(struct.prop.to_s).to eq '/x/y/'
612
+ end
613
+ it "can be set to 'x/y'" do
614
+ struct.prop = 'x/y'
615
+ expect(struct.prop.to_s).to eq 'a/b/x/y'
616
+ end
617
+ it "can be set to 'x/y/'" do
618
+ struct.prop = 'x/y/'
619
+ expect(struct.prop.to_s).to eq 'a/b/x/y/'
620
+ end
621
+ it "can be set to 'x'" do
622
+ struct.prop = 'x'
623
+ expect(struct.prop.to_s).to eq 'a/b/x'
624
+ end
625
+ it "can be set to 'x/'" do
626
+ struct.prop = 'x/'
627
+ expect(struct.prop.to_s).to eq 'a/b/x/'
628
+ end
629
+ it "can be set to '//x/y/'" do
630
+ struct.prop = '//x/y/'
631
+ expect(struct.prop.to_s).to eq '//x/y/'
632
+ end
633
+ it "can be set to 'x//y/'" do
634
+ struct.prop = 'x//y/'
635
+ expect(struct.prop.to_s).to eq 'a/b/x//y/'
636
+ end
637
+ it "can be set to 'x/y//'" do
638
+ struct.prop = 'x/y//'
639
+ expect(struct.prop.to_s).to eq 'a/b/x/y//'
640
+ end
641
+ end
642
+
643
+ context "With a Pathname property relative to a/b/" do
644
+ with_property Pathname, relative_to: 'a/b/'
645
+
646
+ it "Defaults to nil" do
647
+ expect(struct.prop).to be_nil
648
+ end
649
+ it "can be set to nil" do
650
+ struct.prop = nil
651
+ expect(struct.prop).to be_nil
652
+ end
653
+ it "can be set to '/x/y'" do
654
+ struct.prop = '/x/y'
655
+ expect(struct.prop.to_s).to eq '/x/y'
656
+ end
657
+ it "can be set to '/x/y/'" do
658
+ struct.prop = '/x/y/'
659
+ expect(struct.prop.to_s).to eq '/x/y/'
660
+ end
661
+ it "can be set to 'x/y'" do
662
+ struct.prop = 'x/y'
663
+ expect(struct.prop.to_s).to eq 'a/b/x/y'
664
+ end
665
+ it "can be set to 'x/y/'" do
666
+ struct.prop = 'x/y/'
667
+ expect(struct.prop.to_s).to eq 'a/b/x/y/'
668
+ end
669
+ it "can be set to 'x'" do
670
+ struct.prop = 'x'
671
+ expect(struct.prop.to_s).to eq 'a/b/x'
672
+ end
673
+ it "can be set to 'x/'" do
674
+ struct.prop = 'x/'
675
+ expect(struct.prop.to_s).to eq 'a/b/x/'
676
+ end
677
+ it "can be set to '//x/y/'" do
678
+ struct.prop = '//x/y/'
679
+ expect(struct.prop.to_s).to eq '//x/y/'
680
+ end
681
+ it "can be set to 'x//y/'" do
682
+ struct.prop = 'x//y/'
683
+ expect(struct.prop.to_s).to eq 'a/b/x//y/'
684
+ end
685
+ it "can be set to 'x/y//'" do
686
+ struct.prop = 'x/y//'
687
+ expect(struct.prop.to_s).to eq 'a/b/x/y//'
688
+ end
689
+ end
690
+
691
+ context "With a Pathname property relative to a" do
692
+ with_property Pathname, relative_to: 'a'
693
+
694
+ it "Defaults to nil" do
695
+ expect(struct.prop).to be_nil
696
+ end
697
+ it "can be set to nil" do
698
+ struct.prop = nil
699
+ expect(struct.prop).to be_nil
700
+ end
701
+ it "can be set to '/x/y'" do
702
+ struct.prop = '/x/y'
703
+ expect(struct.prop.to_s).to eq '/x/y'
704
+ end
705
+ it "can be set to '/x/y/'" do
706
+ struct.prop = '/x/y/'
707
+ expect(struct.prop.to_s).to eq '/x/y/'
708
+ end
709
+ it "can be set to 'x/y'" do
710
+ struct.prop = 'x/y'
711
+ expect(struct.prop.to_s).to eq 'a/x/y'
712
+ end
713
+ it "can be set to 'x/y/'" do
714
+ struct.prop = 'x/y/'
715
+ expect(struct.prop.to_s).to eq 'a/x/y/'
716
+ end
717
+ it "can be set to 'x'" do
718
+ struct.prop = 'x'
719
+ expect(struct.prop.to_s).to eq 'a/x'
720
+ end
721
+ it "can be set to 'x/'" do
722
+ struct.prop = 'x/'
723
+ expect(struct.prop.to_s).to eq 'a/x/'
724
+ end
725
+ it "can be set to '//x/y/'" do
726
+ struct.prop = '//x/y/'
727
+ expect(struct.prop.to_s).to eq '//x/y/'
728
+ end
729
+ it "can be set to 'x//y/'" do
730
+ struct.prop = 'x//y/'
731
+ expect(struct.prop.to_s).to eq 'a/x//y/'
732
+ end
733
+ it "can be set to 'x/y//'" do
734
+ struct.prop = 'x/y//'
735
+ expect(struct.prop.to_s).to eq 'a/x/y//'
736
+ end
737
+ end
738
+ end
739
+
740
+ describe ChefResource::Types::URIType do
741
+ context "With a URI property" do
742
+ with_property URI
743
+
744
+ it "Defaults to nil" do
745
+ expect(struct.prop).to be_nil
746
+ end
747
+ it "can be set to nil" do
748
+ struct.prop = nil
749
+ expect(struct.prop).to be_nil
750
+ end
751
+ it "can be set to 'https://blah.com'" do
752
+ struct.prop = 'https://blah.com'
753
+ expect(struct.prop.to_s).to eq 'https://blah.com'
754
+ end
755
+ it "can be set to 'https://blah.com/zztop'" do
756
+ struct.prop = 'https://blah.com/zztop'
757
+ expect(struct.prop.to_s).to eq 'https://blah.com/zztop'
758
+ end
759
+ it "can be set to '/x/y'" do
760
+ struct.prop = '/x/y'
761
+ expect(struct.prop.to_s).to eq '/x/y'
762
+ end
763
+ it "can be set to '/x/y/'" do
764
+ struct.prop = '/x/y/'
765
+ expect(struct.prop.to_s).to eq '/x/y/'
766
+ end
767
+ it "can be set to 'x/y'" do
768
+ struct.prop = 'x/y'
769
+ expect(struct.prop.to_s).to eq 'x/y'
770
+ end
771
+ it "can be set to 'x/y/'" do
772
+ struct.prop = 'x/y/'
773
+ expect(struct.prop.to_s).to eq 'x/y/'
774
+ end
775
+ it "can be set to 'x'" do
776
+ struct.prop = 'x'
777
+ expect(struct.prop.to_s).to eq 'x'
778
+ end
779
+ it "can be set to 'x/'" do
780
+ struct.prop = 'x/'
781
+ expect(struct.prop.to_s).to eq 'x/'
782
+ end
783
+ it "can be set to '//x/y/'" do
784
+ struct.prop = '//x/y/'
785
+ expect(struct.prop.to_s).to eq '//x/y/'
786
+ end
787
+ it "can be set to '/x//y/'" do
788
+ struct.prop = '/x//y/'
789
+ expect(struct.prop.to_s).to eq '/x//y/'
790
+ end
791
+ it "can be set to '/x/y//'" do
792
+ struct.prop = '/x/y//'
793
+ expect(struct.prop.to_s).to eq '/x/y//'
794
+ end
795
+ end
796
+
797
+ context "Lazy" do
798
+ context "With a URI property with attr_default=c/d and default: ChefResource::LazyProc.new { attr_default }" do
799
+ with_struct do
800
+ property :attr_default, URI, nullable: :validate
801
+ property :prop, URI, default: ChefResource::LazyProc.new { attr_default }, nullable: :validate
802
+ end
803
+ before :each do
804
+ struct.attr_default 'c/d'
805
+ end
806
+ it "Defaults to c/d" do
807
+ expect(struct.prop.to_s).to eq 'c/d'
808
+ end
809
+ end
810
+
811
+ context "With a URI property with rel=https://google.com and relative_to: ChefResource::LazyProc.new { rel }" do
812
+ with_struct do
813
+ property :rel, URI, nullable: :validate
814
+ property :prop, URI, relative_to: ChefResource::LazyProc.new { rel }, nullable: :validate
815
+ end
816
+ before :each do
817
+ struct.rel = 'https://google.com'
818
+ end
819
+ it "Defaults to nil" do
820
+ expect(struct.prop).to be_nil
821
+ end
822
+ it "Relativizes c/d" do
823
+ struct.prop = 'c/d'
824
+ expect(struct.prop.to_s).to eq 'https://google.com/c/d'
825
+ end
826
+ end
827
+
828
+ context "With a URI property attr_default=c/d, rel=/a/b and relative_to: ChefResource::LazyProc.new { rel }, and default: ChefResource::LazyProc.new { attr_default }" do
829
+ with_struct do
830
+ property :attr_default, URI, nullable: :validate
831
+ property :rel, URI, nullable: :validate
832
+ property :prop, URI, relative_to: ChefResource::LazyProc.new { rel }, default: ChefResource::LazyProc.new { attr_default }, nullable: :validate
833
+ end
834
+ before :each do
835
+ struct.attr_default 'c/d'
836
+ struct.rel 'https://google.com'
837
+ end
838
+ it "Defaults to https://google.com/c/d" do
839
+ expect(struct.prop.to_s).to eq 'https://google.com/c/d'
840
+ end
841
+ it "Relativizes foo/bar" do
842
+ struct.prop = 'foo/bar'
843
+ expect(struct.prop.to_s).to eq 'https://google.com/foo/bar'
844
+ end
845
+ end
846
+ end
847
+
848
+ context "With a URI property relative to https://google.com/a/b" do
849
+ with_property URI, relative_to: 'https://google.com/a/b', nullable: :validate
850
+
851
+ it "Defaults to nil" do
852
+ expect(struct.prop).to be_nil
853
+ end
854
+ it "can be set to nil" do
855
+ struct.prop = nil
856
+ expect(struct.prop).to be_nil
857
+ end
858
+ it "can be set to 'https://blah.com'" do
859
+ struct.prop = 'https://blah.com'
860
+ expect(struct.prop.to_s).to eq 'https://blah.com'
861
+ end
862
+ it "can be set to 'https://blah.com/zztop'" do
863
+ struct.prop = 'https://blah.com/zztop'
864
+ expect(struct.prop.to_s).to eq 'https://blah.com/zztop'
865
+ end
866
+ it "can be set to '/x/y'" do
867
+ struct.prop = '/x/y'
868
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y'
869
+ end
870
+ it "can be set to '/x/y/'" do
871
+ struct.prop = '/x/y/'
872
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y/'
873
+ end
874
+ it "can be set to 'x/y'" do
875
+ pending
876
+ struct.prop = 'x/y'
877
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x/y'
878
+ end
879
+ it "can be set to 'x/y/'" do
880
+ pending
881
+ struct.prop = 'x/y/'
882
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x/y/'
883
+ end
884
+ it "can be set to 'x'" do
885
+ pending
886
+ struct.prop = 'x'
887
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x'
888
+ end
889
+ it "can be set to 'x/'" do
890
+ pending
891
+ struct.prop = 'x/'
892
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x/'
893
+ end
894
+ it "can be set to '//x.com/y/'" do
895
+ struct.prop = '//x.com/y/'
896
+ expect(struct.prop.to_s).to eq 'https://x.com/y/'
897
+ end
898
+ it "can be set to 'x//y/'" do
899
+ pending
900
+ struct.prop = 'x//y/'
901
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x/y/'
902
+ end
903
+ it "can be set to 'x/y//'" do
904
+ pending
905
+ struct.prop = 'x/y//'
906
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x/y/'
907
+ end
908
+ end
909
+
910
+ context "With a URI property relative to https://google.com/a/b/" do
911
+ with_property URI, relative_to: 'https://google.com/a/b/', nullable: :validate
912
+
913
+ it "Defaults to nil" do
914
+ expect(struct.prop).to be_nil
915
+ end
916
+ it "can be set to nil" do
917
+ struct.prop = nil
918
+ expect(struct.prop).to be_nil
919
+ end
920
+ it "can be set to 'https://blah.com'" do
921
+ struct.prop = 'https://blah.com'
922
+ expect(struct.prop.to_s).to eq 'https://blah.com'
923
+ end
924
+ it "can be set to 'https://blah.com/zztop'" do
925
+ struct.prop = 'https://blah.com/zztop'
926
+ expect(struct.prop.to_s).to eq 'https://blah.com/zztop'
927
+ end
928
+ it "can be set to '/x/y'" do
929
+ struct.prop = '/x/y'
930
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y'
931
+ end
932
+ it "can be set to '/x/y/'" do
933
+ struct.prop = '/x/y/'
934
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y/'
935
+ end
936
+ it "can be set to 'x/y'" do
937
+ struct.prop = 'x/y'
938
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x/y'
939
+ end
940
+ it "can be set to 'x/y/'" do
941
+ struct.prop = 'x/y/'
942
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x/y/'
943
+ end
944
+ it "can be set to 'x'" do
945
+ struct.prop = 'x'
946
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x'
947
+ end
948
+ it "can be set to 'x/'" do
949
+ struct.prop = 'x/'
950
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x/'
951
+ end
952
+ it "can be set to '//x.com/y/'" do
953
+ struct.prop = '//x.com/y/'
954
+ expect(struct.prop.to_s).to eq 'https://x.com/y/'
955
+ end
956
+ it "can be set to 'x//y/'" do
957
+ struct.prop = 'x//y/'
958
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x/y/'
959
+ end
960
+ it "can be set to 'x/y//'" do
961
+ struct.prop = 'x/y//'
962
+ expect(struct.prop.to_s).to eq 'https://google.com/a/b/x/y/'
963
+ end
964
+ end
965
+
966
+ context "With a URI property relative to https://google.com" do
967
+ with_property URI, relative_to: 'https://google.com', nullable: :validate
968
+
969
+ it "Defaults to nil" do
970
+ expect(struct.prop).to be_nil
971
+ end
972
+ it "can be set to nil" do
973
+ struct.prop = nil
974
+ expect(struct.prop).to be_nil
975
+ end
976
+ it "can be set to 'https://blah.com'" do
977
+ struct.prop = 'https://blah.com'
978
+ expect(struct.prop.to_s).to eq 'https://blah.com'
979
+ end
980
+ it "can be set to 'https://blah.com/zztop'" do
981
+ struct.prop = 'https://blah.com/zztop'
982
+ expect(struct.prop.to_s).to eq 'https://blah.com/zztop'
983
+ end
984
+ it "can be set to '/x/y'" do
985
+ struct.prop = '/x/y'
986
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y'
987
+ end
988
+ it "can be set to '/x/y/'" do
989
+ struct.prop = '/x/y/'
990
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y/'
991
+ end
992
+ it "can be set to 'x/y'" do
993
+ struct.prop = 'x/y'
994
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y'
995
+ end
996
+ it "can be set to 'x/y/'" do
997
+ struct.prop = 'x/y/'
998
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y/'
999
+ end
1000
+ it "can be set to 'x'" do
1001
+ struct.prop = 'x'
1002
+ expect(struct.prop.to_s).to eq 'https://google.com/x'
1003
+ end
1004
+ it "can be set to 'x/'" do
1005
+ struct.prop = 'x/'
1006
+ expect(struct.prop.to_s).to eq 'https://google.com/x/'
1007
+ end
1008
+ it "can be set to '//x.com/y/'" do
1009
+ struct.prop = '//x.com/y/'
1010
+ expect(struct.prop.to_s).to eq 'https://x.com/y/'
1011
+ end
1012
+ it "can be set to 'x//y/'" do
1013
+ struct.prop = 'x//y/'
1014
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y/'
1015
+ end
1016
+ it "can be set to 'x/y//'" do
1017
+ struct.prop = 'x/y//'
1018
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y/'
1019
+ end
1020
+ end
1021
+
1022
+ context "With a URI property relative to https://google.com/" do
1023
+ with_property URI, relative_to: 'https://google.com/', nullable: :validate
1024
+
1025
+ it "Defaults to nil" do
1026
+ expect(struct.prop).to be_nil
1027
+ end
1028
+ it "can be set to nil" do
1029
+ struct.prop = nil
1030
+ expect(struct.prop).to be_nil
1031
+ end
1032
+ it "can be set to 'https://blah.com'" do
1033
+ struct.prop = 'https://blah.com'
1034
+ expect(struct.prop.to_s).to eq 'https://blah.com'
1035
+ end
1036
+ it "can be set to 'https://blah.com/zztop'" do
1037
+ struct.prop = 'https://blah.com/zztop'
1038
+ expect(struct.prop.to_s).to eq 'https://blah.com/zztop'
1039
+ end
1040
+ it "can be set to '/x/y'" do
1041
+ struct.prop = '/x/y'
1042
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y'
1043
+ end
1044
+ it "can be set to '/x/y/'" do
1045
+ struct.prop = '/x/y/'
1046
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y/'
1047
+ end
1048
+ it "can be set to 'x/y'" do
1049
+ struct.prop = 'x/y'
1050
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y'
1051
+ end
1052
+ it "can be set to 'x/y/'" do
1053
+ struct.prop = 'x/y/'
1054
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y/'
1055
+ end
1056
+ it "can be set to 'x'" do
1057
+ struct.prop = 'x'
1058
+ expect(struct.prop.to_s).to eq 'https://google.com/x'
1059
+ end
1060
+ it "can be set to 'x/'" do
1061
+ struct.prop = 'x/'
1062
+ expect(struct.prop.to_s).to eq 'https://google.com/x/'
1063
+ end
1064
+ it "can be set to '//x.com/y/'" do
1065
+ struct.prop = '//x.com/y/'
1066
+ expect(struct.prop.to_s).to eq 'https://x.com/y/'
1067
+ end
1068
+ it "can be set to 'x//y/'" do
1069
+ struct.prop = 'x//y/'
1070
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y/'
1071
+ end
1072
+ it "can be set to 'x/y//'" do
1073
+ struct.prop = 'x/y//'
1074
+ expect(struct.prop.to_s).to eq 'https://google.com/x/y/'
1075
+ end
1076
+ end
1077
+ end
1078
+
1079
+ describe ChefResource::Types::StringType do
1080
+ context "With a String property" do
1081
+ with_property String, nullable: :validate
1082
+
1083
+ it "Can be set to 'blah'" do
1084
+ struct.prop = 'blah'
1085
+ expect(struct.prop).to eq 'blah'
1086
+ end
1087
+ it "Can be set to :blah" do
1088
+ struct.prop = :blah
1089
+ expect(struct.prop).to eq 'blah'
1090
+ end
1091
+ it "Can be set to nil" do
1092
+ struct.prop = nil
1093
+ expect(struct.prop).to be_nil
1094
+ end
1095
+ it "Can be set to 1" do
1096
+ struct.prop = 1
1097
+ expect(struct.prop).to eq '1'
1098
+ end
1099
+ end
1100
+ end
1101
+
1102
+ describe ChefResource::Types::SymbolType do
1103
+ context "With a Symbol property" do
1104
+ with_property Symbol, nullable: :validate
1105
+
1106
+ it "Can be set to :blah" do
1107
+ struct.prop = :blah
1108
+ expect(struct.prop).to eq :blah
1109
+ end
1110
+ it "Can be set to 'blah'" do
1111
+ struct.prop = 'blah'
1112
+ expect(struct.prop).to eq :blah
1113
+ end
1114
+ it "Can be set to nil" do
1115
+ struct.prop = nil
1116
+ expect(struct.prop).to be_nil
1117
+ end
1118
+ it "Cannot be set to 1" do
1119
+ expect { struct.prop = 1 }.to raise_error ChefResource::ValidationError
1120
+ end
1121
+ end
1122
+ end
1123
+ end