puppet 4.7.1-universal-darwin → 4.8.0-universal-darwin

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 (276) hide show
  1. data/Gemfile +0 -3
  2. data/MAINTAINERS +76 -0
  3. data/README.md +0 -6
  4. data/Rakefile +2 -2
  5. data/lib/puppet/agent.rb +3 -3
  6. data/lib/puppet/application/apply.rb +1 -1
  7. data/lib/puppet/configurer.rb +2 -2
  8. data/lib/puppet/data_providers.rb +1 -0
  9. data/lib/puppet/data_providers/data_adapter.rb +1 -0
  10. data/lib/puppet/data_providers/data_function_support.rb +1 -0
  11. data/lib/puppet/data_providers/function_env_data_provider.rb +1 -0
  12. data/lib/puppet/data_providers/function_module_data_provider.rb +1 -0
  13. data/lib/puppet/data_providers/hiera_config.rb +1 -0
  14. data/lib/puppet/data_providers/hiera_env_data_provider.rb +1 -0
  15. data/lib/puppet/data_providers/hiera_interpolate.rb +1 -0
  16. data/lib/puppet/data_providers/hiera_module_data_provider.rb +1 -0
  17. data/lib/puppet/data_providers/hiera_support.rb +1 -2
  18. data/lib/puppet/data_providers/json_data_provider_factory.rb +2 -0
  19. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -0
  20. data/lib/puppet/defaults.rb +20 -1
  21. data/lib/puppet/environments.rb +5 -2
  22. data/lib/puppet/face/catalog.rb +1 -1
  23. data/lib/puppet/face/epp.rb +57 -11
  24. data/lib/puppet/face/module/install.rb +6 -6
  25. data/lib/puppet/functions.rb +23 -24
  26. data/lib/puppet/functions/alert.rb +14 -0
  27. data/lib/puppet/functions/binary_file.rb +25 -0
  28. data/lib/puppet/functions/break.rb +22 -0
  29. data/lib/puppet/functions/contain.rb +33 -0
  30. data/lib/puppet/functions/crit.rb +14 -0
  31. data/lib/puppet/functions/debug.rb +14 -0
  32. data/lib/puppet/functions/emerg.rb +14 -0
  33. data/lib/puppet/functions/epp.rb +1 -1
  34. data/lib/puppet/functions/err.rb +14 -0
  35. data/lib/puppet/functions/find_file.rb +31 -0
  36. data/lib/puppet/functions/include.rb +21 -0
  37. data/lib/puppet/functions/info.rb +14 -0
  38. data/lib/puppet/functions/new.rb +1 -1
  39. data/lib/puppet/functions/next.rb +23 -0
  40. data/lib/puppet/functions/notice.rb +14 -0
  41. data/lib/puppet/functions/regsubst.rb +12 -16
  42. data/lib/puppet/functions/require.rb +37 -0
  43. data/lib/puppet/functions/return.rb +22 -0
  44. data/lib/puppet/functions/strftime.rb +35 -0
  45. data/lib/puppet/functions/warning.rb +14 -0
  46. data/lib/puppet/generate/models/type/type.rb +4 -0
  47. data/lib/puppet/generate/templates/type/pcore.erb +2 -1
  48. data/lib/puppet/indirector/face.rb +6 -1
  49. data/lib/puppet/network/http/error.rb +2 -2
  50. data/lib/puppet/network/http/handler.rb +2 -2
  51. data/lib/puppet/node/environment.rb +11 -0
  52. data/lib/puppet/parser/ast.rb +5 -0
  53. data/lib/puppet/parser/ast/pops_bridge.rb +17 -4
  54. data/lib/puppet/parser/compiler.rb +29 -1
  55. data/lib/puppet/parser/functions.rb +6 -0
  56. data/lib/puppet/parser/functions/assert_type.rb +1 -1
  57. data/lib/puppet/parser/functions/binary_file.rb +24 -0
  58. data/lib/puppet/parser/functions/break.rb +39 -0
  59. data/lib/puppet/parser/functions/contain.rb +7 -15
  60. data/lib/puppet/parser/functions/defined.rb +2 -2
  61. data/lib/puppet/parser/functions/dig.rb +1 -1
  62. data/lib/puppet/parser/functions/each.rb +1 -1
  63. data/lib/puppet/parser/functions/epp.rb +2 -2
  64. data/lib/puppet/parser/functions/filter.rb +1 -1
  65. data/lib/puppet/parser/functions/find_file.rb +28 -0
  66. data/lib/puppet/parser/functions/hiera.rb +4 -4
  67. data/lib/puppet/parser/functions/hiera_array.rb +1 -1
  68. data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
  69. data/lib/puppet/parser/functions/hiera_include.rb +1 -1
  70. data/lib/puppet/parser/functions/include.rb +4 -8
  71. data/lib/puppet/parser/functions/inline_epp.rb +1 -1
  72. data/lib/puppet/parser/functions/lest.rb +1 -1
  73. data/lib/puppet/parser/functions/lookup.rb +4 -2
  74. data/lib/puppet/parser/functions/map.rb +1 -1
  75. data/lib/puppet/parser/functions/match.rb +1 -1
  76. data/lib/puppet/parser/functions/new.rb +414 -18
  77. data/lib/puppet/parser/functions/next.rb +38 -0
  78. data/lib/puppet/parser/functions/reduce.rb +1 -1
  79. data/lib/puppet/parser/functions/regsubst.rb +4 -2
  80. data/lib/puppet/parser/functions/require.rb +4 -27
  81. data/lib/puppet/parser/functions/return.rb +71 -0
  82. data/lib/puppet/parser/functions/reverse_each.rb +1 -1
  83. data/lib/puppet/parser/functions/scanf.rb +13 -8
  84. data/lib/puppet/parser/functions/slice.rb +1 -1
  85. data/lib/puppet/parser/functions/split.rb +1 -1
  86. data/lib/puppet/parser/functions/step.rb +1 -1
  87. data/lib/puppet/parser/functions/strftime.rb +185 -0
  88. data/lib/puppet/parser/functions/then.rb +1 -1
  89. data/lib/puppet/parser/functions/type.rb +1 -1
  90. data/lib/puppet/parser/functions/with.rb +3 -3
  91. data/lib/puppet/parser/resource.rb +8 -5
  92. data/lib/puppet/parser/scope.rb +1 -1
  93. data/lib/puppet/plugins/configuration.rb +8 -0
  94. data/lib/puppet/plugins/data_providers.rb +1 -0
  95. data/lib/puppet/plugins/data_providers/data_provider.rb +7 -28
  96. data/lib/puppet/plugins/data_providers/registry.rb +1 -0
  97. data/lib/puppet/pops.rb +4 -0
  98. data/lib/puppet/pops/evaluator/access_operator.rb +36 -5
  99. data/lib/puppet/pops/evaluator/closure.rb +81 -12
  100. data/lib/puppet/pops/evaluator/compare_operator.rb +24 -1
  101. data/lib/puppet/pops/evaluator/evaluator_impl.rb +29 -5
  102. data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +1 -1
  103. data/lib/puppet/pops/evaluator/runtime3_converter.rb +53 -62
  104. data/lib/puppet/pops/evaluator/runtime3_support.rb +15 -6
  105. data/lib/puppet/pops/functions/dispatch.rb +9 -2
  106. data/lib/puppet/pops/functions/dispatcher.rb +3 -1
  107. data/lib/puppet/pops/functions/function.rb +19 -2
  108. data/lib/puppet/pops/issues.rb +9 -0
  109. data/lib/puppet/pops/label_provider.rb +2 -2
  110. data/lib/puppet/pops/loader/loader.rb +17 -0
  111. data/lib/puppet/pops/loader/static_loader.rb +0 -41
  112. data/lib/puppet/pops/lookup.rb +12 -0
  113. data/lib/puppet/pops/lookup/context.rb +86 -0
  114. data/lib/puppet/pops/lookup/explainer.rb +46 -6
  115. data/lib/puppet/pops/lookup/invocation.rb +19 -0
  116. data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
  117. data/lib/puppet/pops/model/factory.rb +20 -8
  118. data/lib/puppet/pops/model/model_label_provider.rb +3 -0
  119. data/lib/puppet/pops/model/model_meta.rb +2 -0
  120. data/lib/puppet/pops/model/model_tree_dumper.rb +14 -0
  121. data/lib/puppet/pops/parser/egrammar.ra +11 -6
  122. data/lib/puppet/pops/parser/eparser.rb +1112 -1086
  123. data/lib/puppet/pops/parser/heredoc_support.rb +1 -2
  124. data/lib/puppet/pops/pcore.rb +1 -0
  125. data/lib/puppet/pops/puppet_stack.rb +3 -3
  126. data/lib/puppet/pops/resource/param.rb +5 -1
  127. data/lib/puppet/pops/resource/resource_type_impl.rb +8 -4
  128. data/lib/puppet/pops/resource/resource_type_set.pcore +1 -0
  129. data/lib/puppet/pops/serialization/abstract_reader.rb +19 -2
  130. data/lib/puppet/pops/serialization/abstract_writer.rb +16 -3
  131. data/lib/puppet/pops/serialization/deserializer.rb +5 -1
  132. data/lib/puppet/pops/serialization/extension.rb +2 -0
  133. data/lib/puppet/pops/serialization/json.rb +76 -26
  134. data/lib/puppet/pops/serialization/serializer.rb +5 -1
  135. data/lib/puppet/pops/serialization/time_factory.rb +2 -1
  136. data/lib/puppet/pops/time/timespan.rb +718 -0
  137. data/lib/puppet/pops/time/timestamp.rb +148 -0
  138. data/lib/puppet/pops/types/p_binary_type.rb +220 -0
  139. data/lib/puppet/pops/types/p_object_type.rb +12 -6
  140. data/lib/puppet/pops/types/p_sensitive_type.rb +5 -1
  141. data/lib/puppet/pops/types/p_timespan_type.rb +141 -0
  142. data/lib/puppet/pops/types/p_timestamp_type.rb +69 -0
  143. data/lib/puppet/pops/types/string_converter.rb +62 -0
  144. data/lib/puppet/pops/types/type_asserter.rb +1 -1
  145. data/lib/puppet/pops/types/type_calculator.rb +17 -3
  146. data/lib/puppet/pops/types/type_factory.rb +35 -1
  147. data/lib/puppet/pops/types/type_formatter.rb +64 -11
  148. data/lib/puppet/pops/types/type_mismatch_describer.rb +110 -61
  149. data/lib/puppet/pops/types/type_parser.rb +18 -4
  150. data/lib/puppet/pops/types/types.rb +98 -63
  151. data/lib/puppet/pops/validation.rb +9 -1
  152. data/lib/puppet/pops/validation/checker4_0.rb +7 -0
  153. data/lib/puppet/property.rb +1 -1
  154. data/lib/puppet/provider.rb +3 -6
  155. data/lib/puppet/provider/mcx/mcxcontent.rb +1 -1
  156. data/lib/puppet/provider/mount/parsed.rb +18 -4
  157. data/lib/puppet/provider/nameservice/directoryservice.rb +15 -7
  158. data/lib/puppet/provider/package/gem.rb +6 -1
  159. data/lib/puppet/provider/package/pip.rb +0 -1
  160. data/lib/puppet/provider/package/pkg.rb +5 -1
  161. data/lib/puppet/provider/package/pkgng.rb +1 -1
  162. data/lib/puppet/provider/package/yum.rb +10 -0
  163. data/lib/puppet/provider/service/launchd.rb +1 -0
  164. data/lib/puppet/provider/user/directoryservice.rb +6 -6
  165. data/lib/puppet/provider/yumrepo/inifile.rb +1 -1
  166. data/lib/puppet/provider/zpool/zpool.rb +1 -1
  167. data/lib/puppet/resource.rb +54 -12
  168. data/lib/puppet/resource/capability_finder.rb +15 -9
  169. data/lib/puppet/resource/catalog.rb +25 -6
  170. data/lib/puppet/resource/type.rb +3 -1
  171. data/lib/puppet/settings.rb +1 -1
  172. data/lib/puppet/settings/environment_conf.rb +12 -4
  173. data/lib/puppet/syntax_checkers/base64.rb +41 -0
  174. data/lib/puppet/syntax_checkers/json.rb +0 -2
  175. data/lib/puppet/transaction.rb +6 -0
  176. data/lib/puppet/transaction/additional_resource_generator.rb +5 -0
  177. data/lib/puppet/transaction/report.rb +7 -2
  178. data/lib/puppet/type.rb +2 -1
  179. data/lib/puppet/type/file/checksum.rb +1 -0
  180. data/lib/puppet/type/file/content.rb +4 -4
  181. data/lib/puppet/type/mount.rb +44 -0
  182. data/lib/puppet/type/ssh_authorized_key.rb +1 -1
  183. data/lib/puppet/type/tidy.rb +3 -0
  184. data/lib/puppet/type/user.rb +12 -6
  185. data/lib/puppet/util/log.rb +25 -0
  186. data/lib/puppet/util/plist.rb +8 -3
  187. data/lib/puppet/version.rb +1 -1
  188. data/lib/puppet_x.rb +7 -1
  189. data/spec/integration/application/apply_spec.rb +118 -0
  190. data/spec/integration/parser/compiler_spec.rb +28 -0
  191. data/spec/integration/parser/pcore_resource_spec.rb +40 -3
  192. data/spec/integration/provider/mount_spec.rb +2 -1
  193. data/spec/integration/util/windows/principal_spec.rb +2 -2
  194. data/spec/integration/util/windows/registry_spec.rb +4 -4
  195. data/spec/lib/puppet_spec/compiler.rb +5 -1
  196. data/spec/lib/puppet_spec/unindent.rb +5 -0
  197. data/spec/shared_contexts/types_setup.rb +6 -0
  198. data/spec/shared_examples/rhel_package_provider.rb +16 -0
  199. data/spec/spec_helper.rb +1 -0
  200. data/spec/unit/agent_spec.rb +11 -0
  201. data/spec/unit/application/lookup_spec.rb +94 -3
  202. data/spec/unit/capability_spec.rb +22 -0
  203. data/spec/unit/configurer_spec.rb +8 -0
  204. data/spec/unit/face/epp_face_spec.rb +22 -3
  205. data/spec/unit/functions/assert_type_spec.rb +3 -3
  206. data/spec/unit/functions/binary_file_spec.rb +46 -0
  207. data/spec/unit/functions/break_spec.rb +89 -0
  208. data/spec/unit/{parser/functions → functions}/contain_spec.rb +68 -3
  209. data/spec/unit/functions/find_file_spec.rb +69 -0
  210. data/spec/unit/functions/include_spec.rb +175 -0
  211. data/spec/unit/functions/logging_spec.rb +54 -0
  212. data/spec/unit/functions/lookup_spec.rb +3 -3
  213. data/spec/unit/functions/new_spec.rb +105 -5
  214. data/spec/unit/functions/next_spec.rb +93 -0
  215. data/spec/unit/functions/require_spec.rb +83 -0
  216. data/spec/unit/functions/return_spec.rb +105 -0
  217. data/spec/unit/{parser/functions → functions}/shared.rb +14 -11
  218. data/spec/unit/functions/strftime_spec.rb +152 -0
  219. data/spec/unit/functions4_spec.rb +22 -0
  220. data/spec/unit/indirector/face_spec.rb +10 -2
  221. data/spec/unit/network/http/error_spec.rb +1 -2
  222. data/spec/unit/network/http/handler_spec.rb +6 -5
  223. data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
  224. data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
  225. data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
  226. data/spec/unit/parser/functions/hiera_spec.rb +1 -1
  227. data/spec/unit/parser/functions/lookup_spec.rb +1 -1
  228. data/spec/unit/parser/functions/regsubst_spec.rb +1 -1
  229. data/spec/unit/parser/functions/split_spec.rb +1 -1
  230. data/spec/unit/pops/evaluator/access_ops_spec.rb +81 -1
  231. data/spec/unit/pops/evaluator/arithmetic_ops_spec.rb +170 -0
  232. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +29 -4
  233. data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +112 -4
  234. data/spec/unit/pops/loaders/dependency_loader_spec.rb +12 -0
  235. data/spec/unit/pops/loaders/static_loader_spec.rb +0 -26
  236. data/spec/unit/pops/lookup/context_spec.rb +149 -0
  237. data/spec/unit/pops/parser/parse_functions_spec.rb +19 -0
  238. data/spec/unit/pops/parser/parse_lambda_spec.rb +19 -0
  239. data/spec/unit/pops/puppet_stack_spec.rb +1 -1
  240. data/spec/unit/pops/resource/resource_type_impl_spec.rb +74 -0
  241. data/spec/unit/pops/serialization/packer_spec.rb +34 -14
  242. data/spec/unit/pops/serialization/serialization_spec.rb +67 -5
  243. data/spec/unit/pops/time/timespan_spec.rb +121 -0
  244. data/spec/unit/pops/types/p_binary_type_spec.rb +243 -0
  245. data/spec/unit/pops/types/p_object_type_spec.rb +7 -7
  246. data/spec/unit/pops/types/p_sensitive_type_spec.rb +1 -1
  247. data/spec/unit/pops/types/p_timespan_type_spec.rb +273 -0
  248. data/spec/unit/pops/types/p_timestamp_type_spec.rb +311 -0
  249. data/spec/unit/pops/types/p_type_set_type_spec.rb +13 -13
  250. data/spec/unit/pops/types/ruby_generator_spec.rb +12 -12
  251. data/spec/unit/pops/types/string_converter_spec.rb +89 -0
  252. data/spec/unit/pops/types/type_asserter_spec.rb +3 -3
  253. data/spec/unit/pops/types/type_calculator_spec.rb +113 -5
  254. data/spec/unit/pops/types/type_formatter_spec.rb +40 -0
  255. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +49 -38
  256. data/spec/unit/pops/types/type_parser_spec.rb +87 -4
  257. data/spec/unit/pops/types/types_spec.rb +1 -1
  258. data/spec/unit/pops/validator/validator_spec.rb +23 -0
  259. data/spec/unit/provider/mount/parsed_spec.rb +47 -29
  260. data/spec/unit/provider/package/pkg_spec.rb +109 -99
  261. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -0
  262. data/spec/unit/provider/user/aix_spec.rb +1 -1
  263. data/spec/unit/provider/user/directoryservice_spec.rb +101 -30
  264. data/spec/unit/resource/capability_finder_spec.rb +29 -7
  265. data/spec/unit/resource/catalog_spec.rb +127 -0
  266. data/spec/unit/ssl/certificate_request_spec.rb +1 -1
  267. data/spec/unit/transaction/additional_resource_generator_spec.rb +30 -0
  268. data/spec/unit/transaction/persistence_spec.rb +1 -6
  269. data/spec/unit/transaction/report_spec.rb +23 -0
  270. data/spec/unit/transaction_spec.rb +38 -0
  271. data/spec/unit/type/mount_spec.rb +5 -0
  272. data/spec/unit/util/plist_spec.rb +14 -2
  273. metadata +71 -12
  274. data/spec/integration/parser/functions/require_spec.rb +0 -43
  275. data/spec/unit/parser/functions/include_spec.rb +0 -55
  276. data/spec/unit/parser/functions/require_spec.rb +0 -68
@@ -391,4 +391,26 @@ test { one: hostname => "ahost", export => Cap[two] }
391
391
  end
392
392
  end
393
393
  end
394
+
395
+ context 'and aliased resources' do
396
+ let(:drive) { Puppet.features.microsoft_windows? ? 'C:' : '' }
397
+ let(:code) { <<-PUPPET }
398
+ $dir='#{drive}/tmp/test'
399
+ $same_dir='#{drive}/tmp/test/'
400
+
401
+ file {$dir:
402
+ ensure => directory
403
+ }
404
+
405
+ if !defined(File["${same_dir}"]) {
406
+ file { $same_dir:
407
+ ensure => directory
408
+ }
409
+ }
410
+ PUPPET
411
+
412
+ it 'fails if a resource is defined and then redefined using name that results in the same alias' do
413
+ expect { compile_to_ral(code) }.to raise_error(/resource \["File", "#{drive}\/tmp\/test"\] already declared/)
414
+ end
415
+ end
394
416
  end
@@ -424,6 +424,14 @@ describe Puppet::Configurer do
424
424
  end
425
425
  end
426
426
 
427
+ describe "when initialized with a transaction_uuid" do
428
+ it "stores it" do
429
+ SecureRandom.expects(:uuid).never
430
+ configurer = Puppet::Configurer.new(Puppet::Configurer::DownloaderFactory.new, 'foo')
431
+ expect(configurer.instance_variable_get(:@transaction_uuid) == 'foo')
432
+ end
433
+ end
434
+
427
435
  describe "when sending a report" do
428
436
  include PuppetSpec::Files
429
437
 
@@ -102,9 +102,6 @@ describe Puppet::Face[:epp, :current] do
102
102
  end
103
103
  end
104
104
 
105
- context "render" do
106
-
107
- end
108
105
 
109
106
  context "dump" do
110
107
  it "prints the AST of a template given with the -e option" do
@@ -232,6 +229,28 @@ describe Puppet::Face[:epp, :current] do
232
229
  ).to eq("goodbye mr Y")
233
230
  end
234
231
 
232
+ it "sets $facts" do
233
+ expect(eppface.render({ :e => 'facts is hash: <%= $facts =~ Hash %>' })).to eql("facts is hash: true")
234
+ end
235
+
236
+ it "sets $trusted" do
237
+ expect(eppface.render({ :e => 'trusted is hash: <%= $trusted =~ Hash %>' })).to eql("trusted is hash: true")
238
+ end
239
+
240
+ it "facts can be added to" do
241
+ expect(eppface.render({
242
+ :facts => {'the_crux' => 'biscuit'},
243
+ :e => '<%= $facts[the_crux] %>',
244
+ })).to eql("biscuit")
245
+ end
246
+
247
+ it "facts can be overridden" do
248
+ expect(eppface.render({
249
+ :facts => {'operatingsystem' => 'Merwin'},
250
+ :e => '<%= $facts[operatingsystem] %>',
251
+ })).to eql("Merwin")
252
+ end
253
+
235
254
  context "in an environment with templates" do
236
255
  let(:dir) do
237
256
  dir_containing('environments', { 'production' => { 'modules' => {
@@ -22,7 +22,7 @@ describe 'the assert_type function' do
22
22
  it 'asserts non compliant type by raising an error' do
23
23
  expect do
24
24
  func.call({}, type(Integer), 'hello world')
25
- end.to raise_error(Puppet::Pops::Types::TypeAssertionError, /expected an Integer value, got String/)
25
+ end.to raise_error(Puppet::Pops::Types::TypeAssertionError, /expects an Integer value, got String/)
26
26
  end
27
27
 
28
28
  it 'checks that first argument is a type' do
@@ -84,7 +84,7 @@ describe 'the assert_type function' do
84
84
  assert_type(UnprivilegedPort, 345)
85
85
  notice('ok')
86
86
  CODE
87
- expect { eval_and_collect_notices(code) }.to raise_error(Puppet::Error, /expected an UnprivilegedPort = Integer\[1024, 65537\] value, got Integer\[345, 345\]/)
87
+ expect { eval_and_collect_notices(code) }.to raise_error(Puppet::Error, /expects an UnprivilegedPort = Integer\[1024, 65537\] value, got Integer\[345, 345\]/)
88
88
  end
89
89
 
90
90
  it 'will use infer_set to report detailed information about complex mismatches' do
@@ -92,6 +92,6 @@ describe 'the assert_type function' do
92
92
  assert_type(Struct[{a=>Integer,b=>Boolean}], {a=>hej,x=>s})
93
93
  CODE
94
94
  expect { eval_and_collect_notices(code) }.to raise_error(Puppet::Error,
95
- /entry 'a' expected an Integer value, got String.*expected a value for key 'b'.*unrecognized key 'x'/m)
95
+ /entry 'a' expects an Integer value, got String.*expects a value for key 'b'.*unrecognized key 'x'/m)
96
96
  end
97
97
  end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'puppet_spec/compiler'
3
+ require 'matchers/resource'
4
+ require 'puppet_spec/files'
5
+
6
+ describe 'the binary_file function' do
7
+ include PuppetSpec::Compiler
8
+ include Matchers::Resource
9
+ include PuppetSpec::Files
10
+
11
+ def with_file_content(content)
12
+ path = tmpfile('find-file-function')
13
+ file = File.new(path, 'wb')
14
+ file.sync = true
15
+ file.print content
16
+ yield path
17
+ end
18
+
19
+ it 'reads an existing absolute file' do
20
+ with_file_content('one') do |one|
21
+ # Note that Binary to String produced Base64 encoded version of 'one' which is 'b23l'
22
+ expect(compile_to_catalog("notify { String(binary_file('#{one}')):}")).to have_resource("Notify[b25l]")
23
+ end
24
+ end
25
+
26
+ it 'errors on non existing files' do
27
+ expect do
28
+ with_file_content('one') do |one|
29
+ compile_to_catalog("notify { binary_file('#{one}/nope'):}")
30
+ end
31
+ end.to raise_error(/The given file '.*' does not exist/)
32
+ end
33
+
34
+ it 'reads an existing file in a module' do
35
+ with_file_content('binary_data') do |name|
36
+ mod = mock 'module'
37
+ mod.stubs(:file).with('myfile').returns(name)
38
+ Puppet[:code] = "notify { String(binary_file('mymod/myfile')):}"
39
+ node = Puppet::Node.new('localhost')
40
+ compiler = Puppet::Parser::Compiler.new(node)
41
+ compiler.environment.stubs(:module).with('mymod').returns(mod)
42
+ # Note that the Binary to string produces Base64 encoded version of 'binary_data' which is 'YmluYXJ5X2RhdGE='
43
+ expect(compiler.compile().filter { |r| r.virtual? }).to have_resource("Notify[YmluYXJ5X2RhdGE=]")
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ require 'puppet_spec/compiler'
4
+ require 'matchers/resource'
5
+
6
+ describe 'the break function' do
7
+ include PuppetSpec::Compiler
8
+ include Matchers::Resource
9
+
10
+ context do
11
+ it 'breaks iteration as if at end of input' do
12
+ expect(compile_to_catalog(<<-CODE)).to have_resource('Notify[[1, 2]]')
13
+ function please_break() {
14
+ [1,2,3].map |$x| { if $x == 3 { break() } $x }
15
+ }
16
+ notify { String(please_break()): }
17
+ CODE
18
+ end
19
+ end
20
+
21
+ it 'does not provide early exit from a class' do
22
+ # A break would semantically mean that the class should not be included - as if the
23
+ # iteration over class names should stop. That is too magic and should
24
+ # be done differently by the user.
25
+ #
26
+ expect do
27
+ compile_to_catalog(<<-CODE)
28
+ class does_break {
29
+ notice 'a'
30
+ if 1 == 1 { break() } # avoid making next line statically unreachable
31
+ notice 'b'
32
+ }
33
+ include(does_break)
34
+ CODE
35
+ end.to raise_error(/break\(\) from context where this is illegal at unknown:3 on node.*/)
36
+ end
37
+
38
+ it 'does not provide early exit from a define' do
39
+ # A break would semantically mean that the resource should not be created - as if the
40
+ # iteration over resource titles should stop. That is too magic and should
41
+ # be done differently by the user.
42
+ #
43
+ expect do
44
+ compile_to_catalog(<<-CODE)
45
+ define does_break {
46
+ notice 'a'
47
+ if 1 == 1 { break() } # avoid making next line statically unreachable
48
+ notice 'b'
49
+ }
50
+ does_break { 'no_you_cannot': }
51
+ CODE
52
+ end.to raise_error(/break\(\) from context where this is illegal at unknown:3 on node.*/)
53
+ end
54
+
55
+ it 'can be called when nested in a function to make that function behave as a break' do
56
+ # This allows functions like break_when(...) to be implemented by calling break() conditionally
57
+ #
58
+ expect(eval_and_collect_notices(<<-CODE)).to eql(['[100]'])
59
+ function nested_break($x) {
60
+ if $x == 2 { break() } else { $x * 100 }
61
+ }
62
+ function example() {
63
+ [1,2,3].map |$x| { nested_break($x) }
64
+ }
65
+ notice example()
66
+ CODE
67
+ end
68
+
69
+ it 'can not be called nested from top scope' do
70
+ expect do
71
+ compile_to_catalog(<<-CODE)
72
+ # line 1
73
+ # line 2
74
+ $result = with(1) |$x| { with($x) |$x| {break() }}
75
+ notice $result
76
+ CODE
77
+ end.to raise_error(/break\(\) from context where this is illegal at unknown:3 on node.*/)
78
+ end
79
+
80
+ it 'can not be called from top scope' do
81
+ expect do
82
+ compile_to_catalog(<<-CODE)
83
+ # line 1
84
+ # line 2
85
+ break()
86
+ CODE
87
+ end.to raise_error(/break\(\) from context where this is illegal at unknown:3 on node.*/)
88
+ end
89
+ end
@@ -5,7 +5,7 @@ require 'puppet/parser/functions'
5
5
  require 'matchers/containment_matchers'
6
6
  require 'matchers/resource'
7
7
  require 'matchers/include_in_order'
8
- require 'unit/parser/functions/shared'
8
+ require 'unit/functions/shared'
9
9
 
10
10
 
11
11
  describe 'The "contain" function' do
@@ -227,7 +227,72 @@ describe 'The "contain" function' do
227
227
  end
228
228
  end
229
229
 
230
- it_should_behave_like 'all functions transforming relative to absolute names', :function_contain
231
- it_should_behave_like 'an inclusion function, regardless of the type of class reference,', :contain
230
+ it 'produces an array with a single class references given a single argument' do
231
+ catalog = compile_to_catalog(<<-MANIFEST)
232
+ class a {
233
+ notify { "a": }
234
+ }
235
+
236
+ class container {
237
+ $x = contain(a)
238
+ Array[Type[Class], 1, 1].assert_type($x)
239
+ notify { 'feedback': message => "$x" }
240
+ }
241
+
242
+ include container
243
+ MANIFEST
244
+
245
+ feedback = catalog.resource("Notify", "feedback")
246
+ expect(feedback[:message]).to eql("[Class[a]]")
247
+ end
248
+
249
+ it 'produces an array with class references given multiple arguments' do
250
+ catalog = compile_to_catalog(<<-MANIFEST)
251
+ class a {
252
+ notify { "a": }
253
+ }
254
+
255
+ class b {
256
+ notify { "b": }
257
+ }
258
+
259
+ class container {
260
+ $x = contain(a, b)
261
+ Array[Type[Class], 2, 2].assert_type($x)
262
+ notify { 'feedback': message => "$x" }
263
+ }
232
264
 
265
+ include container
266
+ MANIFEST
267
+
268
+ feedback = catalog.resource("Notify", "feedback")
269
+ expect(feedback[:message]).to eql("[Class[a], Class[b]]")
270
+ end
271
+
272
+ it 'allows the result to be used in a relationship operation' do
273
+ catalog = compile_to_catalog(<<-MANIFEST)
274
+ class a {
275
+ notify { "a": }
276
+ }
277
+
278
+ class b {
279
+ notify { "b": }
280
+ }
281
+
282
+ notify { 'c': }
283
+
284
+ class container {
285
+ contain(a, b) -> Notify[c]
286
+ }
287
+
288
+ include container
289
+ MANIFEST
290
+
291
+ # Assert relationships are formed
292
+ expect(catalog.resource("Class", "a")[:before][0]).to eql('Notify[c]')
293
+ expect(catalog.resource("Class", "b")[:before][0]).to eql('Notify[c]')
294
+ end
295
+
296
+ it_should_behave_like 'all functions transforming relative to absolute names', :contain
297
+ it_should_behave_like 'an inclusion function, regardless of the type of class reference,', :contain
233
298
  end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+ require 'puppet_spec/compiler'
3
+ require 'matchers/resource'
4
+ require 'puppet_spec/files'
5
+
6
+ describe 'the find_file function' do
7
+ include PuppetSpec::Compiler
8
+ include Matchers::Resource
9
+ include PuppetSpec::Files
10
+
11
+ def with_file_content(content)
12
+ path = tmpfile('find-file-function')
13
+ file = File.new(path, 'wb')
14
+ file.sync = true
15
+ file.print content
16
+ yield path
17
+ end
18
+
19
+ it 'finds an existing absolute file when given arguments individually' do
20
+ with_file_content('one') do |one|
21
+ with_file_content('two') do |two|
22
+ expect(compile_to_catalog("notify { find_file('#{one}', '#{two}'):}")).to have_resource("Notify[#{one}]")
23
+ end
24
+ end
25
+ end
26
+
27
+ it 'skips non existing files' do
28
+ with_file_content('one') do |one|
29
+ with_file_content('two') do |two|
30
+ expect(compile_to_catalog("notify { find_file('#{one}/nope', '#{two}'):}")).to have_resource("Notify[#{two}]")
31
+ end
32
+ end
33
+ end
34
+
35
+ it 'accepts arguments given as an array' do
36
+ with_file_content('one') do |one|
37
+ with_file_content('two') do |two|
38
+ expect(compile_to_catalog("notify { find_file(['#{one}', '#{two}']):}")).to have_resource("Notify[#{one}]")
39
+ end
40
+ end
41
+ end
42
+
43
+ it 'finds an existing file in a module' do
44
+ with_file_content('file content') do |name|
45
+ mod = mock 'module'
46
+ mod.stubs(:file).with('myfile').returns(name)
47
+ Puppet[:code] = "notify { find_file('mymod/myfile'):}"
48
+ node = Puppet::Node.new('localhost')
49
+ compiler = Puppet::Parser::Compiler.new(node)
50
+ compiler.environment.stubs(:module).with('mymod').returns(mod)
51
+
52
+ expect(compiler.compile().filter { |r| r.virtual? }).to have_resource("Notify[#{name}]")
53
+ end
54
+ end
55
+
56
+ it 'returns undef when none of the paths were found' do
57
+ mod = mock 'module'
58
+ mod.stubs(:file).with('myfile').returns(nil)
59
+ Puppet[:code] = "notify { String(type(find_file('mymod/myfile', 'nomod/nofile'))):}"
60
+ node = Puppet::Node.new('localhost')
61
+ compiler = Puppet::Parser::Compiler.new(node)
62
+ # For a module that does not have the file
63
+ compiler.environment.stubs(:module).with('mymod').returns(mod)
64
+ # For a module that does not exist
65
+ compiler.environment.stubs(:module).with('nomod').returns(nil)
66
+
67
+ expect(compiler.compile().filter { |r| r.virtual? }).to have_resource("Notify[Undef]")
68
+ end
69
+ end
@@ -0,0 +1,175 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet_spec/compiler'
4
+ require 'puppet/parser/functions'
5
+ require 'matchers/containment_matchers'
6
+ require 'matchers/resource'
7
+ require 'matchers/include_in_order'
8
+ require 'unit/functions/shared'
9
+
10
+
11
+ describe 'The "include" function' do
12
+ include PuppetSpec::Compiler
13
+ include ContainmentMatchers
14
+ include Matchers::Resource
15
+
16
+ before(:each) do
17
+ compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
18
+ @scope = Puppet::Parser::Scope.new(compiler)
19
+ end
20
+
21
+ it "includes a class" do
22
+ catalog = compile_to_catalog(<<-MANIFEST)
23
+ class included {
24
+ notify { "included": }
25
+ }
26
+
27
+ include included
28
+ MANIFEST
29
+
30
+ expect(catalog.classes).to include("included")
31
+ end
32
+
33
+ it "includes a class when using a fully qualified anchored name" do
34
+ catalog = compile_to_catalog(<<-MANIFEST)
35
+ class included {
36
+ notify { "included": }
37
+ }
38
+
39
+ include ::included
40
+ MANIFEST
41
+
42
+ expect(catalog.classes).to include("included")
43
+ end
44
+
45
+ it "includes multiple classes" do
46
+ catalog = compile_to_catalog(<<-MANIFEST)
47
+ class included {
48
+ notify { "included": }
49
+ }
50
+ class included_too {
51
+ notify { "included_too": }
52
+ }
53
+
54
+ include included, included_too
55
+ MANIFEST
56
+
57
+ expect(catalog.classes).to include("included")
58
+ expect(catalog.classes).to include("included_too")
59
+ end
60
+
61
+ it "includes multiple classes given as an array" do
62
+ catalog = compile_to_catalog(<<-MANIFEST)
63
+ class included {
64
+ notify { "included": }
65
+ }
66
+ class included_too {
67
+ notify { "included_too": }
68
+ }
69
+
70
+ include [included, included_too]
71
+ MANIFEST
72
+
73
+ expect(catalog.classes).to include("included")
74
+ expect(catalog.classes).to include("included_too")
75
+ end
76
+
77
+ it "flattens nested arrays" do
78
+ catalog = compile_to_catalog(<<-MANIFEST)
79
+ class included {
80
+ notify { "included": }
81
+ }
82
+ class included_too {
83
+ notify { "included_too": }
84
+ }
85
+
86
+ include [[[included], [[[included_too]]]]]
87
+ MANIFEST
88
+
89
+ expect(catalog.classes).to include("included")
90
+ expect(catalog.classes).to include("included_too")
91
+ end
92
+
93
+ it "raises an error if class does not exist" do
94
+ expect {
95
+ catalog = compile_to_catalog(<<-MANIFEST)
96
+ include the_god_in_your_religion
97
+ MANIFEST
98
+ }.to raise_error(Puppet::Error)
99
+ end
100
+
101
+ it "does not contained the included class in the current class" do
102
+ catalog = compile_to_catalog(<<-MANIFEST)
103
+ class not_contained {
104
+ notify { "not_contained": }
105
+ }
106
+
107
+ class container {
108
+ include not_contained
109
+ }
110
+
111
+ include container
112
+ MANIFEST
113
+
114
+ expect(catalog).to_not contain_class("not_contained").in("container")
115
+ end
116
+
117
+
118
+ it 'produces an array with a single class references given a single argument' do
119
+ catalog = compile_to_catalog(<<-MANIFEST)
120
+ class a {
121
+ notify { "a": }
122
+ }
123
+
124
+ $x = include(a)
125
+ Array[Type[Class], 1, 1].assert_type($x)
126
+ notify { 'feedback': message => "$x" }
127
+ MANIFEST
128
+
129
+ feedback = catalog.resource("Notify", "feedback")
130
+ expect(feedback[:message]).to eql("[Class[a]]")
131
+ end
132
+
133
+ it 'produces an array with class references given multiple arguments' do
134
+ catalog = compile_to_catalog(<<-MANIFEST)
135
+ class a {
136
+ notify { "a": }
137
+ }
138
+
139
+ class b {
140
+ notify { "b": }
141
+ }
142
+
143
+ $x = include(a, b)
144
+ Array[Type[Class], 2, 2].assert_type($x)
145
+ notify { 'feedback': message => "$x" }
146
+ MANIFEST
147
+
148
+ feedback = catalog.resource("Notify", "feedback")
149
+ expect(feedback[:message]).to eql("[Class[a], Class[b]]")
150
+ end
151
+
152
+ it 'allows the result to be used in a relationship operation' do
153
+ catalog = compile_to_catalog(<<-MANIFEST)
154
+ class a {
155
+ notify { "a": }
156
+ }
157
+
158
+ class b {
159
+ notify { "b": }
160
+ }
161
+
162
+ notify { 'c': }
163
+
164
+ include(a, b) -> Notify[c]
165
+ MANIFEST
166
+
167
+ # Assert relationships are formed
168
+ expect(catalog.resource("Class", "a")[:before][0]).to eql('Notify[c]')
169
+ expect(catalog.resource("Class", "b")[:before][0]).to eql('Notify[c]')
170
+ end
171
+
172
+ it_should_behave_like 'all functions transforming relative to absolute names', :include
173
+ it_should_behave_like 'an inclusion function, regardless of the type of class reference,', :include
174
+
175
+ end