puppet 5.0.1-x64-mingw32 → 5.1.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/lib/puppet/agent.rb +1 -0
  3. data/lib/puppet/defaults.rb +1 -1
  4. data/lib/puppet/functions.rb +6 -7
  5. data/lib/puppet/functions/all.rb +100 -0
  6. data/lib/puppet/functions/any.rb +105 -0
  7. data/lib/puppet/functions/defined.rb +3 -3
  8. data/lib/puppet/functions/new.rb +2 -1
  9. data/lib/puppet/functions/reduce.rb +31 -0
  10. data/lib/puppet/functions/tree_each.rb +200 -0
  11. data/lib/puppet/module.rb +30 -0
  12. data/lib/puppet/parser/functions/new.rb +67 -0
  13. data/lib/puppet/parser/functions/reduce.rb +31 -0
  14. data/lib/puppet/parser/relationship.rb +2 -2
  15. data/lib/puppet/parser/resource.rb +39 -10
  16. data/lib/puppet/parser/scope.rb +1 -1
  17. data/lib/puppet/pops/evaluator/access_operator.rb +11 -4
  18. data/lib/puppet/pops/evaluator/collector_transformer.rb +1 -1
  19. data/lib/puppet/pops/evaluator/evaluator_impl.rb +4 -4
  20. data/lib/puppet/pops/evaluator/relationship_operator.rb +1 -1
  21. data/lib/puppet/pops/evaluator/runtime3_converter.rb +3 -3
  22. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +1 -1
  23. data/lib/puppet/pops/loader/module_loaders.rb +1 -1
  24. data/lib/puppet/pops/loader/static_loader.rb +1 -2
  25. data/lib/puppet/pops/loaders.rb +1 -2
  26. data/lib/puppet/pops/lookup/context.rb +1 -1
  27. data/lib/puppet/pops/lookup/lookup_adapter.rb +2 -1
  28. data/lib/puppet/pops/model/ast.rb +440 -436
  29. data/lib/puppet/pops/model/factory.rb +140 -140
  30. data/lib/puppet/pops/pcore.rb +1 -2
  31. data/lib/puppet/pops/resource/param.rb +1 -1
  32. data/lib/puppet/pops/resource/resource_type_impl.rb +1 -1
  33. data/lib/puppet/pops/serialization/from_data_converter.rb +0 -12
  34. data/lib/puppet/pops/time/timestamp.rb +29 -17
  35. data/lib/puppet/pops/types/annotatable.rb +2 -2
  36. data/lib/puppet/pops/types/annotation.rb +8 -8
  37. data/lib/puppet/pops/types/class_loader.rb +3 -3
  38. data/lib/puppet/pops/types/implementation_registry.rb +1 -1
  39. data/lib/puppet/pops/types/iterable.rb +2 -2
  40. data/lib/puppet/pops/types/p_binary_type.rb +2 -2
  41. data/lib/puppet/pops/types/p_init_type.rb +238 -0
  42. data/lib/puppet/pops/types/p_meta_type.rb +14 -11
  43. data/lib/puppet/pops/types/p_object_type.rb +15 -15
  44. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +2 -2
  45. data/lib/puppet/pops/types/p_sem_ver_type.rb +2 -2
  46. data/lib/puppet/pops/types/p_sensitive_type.rb +2 -2
  47. data/lib/puppet/pops/types/p_timespan_type.rb +6 -6
  48. data/lib/puppet/pops/types/p_timestamp_type.rb +6 -2
  49. data/lib/puppet/pops/types/p_type_set_type.rb +10 -9
  50. data/lib/puppet/pops/types/ruby_generator.rb +6 -5
  51. data/lib/puppet/pops/types/ruby_method.rb +2 -2
  52. data/lib/puppet/pops/types/string_converter.rb +1 -1
  53. data/lib/puppet/pops/types/tree_iterators.rb +250 -0
  54. data/lib/puppet/pops/types/type_calculator.rb +13 -13
  55. data/lib/puppet/pops/types/type_factory.rb +26 -7
  56. data/lib/puppet/pops/types/type_formatter.rb +9 -4
  57. data/lib/puppet/pops/types/type_parser.rb +8 -3
  58. data/lib/puppet/pops/types/type_set_reference.rb +2 -2
  59. data/lib/puppet/pops/types/types.rb +168 -109
  60. data/lib/puppet/provider/package/gem.rb +10 -9
  61. data/lib/puppet/provider/package/pip.rb +12 -3
  62. data/lib/puppet/provider/package/yum.rb +9 -1
  63. data/lib/puppet/resource/capability_finder.rb +30 -11
  64. data/lib/puppet/type/file.rb +21 -13
  65. data/lib/puppet/util/execution.rb +67 -14
  66. data/lib/puppet/util/suidmanager.rb +1 -0
  67. data/lib/puppet/version.rb +1 -1
  68. data/locales/puppet.pot +130 -66
  69. data/man/man5/puppet.conf.5 +1 -1
  70. data/spec/fixtures/unit/provider/package/yum/yum-check-update-simple.txt +1 -0
  71. data/spec/integration/parser/collection_spec.rb +40 -1
  72. data/spec/shared_contexts/types_setup.rb +41 -2
  73. data/spec/unit/agent_spec.rb +11 -0
  74. data/spec/unit/file_bucket/dipper_spec.rb +13 -4
  75. data/spec/unit/functions/all_spec.rb +97 -0
  76. data/spec/unit/functions/any_spec.rb +109 -0
  77. data/spec/unit/functions/hiera_spec.rb +5 -0
  78. data/spec/unit/functions/new_spec.rb +66 -0
  79. data/spec/unit/functions/tree_each_spec.rb +444 -0
  80. data/spec/unit/module_spec.rb +29 -0
  81. data/spec/unit/pops/serialization/serialization_spec.rb +2 -2
  82. data/spec/unit/pops/serialization/to_from_hr_spec.rb +2 -2
  83. data/spec/unit/pops/types/iterable_spec.rb +9 -9
  84. data/spec/unit/pops/types/p_init_type_spec.rb +285 -0
  85. data/spec/unit/pops/types/p_object_type_spec.rb +8 -8
  86. data/spec/unit/pops/types/p_sensitive_type_spec.rb +4 -0
  87. data/spec/unit/pops/types/p_timespan_type_spec.rb +14 -0
  88. data/spec/unit/pops/types/p_timestamp_type_spec.rb +19 -1
  89. data/spec/unit/pops/types/p_type_set_type_spec.rb +2 -2
  90. data/spec/unit/pops/types/ruby_generator_spec.rb +9 -22
  91. data/spec/unit/pops/types/string_converter_spec.rb +2 -2
  92. data/spec/unit/pops/types/type_acceptor_spec.rb +2 -2
  93. data/spec/unit/pops/types/type_calculator_spec.rb +43 -38
  94. data/spec/unit/pops/types/type_factory_spec.rb +6 -6
  95. data/spec/unit/pops/types/type_formatter_spec.rb +6 -6
  96. data/spec/unit/pops/types/types_spec.rb +16 -4
  97. data/spec/unit/provider/package/gem_spec.rb +6 -6
  98. data/spec/unit/provider/package/pip_spec.rb +44 -23
  99. data/spec/unit/provider/package/puppet_gem_spec.rb +1 -1
  100. data/spec/unit/provider/package/yum_spec.rb +8 -0
  101. data/spec/unit/resource/capability_finder_spec.rb +4 -5
  102. data/spec/unit/type/file_spec.rb +19 -14
  103. data/spec/unit/util/execution_spec.rb +216 -82
  104. data/tasks/generate_ast_model.rake +10 -2
  105. metadata +15 -2
@@ -0,0 +1,444 @@
1
+ require 'puppet'
2
+ require 'spec_helper'
3
+ require 'puppet_spec/compiler'
4
+
5
+ require 'shared_behaviours/iterative_functions'
6
+
7
+ describe 'the tree_each function' do
8
+ include PuppetSpec::Compiler
9
+
10
+ context "can be called on" do
11
+ it 'an Array, yielding path and value when lambda has arity 2' do
12
+ catalog = compile_to_catalog(<<-MANIFEST)
13
+ $a = [1,2,3]
14
+ $msg = inline_epp(@(TEMPLATE))
15
+ <% $a.tree_each() |$path, $v| { -%>
16
+ path: <%= $path %> value: <%= $v %>
17
+ <% } -%>
18
+ | TEMPLATE
19
+ notify {'test': message => $msg}
20
+ MANIFEST
21
+
22
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
23
+ [ 'path: [] value: [1, 2, 3]',
24
+ 'path: [0] value: 1',
25
+ 'path: [1] value: 2',
26
+ 'path: [2] value: 3',
27
+ ''
28
+ ].join("\n"))
29
+ end
30
+
31
+ it 'an Array, yielding only value when lambda has arity 1' do
32
+ catalog = compile_to_catalog(<<-MANIFEST)
33
+ $a = [1,2,3]
34
+ $msg = inline_epp(@(TEMPLATE))
35
+ <% $a.tree_each() | $v| { -%>
36
+ path: - value: <%= $v %>
37
+ <% } -%>
38
+ | TEMPLATE
39
+ notify {'test': message => $msg}
40
+ MANIFEST
41
+
42
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
43
+ [ 'path: - value: [1, 2, 3]',
44
+ 'path: - value: 1',
45
+ 'path: - value: 2',
46
+ 'path: - value: 3',
47
+ ''
48
+ ].join("\n"))
49
+ end
50
+
51
+ it 'a Hash, yielding path and value when lambda has arity 2' do
52
+ catalog = compile_to_catalog(<<-MANIFEST)
53
+ $a = {'a'=>'apple','b'=>'banana'}
54
+ $msg = inline_epp(@(TEMPLATE))
55
+ <% $a.tree_each() |$path, $v| { -%>
56
+ path: <%= $path %> value: <%= $v %>
57
+ <% } -%>
58
+ | TEMPLATE
59
+ notify {'test': message => $msg}
60
+ MANIFEST
61
+
62
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
63
+ [ 'path: [] value: {a => apple, b => banana}',
64
+ 'path: [a] value: apple',
65
+ 'path: [b] value: banana',
66
+ ''
67
+ ].join("\n"))
68
+ end
69
+
70
+ it 'a Hash, yielding only value when lambda has arity 1' do
71
+ catalog = compile_to_catalog(<<-MANIFEST)
72
+ $a = {'a'=>'apple','b'=>'banana'}
73
+ $msg = inline_epp(@(TEMPLATE))
74
+ <% $a.tree_each() | $v| { -%>
75
+ path: - value: <%= $v %>
76
+ <% } -%>
77
+ | TEMPLATE
78
+ notify {'test': message => $msg}
79
+ MANIFEST
80
+
81
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
82
+ [ 'path: - value: {a => apple, b => banana}',
83
+ 'path: - value: apple',
84
+ 'path: - value: banana',
85
+ ''
86
+ ].join("\n"))
87
+ end
88
+
89
+ it 'an Object, yielding path and value when lambda has arity 2' do
90
+ # this also tests that include_refs => true includes references
91
+ catalog = compile_to_catalog(<<-MANIFEST)
92
+ type Person = Object[{attributes => {
93
+ name => String,
94
+ father => Optional[Person],
95
+ mother => { kind => reference, type => Optional[Person] }
96
+ }}]
97
+ $adam = Person({name => 'Adam'})
98
+ $eve = Person({name => 'Eve'})
99
+ $cain = Person({name => 'Cain', mother => $eve, father => $adam})
100
+ $awan = Person({name => 'Awan', mother => $eve, father => $adam})
101
+ $enoch = Person({name => 'Enoch', mother => $awan, father => $cain})
102
+
103
+ $msg = inline_epp(@(TEMPLATE))
104
+ <% $enoch.tree_each({include_containers=>false, include_refs => true}) |$path, $v| { unless $v =~ Undef {-%>
105
+ path: <%= $path %> value: <%= $v %>
106
+ <% }} -%>
107
+ | TEMPLATE
108
+ notify {'with_refs': message => $msg}
109
+
110
+ MANIFEST
111
+
112
+ expect(catalog.resource(:notify, 'with_refs')['message']).to eq(
113
+ [
114
+ 'path: [name] value: Enoch',
115
+ 'path: [father, name] value: Cain',
116
+ 'path: [father, father, name] value: Adam',
117
+ 'path: [father, mother, name] value: Eve',
118
+ 'path: [mother, name] value: Awan',
119
+ 'path: [mother, father, name] value: Adam',
120
+ 'path: [mother, mother, name] value: Eve',
121
+ ''
122
+ ].join("\n"))
123
+ end
124
+ end
125
+
126
+ context 'a yielded path' do
127
+ it 'holds integer values for Array index at each level' do
128
+ catalog = compile_to_catalog(<<-MANIFEST)
129
+ $a = [1,[2,[3]]]
130
+ $msg = inline_epp(@(TEMPLATE))
131
+ <% $a.tree_each() |$path, $v| { -%>
132
+ path: <%= $path %> t: <%= $path.map |$x| { type($x, generalized) } %> value: <%= $v %>
133
+ <% } -%>
134
+ | TEMPLATE
135
+ notify {'test': message => $msg}
136
+ MANIFEST
137
+
138
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
139
+ [ 'path: [] t: [] value: [1, [2, [3]]]',
140
+ 'path: [0] t: [Integer] value: 1',
141
+ 'path: [1] t: [Integer] value: [2, [3]]',
142
+ 'path: [1, 0] t: [Integer, Integer] value: 2',
143
+ 'path: [1, 1] t: [Integer, Integer] value: [3]',
144
+ 'path: [1, 1, 0] t: [Integer, Integer, Integer] value: 3',
145
+ ''
146
+ ].join("\n"))
147
+ end
148
+
149
+ it 'holds Any values for Hash keys at each level' do
150
+ catalog = compile_to_catalog(<<-MANIFEST)
151
+ $a = {a => 1, /fancy/=> {c => 2, d=>{[e] => 3}}}
152
+ $msg = inline_epp(@(TEMPLATE))
153
+ <% $a.tree_each() |$path, $v| { -%>
154
+ path: <%= $path %> t: <%= $path.map |$x| { type($x, generalized) } %> value: <%= $v %>
155
+ <% } -%>
156
+ | TEMPLATE
157
+ notify {'test': message => $msg}
158
+ MANIFEST
159
+
160
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
161
+ [ 'path: [] t: [] value: {a => 1, /fancy/ => {c => 2, d => {[e] => 3}}}',
162
+ 'path: [a] t: [String] value: 1',
163
+ 'path: [/fancy/] t: [Regexp[/fancy/]] value: {c => 2, d => {[e] => 3}}',
164
+ 'path: [/fancy/, c] t: [Regexp[/fancy/], String] value: 2',
165
+ 'path: [/fancy/, d] t: [Regexp[/fancy/], String] value: {[e] => 3}',
166
+ 'path: [/fancy/, d, [e]] t: [Regexp[/fancy/], String, Array[String]] value: 3',
167
+ ''
168
+ ].join("\n"))
169
+ end
170
+ end
171
+
172
+ it 'errors when asked to operate on a String' do
173
+ expect {
174
+ compile_to_catalog(<<-MANIFEST)
175
+ "hello".tree_each() |$path, $v| {
176
+ notice "$v"
177
+ }
178
+ MANIFEST
179
+ }.to raise_error(/expects a value of type Iterator, Array, Hash, or Object/)
180
+ end
181
+
182
+ context 'produces' do
183
+ it 'the receiver when given a lambda' do
184
+ catalog = compile_to_catalog(<<-MANIFEST)
185
+ $a = [1, 3, 2]
186
+ $b = $a.tree_each |$path, $x| { "unwanted" }
187
+ file { "/file_${b[1]}":
188
+ ensure => present
189
+ }
190
+ MANIFEST
191
+
192
+ expect(catalog.resource(:file, "/file_3")['ensure']).to eq('present')
193
+ end
194
+
195
+ it 'an Iterator when not given a lambda' do
196
+ catalog = compile_to_catalog(<<-MANIFEST)
197
+ $a = [1, 3, 2]
198
+ $b = $a.tree_each
199
+ file { "/file_${$b =~ Iterator}":
200
+ ensure => present
201
+ }
202
+ MANIFEST
203
+
204
+ expect(catalog.resource(:file, "/file_true")['ensure']).to eq('present')
205
+ end
206
+ end
207
+
208
+ context 'recursively yields under the control of options such that' do
209
+ it 'both containers and leafs are included by default' do
210
+ catalog = compile_to_catalog(<<-MANIFEST)
211
+ $a = [1,[2,[3]]]
212
+ $msg = inline_epp(@(TEMPLATE))
213
+ <% $a.tree_each() |$path, $v| { -%>
214
+ path: <%= $path %> value: <%= $v %>
215
+ <% } -%>
216
+ | TEMPLATE
217
+ notify {'test': message => $msg}
218
+ MANIFEST
219
+
220
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
221
+ [ 'path: [] value: [1, [2, [3]]]',
222
+ 'path: [0] value: 1',
223
+ 'path: [1] value: [2, [3]]',
224
+ 'path: [1, 0] value: 2',
225
+ 'path: [1, 1] value: [3]',
226
+ 'path: [1, 1, 0] value: 3',
227
+ ''
228
+ ].join("\n"))
229
+ end
230
+
231
+ it 'containers are skipped when option include_containers=false is used' do
232
+ catalog = compile_to_catalog(<<-MANIFEST)
233
+ $a = [1,[2,[3]]]
234
+ $msg = inline_epp(@(TEMPLATE))
235
+ <% $a.tree_each({include_containers => false}) |$path, $v| { -%>
236
+ path: <%= $path %> value: <%= $v %>
237
+ <% } -%>
238
+ | TEMPLATE
239
+ notify {'test': message => $msg}
240
+ MANIFEST
241
+
242
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
243
+ [
244
+ 'path: [0] value: 1',
245
+ 'path: [1, 0] value: 2',
246
+ 'path: [1, 1, 0] value: 3',
247
+ ''
248
+ ].join("\n"))
249
+ end
250
+
251
+ it 'values are skipped when option include_values=false is used' do
252
+ catalog = compile_to_catalog(<<-MANIFEST)
253
+ $a = [1,[2,[3]]]
254
+ $msg = inline_epp(@(TEMPLATE))
255
+ <% $a.tree_each({include_values => false}) |$path, $v| { -%>
256
+ path: <%= $path %> value: <%= $v %>
257
+ <% } -%>
258
+ | TEMPLATE
259
+ notify {'test': message => $msg}
260
+ MANIFEST
261
+
262
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
263
+ [ 'path: [] value: [1, [2, [3]]]',
264
+ 'path: [1] value: [2, [3]]',
265
+ 'path: [1, 1] value: [3]',
266
+ ''
267
+ ].join("\n"))
268
+ end
269
+
270
+ it 'the root container is skipped when option include_root=false is used' do
271
+ catalog = compile_to_catalog(<<-MANIFEST)
272
+ $a = [1,[2,[3]]]
273
+ $msg = inline_epp(@(TEMPLATE))
274
+ <% $a.tree_each({include_root => false, include_values => false}) |$path, $v| { -%>
275
+ path: <%= $path %> value: <%= $v %>
276
+ <% } -%>
277
+ | TEMPLATE
278
+ notify {'test': message => $msg}
279
+ MANIFEST
280
+
281
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
282
+ [ 'path: [1] value: [2, [3]]',
283
+ 'path: [1, 1] value: [3]',
284
+ ''
285
+ ].join("\n"))
286
+ end
287
+
288
+ it 'containers must be included for root to be included' do
289
+ catalog = compile_to_catalog(<<-MANIFEST)
290
+ $a = [1,[2,[3]]]
291
+ $msg = inline_epp(@(TEMPLATE))
292
+ <% $a.tree_each({include_containers => false, include_root => true}) |$path, $v| { -%>
293
+ path: <%= $path %> value: <%= $v %>
294
+ <% } -%>
295
+ | TEMPLATE
296
+ notify {'test': message => $msg}
297
+ MANIFEST
298
+
299
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
300
+ [
301
+ 'path: [0] value: 1',
302
+ 'path: [1, 0] value: 2',
303
+ 'path: [1, 1, 0] value: 3',
304
+ ''
305
+ ].join("\n"))
306
+ end
307
+
308
+ it 'errors when asked to exclude both containers and values' do
309
+ expect {
310
+ compile_to_catalog(<<-MANIFEST)
311
+ [1,2,3].tree_each({include_containers => false, include_values => false}) |$path, $v| {
312
+ notice "$v"
313
+ }
314
+ MANIFEST
315
+ }.to raise_error(/Options 'include_containers' and 'include_values' cannot both be false/)
316
+ end
317
+
318
+ it 'tree nodes are yielded in depth first order if option order=depth_first' do
319
+ catalog = compile_to_catalog(<<-MANIFEST)
320
+ $a = [1,[2,[3], 4], 5]
321
+ $msg = inline_epp(@(TEMPLATE))
322
+ <% $a.tree_each({order => depth_first, include_containers => false}) |$path, $v| { -%>
323
+ path: <%= $path %> value: <%= $v %>
324
+ <% } -%>
325
+ | TEMPLATE
326
+ notify {'test': message => $msg}
327
+ MANIFEST
328
+
329
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
330
+ [
331
+ 'path: [0] value: 1',
332
+ 'path: [1, 0] value: 2',
333
+ 'path: [1, 1, 0] value: 3',
334
+ 'path: [1, 2] value: 4',
335
+ 'path: [2] value: 5',
336
+ ''
337
+ ].join("\n"))
338
+ end
339
+
340
+ it 'tree nodes are yielded in breadth first order if option order=breadth_first' do
341
+ catalog = compile_to_catalog(<<-MANIFEST)
342
+ $a = [1,[2,[3], 4], 5]
343
+ $msg = inline_epp(@(TEMPLATE))
344
+ <% $a.tree_each({order => breadth_first, include_containers => false}) |$path, $v| { -%>
345
+ path: <%= $path %> value: <%= $v %>
346
+ <% } -%>
347
+ | TEMPLATE
348
+ notify {'test': message => $msg}
349
+ MANIFEST
350
+
351
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
352
+ [
353
+ 'path: [0] value: 1',
354
+ 'path: [2] value: 5',
355
+ 'path: [1, 0] value: 2',
356
+ 'path: [1, 2] value: 4',
357
+ 'path: [1, 1, 0] value: 3',
358
+ ''
359
+ ].join("\n"))
360
+ end
361
+
362
+ it 'attributes of an Object of "reference" kind are not yielded by default' do
363
+ catalog = compile_to_catalog(<<-MANIFEST)
364
+ type Person = Object[{attributes => {
365
+ name => String,
366
+ father => Optional[Person],
367
+ mother => { kind => reference, type => Optional[Person] }
368
+ }}]
369
+ $adam = Person({name => 'Adam'})
370
+ $eve = Person({name => 'Eve'})
371
+ $cain = Person({name => 'Cain', mother => $eve, father => $adam})
372
+ $awan = Person({name => 'Awan', mother => $eve, father => $adam})
373
+ $enoch = Person({name => 'Enoch', mother => $awan, father => $cain})
374
+
375
+ $msg = inline_epp(@(TEMPLATE))
376
+ <% $enoch.tree_each({include_containers=>false }) |$path, $v| { unless $v =~ Undef {-%>
377
+ path: <%= $path %> value: <%= $v %>
378
+ <% }} -%>
379
+ | TEMPLATE
380
+ notify {'by_default': message => $msg}
381
+
382
+ $msg2 = inline_epp(@(TEMPLATE))
383
+ <% $enoch.tree_each({include_containers=>false, include_refs => false}) |$path, $v| { unless $v =~ Undef {-%>
384
+ path: <%= $path %> value: <%= $v %>
385
+ <% }} -%>
386
+ | TEMPLATE
387
+ notify {'when_false': message => $msg2}
388
+
389
+ MANIFEST
390
+
391
+ expected_refs_excluded_result = [
392
+ 'path: [name] value: Enoch',
393
+ 'path: [father, name] value: Cain',
394
+ 'path: [father, father, name] value: Adam',
395
+ ''
396
+ ].join("\n")
397
+
398
+ expect(catalog.resource(:notify, 'by_default')['message']).to eq(expected_refs_excluded_result)
399
+ expect(catalog.resource(:notify, 'when_false')['message']).to eq(expected_refs_excluded_result)
400
+ end
401
+ end
402
+
403
+ context 'can be chained' do
404
+ it 'with reverse_each()' do
405
+ catalog = compile_to_catalog(<<-MANIFEST)
406
+ $a = [1,[2,[3]]]
407
+ $msg = inline_epp(@(TEMPLATE))
408
+ <% $a.tree_each({include_containers => false}).reverse_each |$v| { -%>
409
+ path: <%= $v[0] %> value: <%= $v[1] %>
410
+ <% } -%>
411
+ | TEMPLATE
412
+ notify {'test': message => $msg}
413
+ MANIFEST
414
+
415
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
416
+ [
417
+ 'path: [1, 1, 0] value: 3',
418
+ 'path: [1, 0] value: 2',
419
+ 'path: [0] value: 1',
420
+ ''
421
+ ].join("\n"))
422
+ end
423
+
424
+ it 'with step()' do
425
+ catalog = compile_to_catalog(<<-MANIFEST)
426
+ $a = [1,[2,[3,[4,[5]]]]]
427
+ $msg = inline_epp(@(TEMPLATE))
428
+ <% $a.tree_each({include_containers => false}).step(2) |$v| { -%>
429
+ path: <%= $v[0] %> value: <%= $v[1] %>
430
+ <% } -%>
431
+ | TEMPLATE
432
+ notify {'test': message => $msg}
433
+ MANIFEST
434
+
435
+ expect(catalog.resource(:notify, 'test')['message']).to eq(
436
+ [
437
+ 'path: [0] value: 1',
438
+ 'path: [1, 1, 0] value: 3',
439
+ 'path: [1, 1, 1, 1, 0] value: 5',
440
+ ''
441
+ ].join("\n"))
442
+ end
443
+ end
444
+ end
@@ -440,6 +440,35 @@ describe Puppet::Module do
440
440
  end
441
441
  end
442
442
 
443
+
444
+ describe "initialize_i18n" do
445
+
446
+ let(:modpath) { tmpdir('modpath') }
447
+ let(:modname) { 'puppetlabs-i18n'}
448
+ let(:modroot) { "#{modpath}/#{modname}/" }
449
+ let(:config_path) { "#{modroot}/locales/config.yaml" }
450
+ let(:mod_obj) { PuppetSpec::Modules.create( modname, modpath, :metadata => { :dependencies => [] }, :env => env ) }
451
+
452
+ it "is expected to initialize an un-initialized module" do
453
+ expect(GettextSetup.translation_repositories.has_key? modname).to be false
454
+
455
+ FileUtils.mkdir_p("#{mod_obj.path}/locales")
456
+ config = {
457
+ "gettext" => {
458
+ "project_name" => modname
459
+ }
460
+ }
461
+ File.open(config_path, 'w') { |file| file.write(config.to_yaml) }
462
+
463
+ mod_obj.initialize_i18n
464
+
465
+ expect(GettextSetup.translation_repositories.has_key? modname).to be true
466
+ end
467
+ it "is expected return nil if module is intiailized" do
468
+ expect(mod_obj.initialize_i18n).to be nil
469
+ end
470
+ end
471
+
443
472
  describe "when managing supported platforms" do
444
473
  it "should support specifying a supported platform" do
445
474
  mod.supports "solaris"