puppet 4.4.2 → 4.5.0

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 (218) hide show
  1. data/CONTRIBUTING.md +5 -5
  2. data/Gemfile +2 -2
  3. data/LICENSE +2 -2
  4. data/README.md +5 -0
  5. data/ext/project_data.yaml +2 -0
  6. data/lib/hiera_puppet.rb +6 -14
  7. data/lib/puppet/application/agent.rb +2 -3
  8. data/lib/puppet/data_providers/hiera_config.rb +2 -4
  9. data/lib/puppet/data_providers/hiera_interpolate.rb +12 -154
  10. data/lib/puppet/data_providers/json_data_provider_factory.rb +0 -7
  11. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -8
  12. data/lib/puppet/defaults.rb +70 -7
  13. data/lib/puppet/functions.rb +69 -0
  14. data/lib/puppet/functions/dig.rb +39 -0
  15. data/lib/puppet/functions/lest.rb +53 -0
  16. data/lib/puppet/functions/lookup.rb +40 -27
  17. data/lib/puppet/functions/new.rb +502 -0
  18. data/lib/puppet/functions/regsubst.rb +11 -10
  19. data/lib/puppet/functions/then.rb +74 -0
  20. data/lib/puppet/functions/type.rb +4 -4
  21. data/lib/puppet/functions/with.rb +1 -1
  22. data/lib/puppet/indirector/catalog/compiler.rb +2 -0
  23. data/lib/puppet/indirector/resource_type/parser.rb +5 -0
  24. data/lib/puppet/indirector/rest.rb +5 -1
  25. data/lib/puppet/loaders.rb +2 -0
  26. data/lib/puppet/metatype/manager.rb +19 -2
  27. data/lib/puppet/module_tool/applications/application.rb +1 -1
  28. data/lib/puppet/module_tool/skeleton/templates/generator/Gemfile +6 -2
  29. data/lib/puppet/module_tool/skeleton/templates/generator/Rakefile +19 -4
  30. data/lib/puppet/module_tool/skeleton/templates/generator/{tests → examples}/init.pp.erb +1 -1
  31. data/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +0 -1
  32. data/lib/puppet/network/http/api/master/v3/environment.rb +6 -2
  33. data/lib/puppet/parser/ast/pops_bridge.rb +20 -3
  34. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +24 -2
  35. data/lib/puppet/parser/e4_parser_adapter.rb +13 -12
  36. data/lib/puppet/parser/environment_compiler.rb +2 -2
  37. data/lib/puppet/parser/resource.rb +14 -5
  38. data/lib/puppet/parser/scope.rb +18 -15
  39. data/lib/puppet/plugins/data_providers/data_provider.rb +19 -8
  40. data/lib/puppet/pops.rb +6 -0
  41. data/lib/puppet/pops/adapters.rb +5 -1
  42. data/lib/puppet/pops/evaluator/access_operator.rb +52 -14
  43. data/lib/puppet/pops/evaluator/compare_operator.rb +34 -4
  44. data/lib/puppet/pops/evaluator/evaluator_impl.rb +75 -22
  45. data/lib/puppet/pops/evaluator/literal_evaluator.rb +7 -6
  46. data/lib/puppet/pops/evaluator/runtime3_converter.rb +13 -1
  47. data/lib/puppet/pops/evaluator/runtime3_support.rb +14 -4
  48. data/lib/puppet/pops/functions/dispatcher.rb +1 -1
  49. data/lib/puppet/pops/issues.rb +18 -2
  50. data/lib/puppet/pops/loader/base_loader.rb +48 -7
  51. data/lib/puppet/pops/loader/dependency_loader.rb +27 -2
  52. data/lib/puppet/pops/loader/loader.rb +12 -0
  53. data/lib/puppet/pops/loader/predefined_loader.rb +29 -0
  54. data/lib/puppet/pops/loader/runtime3_type_loader.rb +57 -0
  55. data/lib/puppet/pops/loader/static_loader.rb +92 -5
  56. data/lib/puppet/pops/loader/type_definition_instantiator.rb +25 -3
  57. data/lib/puppet/pops/loaders.rb +84 -14
  58. data/lib/puppet/pops/lookup/explainer.rb +38 -1
  59. data/lib/puppet/pops/lookup/interpolation.rb +115 -0
  60. data/lib/puppet/pops/lookup/sub_lookup.rb +86 -0
  61. data/lib/puppet/pops/model/ast_transformer.rb +8 -1
  62. data/lib/puppet/pops/model/factory.rb +31 -8
  63. data/lib/puppet/pops/model/model.rb +8 -0
  64. data/lib/puppet/pops/model/model_label_provider.rb +1 -0
  65. data/lib/puppet/pops/model/model_meta.rb +7 -1
  66. data/lib/puppet/pops/model/model_tree_dumper.rb +4 -0
  67. data/lib/puppet/pops/parser/egrammar.ra +24 -7
  68. data/lib/puppet/pops/parser/eparser.rb +863 -798
  69. data/lib/puppet/pops/parser/evaluating_parser.rb +4 -0
  70. data/lib/puppet/pops/parser/locator.rb +8 -4
  71. data/lib/puppet/pops/pcore.rb +30 -0
  72. data/lib/puppet/pops/types/class_loader.rb +2 -4
  73. data/lib/puppet/pops/types/implementation_registry.rb +146 -0
  74. data/lib/puppet/pops/types/iterable.rb +4 -4
  75. data/lib/puppet/pops/types/p_object_type.rb +846 -0
  76. data/lib/puppet/pops/types/p_runtime_type.rb +102 -0
  77. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +164 -0
  78. data/lib/puppet/pops/types/p_sem_ver_type.rb +113 -0
  79. data/lib/puppet/pops/types/puppet_object.rb +21 -0
  80. data/lib/puppet/pops/types/ruby_generator.rb +258 -0
  81. data/lib/puppet/pops/types/string_converter.rb +922 -0
  82. data/lib/puppet/pops/types/type_calculator.rb +29 -5
  83. data/lib/puppet/pops/types/type_conversion_error.rb +15 -0
  84. data/lib/puppet/pops/types/type_factory.rb +49 -16
  85. data/lib/puppet/pops/types/type_formatter.rb +335 -112
  86. data/lib/puppet/pops/types/type_mismatch_describer.rb +110 -29
  87. data/lib/puppet/pops/types/type_parser.rb +205 -197
  88. data/lib/puppet/pops/types/types.rb +481 -103
  89. data/lib/puppet/pops/validation.rb +1 -1
  90. data/lib/puppet/pops/validation/checker4_0.rb +66 -4
  91. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -0
  92. data/lib/puppet/pops/visitor.rb +3 -1
  93. data/lib/puppet/property.rb +1 -1
  94. data/lib/puppet/provider/augeas/augeas.rb +1 -1
  95. data/lib/puppet/provider/package/pip.rb +64 -20
  96. data/lib/puppet/provider/package/rpm.rb +112 -0
  97. data/lib/puppet/provider/package/yum.rb +7 -68
  98. data/lib/puppet/provider/service/daemontools.rb +3 -3
  99. data/lib/puppet/provider/service/init.rb +4 -2
  100. data/lib/puppet/provider/service/runit.rb +3 -3
  101. data/lib/puppet/provider/service/smf.rb +6 -3
  102. data/lib/puppet/provider/service/systemd.rb +59 -73
  103. data/lib/puppet/reference/providers.rb +1 -2
  104. data/lib/puppet/resource.rb +54 -37
  105. data/lib/puppet/resource/catalog.rb +31 -29
  106. data/lib/puppet/resource/type_collection.rb +23 -8
  107. data/lib/puppet/settings.rb +4 -2
  108. data/lib/puppet/settings/base_setting.rb +9 -3
  109. data/lib/puppet/settings/symbolic_enum_setting.rb +17 -0
  110. data/lib/puppet/test/test_helper.rb +0 -1
  111. data/lib/puppet/type.rb +9 -3
  112. data/lib/puppet/type/exec.rb +17 -17
  113. data/lib/puppet/type/file.rb +12 -0
  114. data/lib/puppet/type/file/content.rb +6 -6
  115. data/lib/puppet/type/file/ensure.rb +4 -4
  116. data/lib/puppet/type/file/source.rb +4 -4
  117. data/lib/puppet/type/file/target.rb +2 -2
  118. data/lib/puppet/type/mount.rb +18 -1
  119. data/lib/puppet/type/package.rb +3 -3
  120. data/lib/puppet/type/schedule.rb +4 -4
  121. data/lib/puppet/type/service.rb +15 -0
  122. data/lib/puppet/type/sshkey.rb +5 -3
  123. data/lib/puppet/type/tidy.rb +3 -3
  124. data/lib/puppet/type/zone.rb +5 -5
  125. data/lib/puppet/util/feature.rb +1 -1
  126. data/lib/puppet/util/monkey_patches.rb +8 -0
  127. data/lib/puppet/util/network_device/cisco/device.rb +16 -6
  128. data/lib/puppet/util/network_device/cisco/interface.rb +5 -6
  129. data/lib/puppet/util/plist.rb +3 -3
  130. data/lib/puppet/version.rb +1 -1
  131. data/spec/fixtures/unit/application/environments/production/data/common.yaml +13 -0
  132. data/spec/fixtures/unit/data_providers/environments/production/modules/abc/lib/puppet/functions/abc/data.rb +2 -1
  133. data/spec/fixtures/unit/data_providers/environments/production/modules/abc/manifests/init.pp +2 -1
  134. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/data/empty_key.json +1 -0
  135. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/hiera.yaml +5 -0
  136. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/manifests/init.pp +2 -0
  137. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/metadata.json +9 -0
  138. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/data/empty_key.yaml +1 -0
  139. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/hiera.yaml +5 -0
  140. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/manifests/init.pp +2 -0
  141. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/metadata.json +9 -0
  142. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/data/empty.yaml +1 -0
  143. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/lib/puppet/type/usee_type.rb +5 -0
  144. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/manifests/init.pp +6 -0
  145. data/spec/fixtures/unit/provider/service/smf/svcs.out +4 -3
  146. data/spec/integration/module_tool/tar/mini_spec.rb +27 -27
  147. data/spec/integration/parser/catalog_spec.rb +14 -2
  148. data/spec/integration/parser/compiler_spec.rb +94 -3
  149. data/spec/integration/parser/resource_expressions_spec.rb +1 -1
  150. data/spec/integration/resource/type_collection_spec.rb +8 -0
  151. data/spec/lib/puppet_spec/compiler.rb +11 -4
  152. data/spec/shared_contexts/types_setup.rb +4 -0
  153. data/spec/unit/application/lookup_spec.rb +91 -9
  154. data/spec/unit/appmgmt_spec.rb +44 -35
  155. data/spec/unit/capability_spec.rb +33 -53
  156. data/spec/unit/data_providers/function_data_provider_spec.rb +19 -1
  157. data/spec/unit/data_providers/hiera_data_provider_spec.rb +1 -1
  158. data/spec/unit/defaults_spec.rb +18 -0
  159. data/spec/unit/functions/assert_type_spec.rb +1 -1
  160. data/spec/unit/functions/dig_spec.rb +58 -0
  161. data/spec/unit/functions/lest_spec.rb +34 -0
  162. data/spec/unit/functions/lookup_spec.rb +108 -2
  163. data/spec/unit/functions/new_spec.rb +543 -0
  164. data/spec/unit/functions/regsubst_spec.rb +8 -0
  165. data/spec/unit/functions/then_spec.rb +40 -0
  166. data/spec/unit/functions4_spec.rb +78 -10
  167. data/spec/unit/hiera_puppet_spec.rb +49 -8
  168. data/spec/unit/indirector/resource_type/parser_spec.rb +5 -0
  169. data/spec/unit/indirector/rest_spec.rb +12 -0
  170. data/spec/unit/network/http/api/master/v3/environment_spec.rb +60 -0
  171. data/spec/unit/node/environment_spec.rb +10 -0
  172. data/spec/unit/parser/compiler_spec.rb +20 -1
  173. data/spec/unit/parser/functions/create_resources_spec.rb +2 -2
  174. data/spec/unit/parser/functions/shared.rb +1 -1
  175. data/spec/unit/parser/resource_spec.rb +8 -1
  176. data/spec/unit/parser/scope_spec.rb +45 -0
  177. data/spec/unit/pops/evaluator/access_ops_spec.rb +14 -0
  178. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +13 -5
  179. data/spec/unit/pops/loaders/static_loader_spec.rb +92 -1
  180. data/spec/unit/{data_providers/hiera_interpolation_spec.rb → pops/lookup/interpolation_spec.rb} +7 -5
  181. data/spec/unit/pops/parser/lexer2_spec.rb +2 -9
  182. data/spec/unit/pops/parser/parse_application_spec.rb +3 -8
  183. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +19 -0
  184. data/spec/unit/pops/parser/parse_capabilities_spec.rb +3 -10
  185. data/spec/unit/pops/parser/parse_site_spec.rb +19 -10
  186. data/spec/unit/pops/parser/parser_rspec_helper.rb +0 -4
  187. data/spec/unit/pops/types/enumeration_spec.rb +13 -12
  188. data/spec/unit/pops/types/iterable_spec.rb +2 -2
  189. data/spec/unit/pops/types/p_object_type_spec.rb +1060 -0
  190. data/spec/unit/pops/types/p_sem_ver_type_spec.rb +285 -0
  191. data/spec/unit/pops/types/recursion_guard_spec.rb +19 -17
  192. data/spec/unit/pops/types/ruby_generator_spec.rb +261 -0
  193. data/spec/unit/pops/types/string_converter_spec.rb +904 -0
  194. data/spec/unit/pops/types/type_calculator_spec.rb +430 -406
  195. data/spec/unit/pops/types/type_factory_spec.rb +119 -104
  196. data/spec/unit/pops/types/type_formatter_spec.rb +73 -6
  197. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +2 -2
  198. data/spec/unit/pops/types/type_parser_spec.rb +54 -15
  199. data/spec/unit/pops/types/types_spec.rb +113 -8
  200. data/spec/unit/pops/validator/validator_spec.rb +84 -10
  201. data/spec/unit/provider/package/pip3_spec.rb +9 -270
  202. data/spec/unit/provider/package/pip_spec.rb +85 -30
  203. data/spec/unit/provider/package/rpm_spec.rb +160 -3
  204. data/spec/unit/provider/package/yum_spec.rb +23 -134
  205. data/spec/unit/provider/service/smf_spec.rb +14 -2
  206. data/spec/unit/provider/service/systemd_spec.rb +33 -41
  207. data/spec/unit/resource/capability_finder_spec.rb +10 -2
  208. data/spec/unit/settings/file_setting_spec.rb +6 -0
  209. data/spec/unit/transaction/additional_resource_generator_spec.rb +80 -65
  210. data/spec/unit/type/mount_spec.rb +51 -10
  211. data/spec/unit/type/service_spec.rb +16 -0
  212. data/spec/unit/type_spec.rb +14 -0
  213. data/spec/unit/util/feature_spec.rb +1 -1
  214. data/spec/unit/util/monkey_patches_spec.rb +60 -0
  215. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
  216. metadata +63 -11
  217. data/lib/puppet/pops/types/types_meta.rb +0 -0
  218. data/spec/integration/provider/package_spec.rb +0 -35
@@ -324,6 +324,51 @@ describe Puppet::Parser::Scope do
324
324
  expect { @scope['module_name'] }.to_not raise_error
325
325
  end
326
326
  end
327
+
328
+ context "and strict_variables is false and --strict=off" do
329
+ before(:each) do
330
+ Puppet[:strict_variables] = false
331
+ Puppet[:strict] = :off
332
+ end
333
+
334
+ it "should not error when unknown variable is looked up and produce nil" do
335
+ expect(@scope['john_doe']).to be_nil
336
+ end
337
+
338
+ it "should not error when unknown qualified variable is looked up and produce nil" do
339
+ expect(@scope['nowhere::john_doe']).to be_nil
340
+ end
341
+ end
342
+
343
+ context "and strict_variables is false and --strict=warning" do
344
+ before(:each) do
345
+ Puppet[:strict_variables] = false
346
+ Puppet[:strict] = :warning
347
+ end
348
+
349
+ it "should not error when unknown variable is looked up" do
350
+ expect(@scope['john_doe']).to be_nil
351
+ end
352
+
353
+ it "should not error when unknown qualified variable is looked up" do
354
+ expect(@scope['nowhere::john_doe']).to be_nil
355
+ end
356
+ end
357
+
358
+ context "and strict_variables is false and --strict=error" do
359
+ before(:each) do
360
+ Puppet[:strict_variables] = false
361
+ Puppet[:strict] = :error
362
+ end
363
+
364
+ it "should raise error when unknown variable is looked up" do
365
+ expect { @scope['john_doe'] }.to raise_error(/Undefined variable/)
366
+ end
367
+
368
+ it "should not throw a symbol when unknown qualified variable is looked up" do
369
+ expect { @scope['nowhere::john_doe'] }.to raise_error(/Undefined variable/)
370
+ end
371
+ end
327
372
  end
328
373
 
329
374
  describe "when variables are set with append=true" do
@@ -166,6 +166,11 @@ describe 'Puppet::Pops::Evaluator::EvaluatorImpl/AccessOperator' do
166
166
 
167
167
  # Hash Type
168
168
  #
169
+ it 'produces a Hash[0, 0] from the expression Hash[0, 0]' do
170
+ expr = fqr('Hash')[0, 0]
171
+ expect(evaluate(expr)).to be_the_type(types.hash_of(types.default, types.default, types.range(0, 0)))
172
+ end
173
+
169
174
  it 'produces a Hash[Scalar,String] from the expression Hash[Scalar, String]' do
170
175
  expr = fqr('Hash')[fqr('Scalar'), fqr('String')]
171
176
  expect(evaluate(expr)).to be_the_type(types.hash_of(types.string, types.scalar))
@@ -192,6 +197,15 @@ describe 'Puppet::Pops::Evaluator::EvaluatorImpl/AccessOperator' do
192
197
 
193
198
  # Array Type
194
199
  #
200
+ it 'produces an Array[0, 0] from the expression Array[0, 0]' do
201
+ expr = fqr('Array')[0, 0]
202
+ expect(evaluate(expr)).to be_the_type(types.array_of(types.default, types.range(0, 0)))
203
+
204
+ # arguments are flattened
205
+ expr = fqr('Array')[[fqr('String')]]
206
+ expect(evaluate(expr)).to be_the_type(types.array_of(types.string))
207
+ end
208
+
195
209
  it 'produces an Array[String] from the expression Array[String]' do
196
210
  expr = fqr('Array')[fqr('String')]
197
211
  expect(evaluate(expr)).to be_the_type(types.array_of(types.string))
@@ -57,7 +57,15 @@ describe 'Puppet::Pops::Evaluator::EvaluatorImpl' do
57
57
  it "should parse and evaluate the expression '#{source}' to #{result}" do
58
58
  expect(parser.evaluate_string(scope, source, __FILE__)).to eq(result)
59
59
  end
60
- end
60
+ end
61
+
62
+ it 'should error when it encounters an unknown resource' do
63
+ expect {parser.evaluate_string(scope, '$a = SantaClause', __FILE__)}.to raise_error(/Resource type not found: SantaClause/)
64
+ end
65
+
66
+ it 'should error when it encounters an unknown resource with a parameter' do
67
+ expect {parser.evaluate_string(scope, '$b = ToothFairy[emea]', __FILE__)}.to raise_error(/Resource type not found: ToothFairy/)
68
+ end
61
69
  end
62
70
 
63
71
  context "When the evaluator evaluates Lists and Hashes" do
@@ -253,9 +261,9 @@ describe 'Puppet::Pops::Evaluator::EvaluatorImpl' do
253
261
  "xxx in bananas" => false,
254
262
  "/ana/ in bananas" => true,
255
263
  "/xxx/ in bananas" => false,
256
- "ANA in bananas" => false, # ANA is a type, not a String
264
+ "FILE in profiler" => false, # FILE is a type, not a String
265
+ "'FILE' in profiler" => true,
257
266
  "String[1] in bananas" => false, # Philosophically true though :-)
258
- "'ANA' in bananas" => true,
259
267
  "ana in 'BANANAS'" => true,
260
268
  "/ana/ in 'BANANAS'" => false,
261
269
  "/ANA/ in 'BANANAS'" => true,
@@ -307,13 +315,13 @@ describe 'Puppet::Pops::Evaluator::EvaluatorImpl' do
307
315
 
308
316
  {
309
317
  'Any' => ['NotUndef', 'Data', 'Scalar', 'Numeric', 'Integer', 'Float', 'Boolean', 'String', 'Pattern', 'Collection',
310
- 'Array', 'Hash', 'CatalogEntry', 'Resource', 'Class', 'Undef', 'File', 'NotYetKnownResourceType'],
318
+ 'Array', 'Hash', 'CatalogEntry', 'Resource', 'Class', 'Undef', 'File' ],
311
319
 
312
320
  # Note, Data > Collection is false (so not included)
313
321
  'Data' => ['Scalar', 'Numeric', 'Integer', 'Float', 'Boolean', 'String', 'Pattern', 'Array', 'Hash',],
314
322
  'Scalar' => ['Numeric', 'Integer', 'Float', 'Boolean', 'String', 'Pattern'],
315
323
  'Numeric' => ['Integer', 'Float'],
316
- 'CatalogEntry' => ['Class', 'Resource', 'File', 'NotYetKnownResourceType'],
324
+ 'CatalogEntry' => ['Class', 'Resource', 'File'],
317
325
  'Integer[1,10]' => ['Integer[2,3]'],
318
326
  }.each do |general, specials|
319
327
  specials.each do |special |
@@ -46,7 +46,98 @@ describe 'the static loader' do
46
46
  end
47
47
  end
48
48
 
49
+ context 'provides access to resource types built into puppet' do
50
+ let(:loader) { loader = Puppet::Pops::Loader::StaticLoader.new() }
51
+
52
+ %w{
53
+ Auegas
54
+ Component
55
+ Computer
56
+ Cron
57
+ Exec
58
+ File
59
+ Filebucket
60
+ Group
61
+ Host
62
+ Interface
63
+ K5login
64
+ Macauthorization
65
+ Mailalias
66
+ Maillist
67
+ Mcx
68
+ Mount
69
+ Nagios_command
70
+ Nagios_contact
71
+ Nagios_contactgroup
72
+ Nagios_host
73
+ Nagios_hostdependency
74
+ Nagios_hostescalation
75
+ Nagios_hostescalation
76
+ Nagios_hostgroup
77
+ Nagios_service
78
+ Nagios_servicedependency
79
+ Nagios_serviceescalation
80
+ Nagios_serviceextinfo
81
+ Nagios_servicegroup
82
+ Nagios_timeperiod
83
+ Notify
84
+ Package
85
+ Resources
86
+ Router
87
+ Schedule
88
+ Scheduled_task
89
+ Selboolean
90
+ Selmodule
91
+ Service
92
+ Ssh_authorized_key
93
+ Sshkey
94
+ Stage
95
+ Tidy
96
+ User
97
+ Vlan
98
+ Whit
99
+ Yumrepo
100
+ Zfs
101
+ Zone
102
+ Zpool
103
+ }.each do |name |
104
+ it "such that #{name} is available" do
105
+ expect(loader.load(:type, name.downcase)).to be_the_type(resource_type(name))
106
+ end
107
+ end
108
+ end
109
+
110
+ context 'provides access to app-management specific resource types built into puppet' do
111
+ before(:each) { Puppet[:app_management] = true }
112
+ after(:each) { Puppet[:app_management] = false }
113
+
114
+ let(:loader) { loader = Puppet::Pops::Loader::StaticLoader.new() }
115
+
116
+ %w{Node}.each do |name|
117
+ it "such that #{name} is avaiable" do
118
+ expect(loader.load(:type, name.downcase)).to be_the_type(resource_type(name))
119
+ end
120
+ end
121
+ end
122
+
49
123
  def typed_name(type, name)
50
124
  Puppet::Pops::Loader::Loader::TypedName.new(type, name)
51
125
  end
52
- end
126
+
127
+ def resource_type(name)
128
+ Puppet::Pops::Types::TypeFactory.resource(name)
129
+ end
130
+
131
+ matcher :be_the_type do |type|
132
+ calc = Puppet::Pops::Types::TypeCalculator.new
133
+
134
+ match do |actual|
135
+ calc.assignable?(actual, type) && calc.assignable?(type, actual)
136
+ end
137
+
138
+ failure_message do |actual|
139
+ "expected #{type.to_s}, but was #{actual.to_s}"
140
+ end
141
+ end
142
+
143
+ end
@@ -4,14 +4,15 @@ require 'puppet'
4
4
  require 'puppet/data_providers/hiera_config'
5
5
  require 'puppet/data_providers/hiera_interpolate'
6
6
 
7
- describe 'Puppet::DataProviders::HieraInterpolate' do
7
+ module Puppet::Pops
8
+ describe 'Puppet::Pops::Lookup::Interpolation' do
8
9
 
9
- let(:interpolator) { Class.new { include Puppet::DataProviders::HieraInterpolate }.new }
10
+ let(:interpolator) { Class.new { include Lookup::Interpolation }.new }
10
11
  let(:scope) { {} }
11
- let(:lookup_invocation) { Puppet::Pops::Lookup::Invocation.new(scope, {}, {}, nil) }
12
+ let(:lookup_invocation) { Lookup::Invocation.new(scope, {}, {}, nil) }
12
13
 
13
14
  def expect_lookup(*keys)
14
- keys.each { |key| Puppet::Pops::Lookup.expects(:lookup).with(key, nil, '', true, nil, lookup_invocation).returns(data[key]) }
15
+ keys.each { |key| Lookup.expects(:lookup).with(key, nil, '', true, nil, lookup_invocation).returns(data[key]) }
15
16
  end
16
17
 
17
18
  context 'when interpolating nested data' do
@@ -221,7 +222,7 @@ describe 'Puppet::DataProviders::HieraInterpolate' do
221
222
 
222
223
  it 'should not find a subkey that is matched within a string' do
223
224
  expect_lookup('key')
224
- expect{ interpolator.interpolate('%{hiera("key.subkey")}', lookup_invocation, true) }.to raise_error(/Got String when a hash-like object was expected to enable lookup using key 'subkey'/)
225
+ expect{ interpolator.interpolate('%{hiera("key.subkey")}', lookup_invocation, true) }.to raise_error(/Got String when a hash-like object was expected to access value using 'subkey' from key 'key.subkey'/)
225
226
  end
226
227
  end
227
228
 
@@ -309,3 +310,4 @@ describe 'Puppet::DataProviders::HieraInterpolate' do
309
310
  end
310
311
  end
311
312
  end
313
+ end
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
  require 'matchers/match_tokens2'
3
3
  require 'puppet/pops'
4
4
  require 'puppet/pops/parser/lexer2'
5
- require_relative './parser_rspec_helper'
6
5
 
7
6
  module EgrammarLexer2Spec
8
7
  def tokens_scanned_from(s)
@@ -20,7 +19,6 @@ end
20
19
 
21
20
  describe 'Lexer2' do
22
21
  include EgrammarLexer2Spec
23
- include ParserRspecHelper
24
22
 
25
23
  {
26
24
  :LISTSTART => '[',
@@ -116,13 +114,8 @@ describe 'Lexer2' do
116
114
  end
117
115
 
118
116
  context 'when app_managment is (turned) on' do
119
- before(:each) do
120
- with_app_management(true)
121
- end
122
-
123
- after(:each) do
124
- with_app_management(false)
125
- end
117
+ before(:each) { Puppet[:app_management] = true }
118
+ after(:each) { Puppet[:app_management] = false }
126
119
 
127
120
  {
128
121
  "application" => :APPLICATION,
@@ -1,18 +1,13 @@
1
1
  #! /usr/bin/env ruby
2
2
  require 'spec_helper'
3
3
  require 'puppet/pops'
4
- require_relative './parser_rspec_helper'
4
+ require_relative 'parser_rspec_helper'
5
5
 
6
6
  describe "egrammar parsing of 'application'" do
7
7
  include ParserRspecHelper
8
8
 
9
- before(:each) do
10
- with_app_management(true)
11
- end
12
-
13
- after(:each) do
14
- with_app_management(false)
15
- end
9
+ before(:each) { Puppet[:app_management] = true }
10
+ after(:each) { Puppet[:app_management] = false }
16
11
 
17
12
  it "an empty body" do
18
13
  expect(dump(parse("application foo { }"))).to eq("(application foo () ())")
@@ -168,6 +168,25 @@ describe "egrammar parsing basic expressions" do
168
168
  expect(parse("[]").current.body.length).to eq(2)
169
169
  expect(parse("[ ]").current.body.length).to eq(3)
170
170
  end
171
+
172
+ {
173
+ 'keyword' => %w(type function),
174
+ 'reserved word' => %w(application site produces consumes)
175
+ }.each_pair do |word_type, words|
176
+ words.each do |word|
177
+ it "allows the #{word_type} '#{word}' in a list" do
178
+ expect(dump(parse("$a = [#{word}]"))).to(eq("(= $a ([] '#{word}'))"))
179
+ end
180
+
181
+ it "allows the #{word_type} '#{word}' as a key in a hash" do
182
+ expect(dump(parse("$a = {#{word}=>'x'}"))).to(eq("(= $a ({} ('#{word}' 'x')))"))
183
+ end
184
+
185
+ it "allows the #{word_type} '#{word}' as a value in a hash" do
186
+ expect(dump(parse("$a = {'x'=>#{word}}"))).to(eq("(= $a ({} ('x' '#{word}')))"))
187
+ end
188
+ end
189
+ end
171
190
  end
172
191
 
173
192
  context "When parsing indexed access" do
@@ -1,20 +1,13 @@
1
1
  #! /usr/bin/env ruby
2
2
  require 'spec_helper'
3
3
  require 'puppet/pops'
4
-
5
- # relative to this spec file (./) does not work as this file is loaded by rspec
6
- require File.join(File.dirname(__FILE__), '/parser_rspec_helper')
4
+ require_relative 'parser_rspec_helper'
7
5
 
8
6
  describe "egrammar parsing of capability mappings" do
9
7
  include ParserRspecHelper
10
8
 
11
- before(:each) do
12
- with_app_management(true)
13
- end
14
-
15
- after(:each) do
16
- with_app_management(false)
17
- end
9
+ before(:each) { Puppet[:app_management] = true }
10
+ after(:each) { Puppet[:app_management] = false }
18
11
 
19
12
  context "when parsing 'produces'" do
20
13
  it "the ast contains produces and attributes" do
@@ -1,20 +1,13 @@
1
1
  #! /usr/bin/env ruby
2
2
  require 'spec_helper'
3
3
  require 'puppet/pops'
4
-
5
- # relative to this spec file (./) does not work as this file is loaded by rspec
6
- require File.join(File.dirname(__FILE__), '/parser_rspec_helper')
4
+ require_relative 'parser_rspec_helper'
7
5
 
8
6
  describe "egrammar parsing of site expression" do
9
7
  include ParserRspecHelper
10
8
 
11
- before(:each) do
12
- with_app_management(true)
13
- end
14
-
15
- after(:each) do
16
- with_app_management(false)
17
- end
9
+ before(:each) { Puppet[:app_management] = true }
10
+ after(:each) { Puppet[:app_management] = false }
18
11
 
19
12
  context "when parsing 'site'" do
20
13
  it "an empty body is allowed" do
@@ -35,4 +28,20 @@ describe "egrammar parsing of site expression" do
35
28
  expect(dump(parse(prog))).to eq(ast)
36
29
  end
37
30
  end
31
+
32
+ context 'When parsing collections containing application management specific keywords' do
33
+ %w(application site produces consumes).each do |keyword|
34
+ it "allows the keyword '#{keyword}' in a list" do
35
+ expect(dump(parse("$a = [#{keyword}]"))).to(eq("(= $a ([] '#{keyword}'))"))
36
+ end
37
+
38
+ it "allows the keyword '#{keyword}' as a key in a hash" do
39
+ expect(dump(parse("$a = {#{keyword}=>'x'}"))).to(eq("(= $a ({} ('#{keyword}' 'x')))"))
40
+ end
41
+
42
+ it "allows the keyword '#{keyword}' as a value in a hash" do
43
+ expect(dump(parse("$a = {'x'=>#{keyword}}"))).to(eq("(= $a ({} ('x' '#{keyword}')))"))
44
+ end
45
+ end
46
+ end
38
47
  end
@@ -5,10 +5,6 @@ require File.join(File.dirname(__FILE__), '/../factory_rspec_helper')
5
5
  module ParserRspecHelper
6
6
  include FactoryRspecHelper
7
7
 
8
- def with_app_management(flag)
9
- Puppet[:app_management] = flag
10
- end
11
-
12
8
  def parse(code)
13
9
  parser = Puppet::Pops::Parser::Parser.new()
14
10
  parser.parse_string(code)
@@ -1,50 +1,51 @@
1
1
  require 'spec_helper'
2
2
  require 'puppet/pops'
3
3
 
4
+ module Puppet::Pops::Types
4
5
  describe 'The enumeration support' do
5
6
  it 'produces an enumerator for Array' do
6
- expect(Puppet::Pops::Types::Enumeration.enumerator([1,2,3]).respond_to?(:next)).to eql(true)
7
+ expect(Enumeration.enumerator([1,2,3]).respond_to?(:next)).to eql(true)
7
8
  end
8
9
 
9
10
  it 'produces an enumerator for Hash' do
10
- expect(Puppet::Pops::Types::Enumeration.enumerator({:a=>1}).respond_to?(:next)).to eql(true)
11
+ expect(Enumeration.enumerator({:a=>1}).respond_to?(:next)).to eql(true)
11
12
  end
12
13
 
13
14
  it 'produces a char enumerator for String' do
14
- enum = Puppet::Pops::Types::Enumeration.enumerator("abc")
15
+ enum = Enumeration.enumerator("abc")
15
16
  expect(enum.respond_to?(:next)).to eql(true)
16
17
  expect(enum.next).to eql('a')
17
18
  end
18
19
 
19
20
  it 'produces an enumerator for integer times' do
20
- enum = Puppet::Pops::Types::Enumeration.enumerator(2)
21
+ enum = Enumeration.enumerator(2)
21
22
  expect(enum.next).to eql(0)
22
23
  expect(enum.next).to eql(1)
23
24
  expect{enum.next}.to raise_error(StopIteration)
24
25
  end
25
26
 
26
27
  it 'produces an enumerator for Integer range' do
27
- range = Puppet::Pops::Types::TypeFactory.range(1,2)
28
- enum = Puppet::Pops::Types::Enumeration.enumerator(range)
28
+ range = TypeFactory.range(1,2)
29
+ enum = Enumeration.enumerator(range)
29
30
  expect(enum.next).to eql(1)
30
31
  expect(enum.next).to eql(2)
31
32
  expect{enum.next}.to raise_error(StopIteration)
32
33
  end
33
34
 
34
35
  it 'does not produce an enumerator for infinite Integer range' do
35
- range = Puppet::Pops::Types::TypeFactory.range(1,:default)
36
- enum = Puppet::Pops::Types::Enumeration.enumerator(range)
36
+ range = TypeFactory.range(1,:default)
37
+ enum = Enumeration.enumerator(range)
37
38
  expect(enum).to be_nil
38
- range = Puppet::Pops::Types::TypeFactory.range(:default,2)
39
- enum = Puppet::Pops::Types::Enumeration.enumerator(range)
39
+ range = TypeFactory.range(:default,2)
40
+ enum = Enumeration.enumerator(range)
40
41
  expect(enum).to be_nil
41
42
  end
42
43
 
43
44
  [3.14, /.*/, true, false, nil, :something].each do |x|
44
45
  it "does not produce an enumerator for object of type #{x.class}" do
45
- enum = Puppet::Pops::Types::Enumeration.enumerator(x)
46
+ enum = Enumeration.enumerator(x)
46
47
  expect(enum).to be_nil
47
48
  end
48
49
  end
49
-
50
+ end
50
51
  end