puppet 6.19.0 → 6.22.1

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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/CODEOWNERS +2 -16
  3. data/Gemfile +3 -1
  4. data/Gemfile.lock +50 -39
  5. data/ext/project_data.yaml +2 -2
  6. data/lib/puppet/application.rb +10 -6
  7. data/lib/puppet/application/agent.rb +1 -0
  8. data/lib/puppet/application/apply.rb +3 -2
  9. data/lib/puppet/application/device.rb +1 -0
  10. data/lib/puppet/application/filebucket.rb +2 -2
  11. data/lib/puppet/application/script.rb +1 -0
  12. data/lib/puppet/application/ssl.rb +11 -0
  13. data/lib/puppet/application_support.rb +7 -0
  14. data/lib/puppet/configurer.rb +28 -18
  15. data/lib/puppet/defaults.rb +46 -20
  16. data/lib/puppet/environments.rb +54 -55
  17. data/lib/puppet/face/config.rb +10 -0
  18. data/lib/puppet/face/epp.rb +12 -2
  19. data/lib/puppet/face/facts.rb +158 -0
  20. data/lib/puppet/ffi/posix.rb +10 -0
  21. data/lib/puppet/ffi/posix/constants.rb +14 -0
  22. data/lib/puppet/ffi/posix/functions.rb +24 -0
  23. data/lib/puppet/file_system/memory_file.rb +8 -1
  24. data/lib/puppet/file_system/windows.rb +2 -0
  25. data/lib/puppet/functions/epp.rb +1 -0
  26. data/lib/puppet/functions/inline_epp.rb +1 -0
  27. data/lib/puppet/functions/partition.rb +8 -0
  28. data/lib/puppet/indirector/fact_search.rb +60 -0
  29. data/lib/puppet/indirector/facts/facter.rb +24 -3
  30. data/lib/puppet/indirector/facts/json.rb +27 -0
  31. data/lib/puppet/indirector/facts/yaml.rb +3 -58
  32. data/lib/puppet/indirector/json.rb +5 -1
  33. data/lib/puppet/indirector/node/json.rb +8 -0
  34. data/lib/puppet/indirector/report/json.rb +34 -0
  35. data/lib/puppet/module_tool/applications/installer.rb +48 -2
  36. data/lib/puppet/module_tool/errors/shared.rb +17 -2
  37. data/lib/puppet/network/formats.rb +69 -1
  38. data/lib/puppet/network/http/factory.rb +4 -0
  39. data/lib/puppet/pal/pal_impl.rb +70 -17
  40. data/lib/puppet/parser/ast/leaf.rb +3 -2
  41. data/lib/puppet/parser/templatewrapper.rb +1 -1
  42. data/lib/puppet/pops/evaluator/deferred_resolver.rb +5 -3
  43. data/lib/puppet/pops/evaluator/evaluator_impl.rb +22 -3
  44. data/lib/puppet/pops/model/ast_transformer.rb +1 -1
  45. data/lib/puppet/property/list.rb +1 -1
  46. data/lib/puppet/provider/group/groupadd.rb +13 -8
  47. data/lib/puppet/provider/package/apt.rb +34 -2
  48. data/lib/puppet/provider/package/aptitude.rb +6 -0
  49. data/lib/puppet/provider/package/dnfmodule.rb +1 -1
  50. data/lib/puppet/provider/service/debian.rb +2 -0
  51. data/lib/puppet/provider/service/systemd.rb +1 -1
  52. data/lib/puppet/provider/user/aix.rb +2 -2
  53. data/lib/puppet/provider/user/useradd.rb +62 -8
  54. data/lib/puppet/reference/configuration.rb +6 -5
  55. data/lib/puppet/settings.rb +43 -15
  56. data/lib/puppet/settings/alias_setting.rb +37 -0
  57. data/lib/puppet/settings/base_setting.rb +26 -2
  58. data/lib/puppet/settings/environment_conf.rb +1 -0
  59. data/lib/puppet/type/package.rb +3 -3
  60. data/lib/puppet/util/autoload.rb +1 -8
  61. data/lib/puppet/util/fact_dif.rb +81 -0
  62. data/lib/puppet/util/monkey_patches.rb +7 -0
  63. data/lib/puppet/util/posix.rb +54 -5
  64. data/lib/puppet/util/rubygems.rb +5 -1
  65. data/lib/puppet/util/windows/adsi.rb +46 -0
  66. data/lib/puppet/util/windows/api_types.rb +1 -1
  67. data/lib/puppet/util/windows/principal.rb +9 -2
  68. data/lib/puppet/util/windows/service.rb +1 -1
  69. data/lib/puppet/util/windows/sid.rb +4 -2
  70. data/lib/puppet/version.rb +1 -1
  71. data/locales/puppet.pot +295 -219
  72. data/man/man5/puppet.conf.5 +15 -7
  73. data/man/man8/puppet-agent.8 +2 -2
  74. data/man/man8/puppet-apply.8 +2 -2
  75. data/man/man8/puppet-catalog.8 +1 -1
  76. data/man/man8/puppet-config.8 +1 -1
  77. data/man/man8/puppet-describe.8 +1 -1
  78. data/man/man8/puppet-device.8 +2 -2
  79. data/man/man8/puppet-doc.8 +1 -1
  80. data/man/man8/puppet-epp.8 +1 -1
  81. data/man/man8/puppet-facts.8 +90 -1
  82. data/man/man8/puppet-filebucket.8 +3 -3
  83. data/man/man8/puppet-generate.8 +1 -1
  84. data/man/man8/puppet-help.8 +1 -1
  85. data/man/man8/puppet-key.8 +1 -1
  86. data/man/man8/puppet-lookup.8 +1 -1
  87. data/man/man8/puppet-man.8 +1 -1
  88. data/man/man8/puppet-module.8 +1 -1
  89. data/man/man8/puppet-node.8 +4 -1
  90. data/man/man8/puppet-parser.8 +1 -1
  91. data/man/man8/puppet-plugin.8 +1 -1
  92. data/man/man8/puppet-report.8 +4 -1
  93. data/man/man8/puppet-resource.8 +1 -1
  94. data/man/man8/puppet-script.8 +2 -2
  95. data/man/man8/puppet-ssl.8 +5 -1
  96. data/man/man8/puppet-status.8 +1 -1
  97. data/man/man8/puppet.8 +2 -2
  98. data/spec/fixtures/integration/application/agent/cached_deferred_catalog.json +91 -0
  99. data/spec/fixtures/unit/provider/service/systemd/list_unit_files_services_vendor_preset +9 -0
  100. data/spec/fixtures/unit/provider/user/aix/aix_passwd_file.out +4 -0
  101. data/spec/integration/application/agent_spec.rb +160 -3
  102. data/spec/integration/application/apply_spec.rb +19 -0
  103. data/spec/integration/application/plugin_spec.rb +1 -1
  104. data/spec/integration/defaults_spec.rb +0 -7
  105. data/spec/integration/environments/setting_hooks_spec.rb +1 -1
  106. data/spec/integration/http/client_spec.rb +12 -0
  107. data/spec/integration/indirector/direct_file_server_spec.rb +1 -3
  108. data/spec/integration/resource/type_collection_spec.rb +2 -6
  109. data/spec/integration/transaction_spec.rb +4 -9
  110. data/spec/integration/util/windows/adsi_spec.rb +21 -1
  111. data/spec/integration/util/windows/principal_spec.rb +21 -0
  112. data/spec/integration/util/windows/registry_spec.rb +6 -10
  113. data/spec/lib/puppet_spec/settings.rb +6 -1
  114. data/spec/spec_helper.rb +12 -5
  115. data/spec/unit/agent_spec.rb +8 -6
  116. data/spec/unit/application/agent_spec.rb +0 -1
  117. data/spec/unit/application/config_spec.rb +224 -4
  118. data/spec/unit/application/facts_spec.rb +482 -3
  119. data/spec/unit/application/filebucket_spec.rb +0 -2
  120. data/spec/unit/application/ssl_spec.rb +23 -0
  121. data/spec/unit/application_spec.rb +51 -9
  122. data/spec/unit/confine/feature_spec.rb +1 -1
  123. data/spec/unit/confine_spec.rb +8 -2
  124. data/spec/unit/defaults_spec.rb +36 -1
  125. data/spec/unit/environments_spec.rb +221 -68
  126. data/spec/unit/face/config_spec.rb +27 -32
  127. data/spec/unit/face/facts_spec.rb +4 -0
  128. data/spec/unit/face/node_spec.rb +0 -11
  129. data/spec/unit/file_serving/configuration/parser_spec.rb +0 -1
  130. data/spec/unit/file_serving/metadata_spec.rb +3 -3
  131. data/spec/unit/file_serving/terminus_helper_spec.rb +11 -4
  132. data/spec/unit/file_system_spec.rb +9 -0
  133. data/spec/unit/forge/module_release_spec.rb +2 -7
  134. data/spec/unit/functions/inline_epp_spec.rb +26 -1
  135. data/spec/unit/http/service/compiler_spec.rb +49 -0
  136. data/spec/unit/http/service_spec.rb +1 -1
  137. data/spec/unit/indirector/face_spec.rb +0 -1
  138. data/spec/unit/indirector/facts/facter_spec.rb +95 -1
  139. data/spec/unit/indirector/facts/json_spec.rb +255 -0
  140. data/spec/unit/indirector/file_bucket_file/selector_spec.rb +26 -8
  141. data/spec/unit/indirector/indirection_spec.rb +8 -12
  142. data/spec/unit/indirector/key/file_spec.rb +0 -1
  143. data/spec/unit/indirector/node/json_spec.rb +33 -0
  144. data/spec/{integration/indirector/report/yaml.rb → unit/indirector/report/json_spec.rb} +13 -24
  145. data/spec/unit/indirector/report/yaml_spec.rb +72 -8
  146. data/spec/unit/indirector_spec.rb +2 -2
  147. data/spec/unit/module_tool/applications/installer_spec.rb +66 -0
  148. data/spec/unit/network/authconfig_spec.rb +0 -3
  149. data/spec/unit/network/formats_spec.rb +41 -0
  150. data/spec/unit/network/http/api/indirected_routes_spec.rb +0 -9
  151. data/spec/unit/network/http/factory_spec.rb +19 -0
  152. data/spec/unit/network/http/handler_spec.rb +0 -5
  153. data/spec/unit/parser/compiler_spec.rb +3 -19
  154. data/spec/unit/parser/resource_spec.rb +14 -8
  155. data/spec/unit/parser/templatewrapper_spec.rb +4 -3
  156. data/spec/unit/pops/evaluator/deferred_resolver_spec.rb +20 -0
  157. data/spec/unit/property_spec.rb +1 -0
  158. data/spec/unit/provider/group/groupadd_spec.rb +5 -2
  159. data/spec/unit/provider/nameservice_spec.rb +66 -65
  160. data/spec/unit/provider/package/apt_spec.rb +28 -23
  161. data/spec/unit/provider/package/aptitude_spec.rb +1 -1
  162. data/spec/unit/provider/package/base_spec.rb +6 -5
  163. data/spec/unit/provider/package/dnfmodule_spec.rb +10 -1
  164. data/spec/unit/provider/package/pacman_spec.rb +18 -12
  165. data/spec/unit/provider/package/pip_spec.rb +6 -11
  166. data/spec/unit/provider/package/pkgdmg_spec.rb +0 -4
  167. data/spec/unit/provider/service/systemd_spec.rb +11 -0
  168. data/spec/unit/provider/user/aix_spec.rb +5 -0
  169. data/spec/unit/provider/user/hpux_spec.rb +1 -1
  170. data/spec/unit/provider/user/pw_spec.rb +2 -0
  171. data/spec/unit/provider/user/useradd_spec.rb +71 -3
  172. data/spec/unit/provider_spec.rb +8 -10
  173. data/spec/unit/puppet_pal_catalog_spec.rb +45 -0
  174. data/spec/unit/resource/capability_finder_spec.rb +6 -1
  175. data/spec/unit/resource/catalog_spec.rb +1 -1
  176. data/spec/unit/resource/type_spec.rb +1 -1
  177. data/spec/unit/resource_spec.rb +11 -10
  178. data/spec/unit/settings_spec.rb +543 -228
  179. data/spec/unit/ssl/base_spec.rb +0 -1
  180. data/spec/unit/ssl/host_spec.rb +0 -5
  181. data/spec/unit/ssl/ssl_provider_spec.rb +14 -8
  182. data/spec/unit/transaction/additional_resource_generator_spec.rb +3 -7
  183. data/spec/unit/transaction/event_manager_spec.rb +14 -11
  184. data/spec/unit/transaction_spec.rb +13 -4
  185. data/spec/unit/type/file/content_spec.rb +0 -1
  186. data/spec/unit/type/file/selinux_spec.rb +0 -2
  187. data/spec/unit/type/file_spec.rb +0 -6
  188. data/spec/unit/type/group_spec.rb +13 -6
  189. data/spec/unit/type/resources_spec.rb +7 -7
  190. data/spec/unit/type/service_spec.rb +1 -1
  191. data/spec/unit/type/tidy_spec.rb +0 -1
  192. data/spec/unit/type_spec.rb +2 -2
  193. data/spec/unit/util/at_fork_spec.rb +2 -2
  194. data/spec/unit/util/autoload_spec.rb +5 -1
  195. data/spec/unit/util/backups_spec.rb +1 -2
  196. data/spec/unit/util/execution_spec.rb +15 -11
  197. data/spec/unit/util/inifile_spec.rb +6 -14
  198. data/spec/unit/util/log_spec.rb +8 -7
  199. data/spec/unit/util/logging_spec.rb +3 -3
  200. data/spec/unit/util/posix_spec.rb +363 -15
  201. data/spec/unit/util/rubygems_spec.rb +2 -2
  202. data/spec/unit/util/selinux_spec.rb +76 -52
  203. data/spec/unit/util/storage_spec.rb +3 -1
  204. data/spec/unit/util/suidmanager_spec.rb +44 -41
  205. data/spec/unit/util/windows/sid_spec.rb +6 -0
  206. data/spec/unit/util_spec.rb +13 -6
  207. metadata +23 -14
  208. data/spec/integration/application/config_spec.rb +0 -74
  209. data/spec/lib/matchers/include.rb +0 -27
  210. data/spec/lib/matchers/include_spec.rb +0 -32
  211. data/spec/unit/face/catalog_spec.rb +0 -6
  212. data/spec/unit/face/module_spec.rb +0 -3
@@ -205,7 +205,7 @@ describe Puppet::Resource::Catalog, "when compiling" do
205
205
  end
206
206
 
207
207
  it "should set itself as the catalog for each converted resource" do
208
- @catalog.vertices.each { |v| expect(v.catalog.object_id).to equal(@catalog.object_id) }
208
+ @catalog.vertices.each { |v| expect(v.catalog.object_id).to eql(@catalog.object_id) }
209
209
  end
210
210
 
211
211
  # This tests #931.
@@ -554,7 +554,7 @@ describe Puppet::Resource::Type do
554
554
 
555
555
  it "should not create a subscope for the :main class" do
556
556
  allow(@resource).to receive(:title).and_return(:main)
557
- expect(@type).not_to receive(:subscope)
557
+ expect(@scope).not_to receive(:newscope)
558
558
  expect(@type).to receive(:set_resource_parameters).with(@resource, @scope)
559
559
 
560
560
  @type.evaluate_code(@resource)
@@ -321,7 +321,7 @@ describe Puppet::Resource do
321
321
 
322
322
  describe "when the resource type is :hostclass" do
323
323
  let(:environment_name) { "testing env" }
324
- let(:fact_values) { { :a => 1 } }
324
+ let(:fact_values) { { 'a' => 1 } }
325
325
  let(:port) { Puppet::Parser::AST::Leaf.new(:value => '80') }
326
326
 
327
327
  def inject_and_set_defaults(resource, scope)
@@ -330,10 +330,7 @@ describe Puppet::Resource do
330
330
 
331
331
  before do
332
332
  environment.known_resource_types.add(apache)
333
-
334
- allow(scope).to receive(:host).and_return('host')
335
- allow(scope).to receive(:environment).and_return(environment)
336
- allow(scope).to receive(:facts).and_return(Puppet::Node::Facts.new("facts", fact_values))
333
+ scope.set_facts(fact_values)
337
334
  end
338
335
 
339
336
  context 'with a default value expression' do
@@ -627,11 +624,15 @@ describe Puppet::Resource do
627
624
  expect(resource.to_hash[:myvar]).to eq("bob")
628
625
  end
629
626
 
630
- it "should set :name to the title if :name is not present for non-builtin types" do
631
- krt = Puppet::Resource::TypeCollection.new("myenv")
632
- krt.add Puppet::Resource::Type.new(:definition, :foo)
633
- resource = Puppet::Resource.new :foo, "bar"
634
- allow(resource).to receive(:known_resource_types).and_return(krt)
627
+ it "should set :name to the title if :name is not present for non-existent types" do
628
+ resource = Puppet::Resource.new :doesnotexist, "bar"
629
+ expect(resource.to_hash[:name]).to eq("bar")
630
+ end
631
+
632
+ it "should set :name to the title if :name is not present for a definition" do
633
+ type = Puppet::Resource::Type.new(:definition, :foo)
634
+ environment.known_resource_types.add(type)
635
+ resource = Puppet::Resource.new :foo, "bar", :environment => environment
635
636
  expect(resource.to_hash[:name]).to eq("bar")
636
637
  end
637
638
  end
@@ -87,16 +87,7 @@ describe Puppet::Settings do
87
87
  end
88
88
  end
89
89
 
90
-
91
90
  describe "when initializing application defaults do" do
92
- let(:default_values) do
93
- values = {}
94
- PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS.keys.each do |key|
95
- values[key] = 'default value'
96
- end
97
- values
98
- end
99
-
100
91
  before do
101
92
  @settings = Puppet::Settings.new
102
93
  @settings.define_settings(:main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS)
@@ -104,7 +95,7 @@ describe Puppet::Settings do
104
95
 
105
96
  it "should fail if the app defaults hash is missing any required values" do
106
97
  expect {
107
- @settings.initialize_app_defaults(default_values.reject { |key, _| key == :confdir })
98
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.reject { |key, _| key == :confdir })
108
99
  }.to raise_error(Puppet::Settings::SettingsError)
109
100
  end
110
101
 
@@ -112,7 +103,7 @@ describe Puppet::Settings do
112
103
  # case behaviors / uses. However, until that time... we need to make sure that our private run_mode=
113
104
  # setter method gets properly called during app initialization.
114
105
  it "sets the preferred run mode when initializing the app defaults" do
115
- @settings.initialize_app_defaults(default_values.merge(:run_mode => :server))
106
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.merge(:run_mode => :server))
116
107
 
117
108
  expect(@settings.preferred_run_mode).to eq(:server)
118
109
  end
@@ -121,7 +112,7 @@ describe Puppet::Settings do
121
112
  # initialize_app_defaults is called in spec_helper, before we even
122
113
  # get here, but call it here to make it explicit what we're trying
123
114
  # to do.
124
- @settings.initialize_app_defaults(default_values)
115
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES)
125
116
 
126
117
  Puppet::Settings::REQUIRED_APP_SETTINGS.each do |key|
127
118
  expect(File).to exist(File.dirname(Puppet[key]))
@@ -148,6 +139,7 @@ describe Puppet::Settings do
148
139
  end.to_not raise_error
149
140
  end
150
141
  end
142
+
151
143
  describe "if no interpolation error" do
152
144
  it "should not raise an error" do
153
145
  hook_values = []
@@ -177,6 +169,7 @@ describe Puppet::Settings do
177
169
  @settings.send(:call_hooks_deferred_to_application_initialization, options)
178
170
  end.to raise_error(Puppet::Settings::InterpolationError)
179
171
  end
172
+
180
173
  it "should contain the setting name in error message" do
181
174
  hook_values = []
182
175
  @settings.define_settings(
@@ -193,6 +186,7 @@ describe Puppet::Settings do
193
186
  end.to raise_error(Puppet::Settings::InterpolationError, /badhook/)
194
187
  end
195
188
  end
189
+
196
190
  describe "if no interpolation error" do
197
191
  it "should not raise an error" do
198
192
  hook_values = []
@@ -397,122 +391,320 @@ describe Puppet::Settings do
397
391
  end
398
392
 
399
393
  describe "call_hook" do
394
+ let(:config_file) { tmpfile('config') }
395
+
396
+ before :each do
397
+ # We can't specify the config file to read from using `Puppet[:config] =`
398
+ # or pass it as an arg to Puppet.initialize_global_settings, because
399
+ # both of those will set the value on the `Puppet.settings` instance
400
+ # which is different from the `@settings` instance created in the test.
401
+ # Instead, we define a `:config` setting and set its default value to
402
+ # the `config_file` temp file, and then access the `config_file` within
403
+ # each test.
404
+ @settings.define_settings(:main, :config => { :type => :file, :desc => "config file", :default => config_file })
405
+ end
406
+
400
407
  Puppet::Settings::StringSetting.available_call_hook_values.each do |val|
401
408
  describe "when :#{val}" do
402
409
  describe "and definition invalid" do
403
410
  it "should raise error if no hook defined" do
404
411
  expect do
405
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :call_hook => val})
412
+ @settings.define_settings(:section, :setting => {:default => "yay", :desc => "boo", :call_hook => val})
406
413
  end.to raise_error(ArgumentError, /no :hook/)
407
414
  end
415
+
408
416
  it "should include the setting name in the error message" do
409
417
  expect do
410
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :call_hook => val})
411
- end.to raise_error(ArgumentError, /for :hooker/)
418
+ @settings.define_settings(:section, :setting => {:default => "yay", :desc => "boo", :call_hook => val})
419
+ end.to raise_error(ArgumentError, /for :setting/)
412
420
  end
413
421
  end
422
+
414
423
  describe "and definition valid" do
415
424
  before(:each) do
416
425
  hook_values = []
417
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :call_hook => val, :hook => lambda { |v| hook_values << v }})
426
+ @settings.define_settings(:section, :setting => {:default => "yay", :desc => "boo", :call_hook => val, :hook => lambda { |v| hook_values << v }})
418
427
  end
419
428
 
420
429
  it "should call the hook when value written" do
421
- expect(@settings.setting(:hooker)).to receive(:handle).with("something").once
422
- @settings[:hooker] = "something"
430
+ expect(@settings.setting(:setting)).to receive(:handle).with("something").once
431
+ @settings[:setting] = "something"
423
432
  end
424
433
  end
425
434
  end
426
435
  end
427
436
 
428
437
  it "should have a default value of :on_write_only" do
429
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :hook => lambda { |v| hook_values << v }})
430
- expect(@settings.setting(:hooker).call_hook).to eq(:on_write_only)
438
+ @settings.define_settings(:section, :setting => {:default => "yay", :desc => "boo", :hook => lambda { |v| hook_values << v }})
439
+ expect(@settings.setting(:setting).call_hook).to eq(:on_write_only)
431
440
  end
432
441
 
433
442
  describe "when nil" do
434
443
  it "should generate a warning" do
435
444
  expect(Puppet).to receive(:warning)
436
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :call_hook => nil, :hook => lambda { |v| hook_values << v }})
445
+ @settings.define_settings(:section, :setting => {:default => "yay", :desc => "boo", :call_hook => nil, :hook => lambda { |v| hook_values << v }})
437
446
  end
447
+
438
448
  it "should use default" do
439
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :call_hook => nil, :hook => lambda { |v| hook_values << v }})
440
- expect(@settings.setting(:hooker).call_hook).to eq(:on_write_only)
449
+ @settings.define_settings(:section, :setting => {:default => "yay", :desc => "boo", :call_hook => nil, :hook => lambda { |v| hook_values << v }})
450
+ expect(@settings.setting(:setting).call_hook).to eq(:on_write_only)
441
451
  end
442
452
  end
443
453
 
444
454
  describe "when invalid" do
445
455
  it "should raise an error" do
446
456
  expect do
447
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :call_hook => :foo, :hook => lambda { |v| hook_values << v }})
457
+ @settings.define_settings(:section, :setting => {:default => "yay", :desc => "boo", :call_hook => :foo, :hook => lambda { |v| hook_values << v }})
448
458
  end.to raise_error(ArgumentError, /invalid.*call_hook/i)
449
459
  end
450
460
  end
451
461
 
462
+ describe "when :on_write_only" do
463
+ it "returns its hook type" do
464
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :hook => lambda { |_| }})
465
+
466
+ expect(@settings.setting(:setting).call_hook).to eq(:on_write_only)
467
+ end
468
+
469
+ it "should not call the hook at definition" do
470
+ hook_values = []
471
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :hook => lambda { |v| hook_values << v }})
472
+
473
+ expect(hook_values).to eq(%w[])
474
+ end
475
+
476
+ it "calls the hook when initializing global defaults with the value from the `main` section" do
477
+ hook_values = []
478
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :hook => lambda { |v| hook_values << v }})
479
+
480
+ File.write(config_file, <<~END)
481
+ [main]
482
+ setting=in_main
483
+ END
484
+ @settings.initialize_global_settings
485
+
486
+ expect(@settings[:setting]).to eq('in_main')
487
+ expect(hook_values).to eq(%w[in_main])
488
+ end
489
+
490
+ it "doesn't call the hook when initializing app defaults" do
491
+ hook_values = []
492
+ @settings.define_settings(:main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS)
493
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :hook => lambda { |v| hook_values << v }})
494
+
495
+ File.write(config_file, <<~END)
496
+ [main]
497
+ setting=in_main
498
+ [agent]
499
+ setting=in_agent
500
+ END
501
+ @settings.initialize_global_settings
502
+
503
+ hook_values.clear
504
+
505
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES)
506
+
507
+ expect(@settings[:setting]).to eq('in_main')
508
+ expect(hook_values).to eq(%w[])
509
+ end
510
+
511
+ it "doesn't call the hook with value from a section that matches the run_mode" do
512
+ hook_values = []
513
+ @settings.define_settings(:main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS)
514
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :hook => lambda { |v| hook_values << v }})
515
+
516
+ File.write(config_file, <<~END)
517
+ [main]
518
+ setting=in_main
519
+ [agent]
520
+ setting=in_agent
521
+ END
522
+ @settings.initialize_global_settings
523
+
524
+ hook_values.clear
525
+
526
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.merge(:run_mode => :agent))
527
+
528
+ expect(@settings[:setting]).to eq('in_agent')
529
+ expect(hook_values).to eq(%w[])
530
+ end
531
+ end
532
+
452
533
  describe "when :on_define_and_write" do
453
- it "should call the hook at definition" do
534
+ it "returns its hook type" do
535
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_define_and_write, :hook => lambda { |_| }})
536
+
537
+ expect(@settings.setting(:setting).call_hook).to eq(:on_define_and_write)
538
+ end
539
+
540
+ it "should call the hook at definition with the default value" do
541
+ hook_values = []
542
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_define_and_write, :hook => lambda { |v| hook_values << v }})
543
+
544
+ expect(hook_values).to eq(%w[yay])
545
+ end
546
+
547
+ it "calls the hook when initializing global defaults with the value from the `main` section" do
454
548
  hook_values = []
455
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :call_hook => :on_define_and_write, :hook => lambda { |v| hook_values << v }})
456
- expect(@settings.setting(:hooker).call_hook).to eq(:on_define_and_write)
457
- expect(hook_values).to eq(%w{yay})
549
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_define_and_write, :hook => lambda { |v| hook_values << v }})
550
+
551
+ File.write(config_file, <<~END)
552
+ [main]
553
+ setting=in_main
554
+ END
555
+ @settings.initialize_global_settings
556
+
557
+ expect(@settings[:setting]).to eq('in_main')
558
+ expect(hook_values).to eq(%w[yay in_main])
559
+ end
560
+
561
+ it "doesn't call the hook when initializing app defaults" do
562
+ hook_values = []
563
+ @settings.define_settings(:main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS)
564
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_define_and_write, :hook => lambda { |v| hook_values << v }})
565
+
566
+ File.write(config_file, <<~END)
567
+ [main]
568
+ setting=in_main
569
+ [agent]
570
+ setting=in_agent
571
+ END
572
+ @settings.initialize_global_settings
573
+
574
+ hook_values.clear
575
+
576
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES)
577
+
578
+ expect(@settings[:setting]).to eq('in_main')
579
+ expect(hook_values).to eq([])
580
+ end
581
+
582
+ it "doesn't call the hook with value from a section that matches the run_mode" do
583
+ hook_values = []
584
+ @settings.define_settings(:main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS)
585
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_define_and_write, :hook => lambda { |v| hook_values << v }})
586
+
587
+ File.write(config_file, <<~END)
588
+ [main]
589
+ setting=in_main
590
+ [agent]
591
+ setting=in_agent
592
+ END
593
+
594
+ @settings.initialize_global_settings
595
+
596
+ hook_values.clear
597
+
598
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.merge(:run_mode => :agent))
599
+
600
+ # The correct value is returned
601
+ expect(@settings[:setting]).to eq('in_agent')
602
+
603
+ # but the hook is never called, seems like a bug!
604
+ expect(hook_values).to eq([])
458
605
  end
459
606
  end
460
607
 
461
608
  describe "when :on_initialize_and_write" do
462
- before(:each) do
463
- @hook_values = []
464
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :call_hook => :on_initialize_and_write, :hook => lambda { |v| @hook_values << v }})
609
+ it "returns its hook type" do
610
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_initialize_and_write, :hook => lambda { |_| }})
611
+
612
+ expect(@settings.setting(:setting).call_hook).to eq(:on_initialize_and_write)
465
613
  end
466
614
 
467
615
  it "should not call the hook at definition" do
468
- expect(@hook_values).to eq([])
469
- expect(@hook_values).not_to eq(%w{yay})
616
+ hook_values = []
617
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_initialize_and_write, :hook => lambda { |v| hook_values << v }})
618
+ expect(hook_values).to eq([])
470
619
  end
471
620
 
472
- it "should call the hook at initialization" do
473
- app_defaults = {}
474
- Puppet::Settings::REQUIRED_APP_SETTINGS.each do |key|
475
- app_defaults[key] = "foo"
476
- end
477
- app_defaults[:run_mode] = :user
621
+ it "calls the hook when initializing global defaults with the value from the `main` section" do
622
+ hook_values = []
623
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_initialize_and_write, :hook => lambda { |v| hook_values << v }})
624
+
625
+ File.write(config_file, <<~END)
626
+ [main]
627
+ setting=in_main
628
+ END
629
+ @settings.initialize_global_settings
630
+
631
+ expect(@settings[:setting]).to eq('in_main')
632
+ expect(hook_values).to eq(%w[in_main])
633
+ end
634
+
635
+ it "calls the hook when initializing app defaults" do
636
+ hook_values = []
478
637
  @settings.define_settings(:main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS)
638
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_initialize_and_write, :hook => lambda { |v| hook_values << v }})
639
+
640
+ File.write(config_file, <<~END)
641
+ [main]
642
+ setting=in_main
643
+ [agent]
644
+ setting=in_agent
645
+ END
646
+ @settings.initialize_global_settings
647
+
648
+ hook_values.clear
649
+
650
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES)
651
+
652
+ expect(@settings[:setting]).to eq('in_main')
653
+ expect(hook_values).to eq(%w[in_main])
654
+ end
655
+
656
+ it "calls the hook with the overridden value from a section that matches the run_mode" do
657
+ hook_values = []
658
+ @settings.define_settings(:main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS)
659
+ @settings.define_settings(:main, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_initialize_and_write, :hook => lambda { |v| hook_values << v }})
660
+
661
+ File.write(config_file, <<~END)
662
+ [main]
663
+ setting=in_main
664
+ [agent]
665
+ setting=in_agent
666
+ END
667
+ @settings.initialize_global_settings
668
+
669
+ hook_values.clear
479
670
 
480
- expect(@settings.setting(:hooker)).to receive(:handle).with("yay").once
671
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.merge(:run_mode => :agent))
481
672
 
482
- @settings.initialize_app_defaults app_defaults
673
+ expect(@settings[:setting]).to eq('in_agent')
674
+ expect(hook_values).to eq(%w[in_agent])
483
675
  end
484
676
  end
485
677
  end
486
678
 
487
679
  it "should call passed blocks when values are set" do
488
680
  values = []
489
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :hook => lambda { |v| values << v }})
681
+ @settings.define_settings(:section, :setting => {:default => "yay", :desc => "boo", :hook => lambda { |v| values << v }})
490
682
  expect(values).to eq([])
491
683
 
492
- @settings[:hooker] = "something"
684
+ @settings[:setting] = "something"
493
685
  expect(values).to eq(%w{something})
494
686
  end
495
687
 
496
688
  it "should call passed blocks when values are set via the command line" do
497
689
  values = []
498
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :hook => lambda { |v| values << v }})
690
+ @settings.define_settings(:section, :setting => {:default => "yay", :desc => "boo", :hook => lambda { |v| values << v }})
499
691
  expect(values).to eq([])
500
692
 
501
- @settings.handlearg("--hooker", "yay")
693
+ @settings.handlearg("--setting", "yay")
502
694
 
503
695
  expect(values).to eq(%w{yay})
504
696
  end
505
697
 
506
698
  it "should provide an option to call passed blocks during definition" do
507
699
  values = []
508
- @settings.define_settings(:section, :hooker => {:default => "yay", :desc => "boo", :call_hook => :on_define_and_write, :hook => lambda { |v| values << v }})
700
+ @settings.define_settings(:section, :setting => {:default => "yay", :desc => "boo", :call_hook => :on_define_and_write, :hook => lambda { |v| values << v }})
509
701
  expect(values).to eq(%w{yay})
510
702
  end
511
703
 
512
704
  it "should pass the fully interpolated value to the hook when called on definition" do
513
705
  values = []
514
706
  @settings.define_settings(:section, :one => { :default => "test", :desc => "a" })
515
- @settings.define_settings(:section, :hooker => {:default => "$one/yay", :desc => "boo", :call_hook => :on_define_and_write, :hook => lambda { |v| values << v }})
707
+ @settings.define_settings(:section, :setting => {:default => "$one/yay", :desc => "boo", :call_hook => :on_define_and_write, :hook => lambda { |v| values << v }})
516
708
  expect(values).to eq(%w{test/yay})
517
709
  end
518
710
 
@@ -561,12 +753,8 @@ describe Puppet::Settings do
561
753
  end
562
754
 
563
755
  it "setting a value to nil causes it to return to its default" do
564
- default_values = { :one => "skipped value" }
565
- [:logdir, :confdir, :codedir, :vardir].each do |key|
566
- default_values[key] = 'default value'
567
- end
568
756
  @settings.define_settings :main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS
569
- @settings.initialize_app_defaults(default_values)
757
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.merge(:one => "skipped value"))
570
758
  @settings[:one] = "value will disappear"
571
759
 
572
760
  @settings[:one] = nil
@@ -627,13 +815,14 @@ describe Puppet::Settings do
627
815
  end
628
816
 
629
817
  describe "when choosing which value to return" do
818
+ let(:config_file) { tmpfile('settings') }
819
+
630
820
  before do
631
821
  @settings = Puppet::Settings.new
632
822
  @settings.define_settings :section,
633
- :config => { :type => :file, :default => "/my/file", :desc => "a" },
823
+ :config => { :type => :file, :default => config_file, :desc => "a" },
634
824
  :one => { :default => "ONE", :desc => "a" },
635
825
  :two => { :default => "TWO", :desc => "b" }
636
- allow(Puppet::FileSystem).to receive(:exist?).and_return(true)
637
826
  @settings.preferred_run_mode = :agent
638
827
  end
639
828
 
@@ -642,18 +831,16 @@ describe Puppet::Settings do
642
831
  end
643
832
 
644
833
  it "should return values set on the cli before values set in the configuration file" do
645
- text = "[main]\none = fileval\n"
646
- allow(@settings).to receive(:read_file).and_return(text)
834
+ File.write(config_file, "[main]\none = fileval\n")
647
835
  @settings.handlearg("--one", "clival")
648
- @settings.send(:parse_config_files)
836
+ @settings.initialize_global_settings
649
837
 
650
838
  expect(@settings[:one]).to eq("clival")
651
839
  end
652
840
 
653
841
  it "should return values set in the mode-specific section before values set in the main section" do
654
- text = "[main]\none = mainval\n[agent]\none = modeval\n"
655
- allow(@settings).to receive(:read_file).and_return(text)
656
- @settings.send(:parse_config_files)
842
+ File.write(config_file, "[main]\none = mainval\n[agent]\none = modeval\n")
843
+ @settings.initialize_global_settings
657
844
 
658
845
  expect(@settings[:one]).to eq("modeval")
659
846
  end
@@ -663,17 +850,15 @@ describe Puppet::Settings do
663
850
  before(:each) { @settings.preferred_run_mode = run_mode }
664
851
 
665
852
  it "returns values set in the 'master' section if the 'server' section does not exist" do
666
- text = "[main]\none = mainval\n[master]\none = modeval\n"
667
- allow(@settings).to receive(:read_file).and_return(text)
668
- @settings.send(:parse_config_files)
853
+ File.write(config_file, "[main]\none = mainval\n[master]\none = modeval\n")
854
+ @settings.initialize_global_settings
669
855
 
670
856
  expect(@settings[:one]).to eq("modeval")
671
857
  end
672
858
 
673
859
  it "prioritizes values set in the 'server' section if set" do
674
- text = "[main]\none = mainval\n[server]\none = serverval\n[master]\none = masterval\n"
675
- allow(@settings).to receive(:read_file).and_return(text)
676
- @settings.send(:parse_config_files)
860
+ File.write(config_file, "[main]\none = mainval\n[server]\none = serverval\n[master]\none = masterval\n")
861
+ @settings.initialize_global_settings
677
862
 
678
863
  expect(@settings[:one]).to eq("serverval")
679
864
  end
@@ -681,9 +866,9 @@ describe Puppet::Settings do
681
866
  end
682
867
 
683
868
  it "should not return values outside of its search path" do
684
- text = "[other]\none = oval\n"
685
- allow(@settings).to receive(:read_file).and_return(text)
686
- @settings.send(:parse_config_files)
869
+ File.write(config_file, "[other]\none = oval\n")
870
+ @settings.initialize_global_settings
871
+
687
872
  expect(@settings[:one]).to eq("ONE")
688
873
  end
689
874
 
@@ -705,7 +890,7 @@ describe Puppet::Settings do
705
890
  expect(Puppet::FileSystem).to receive(:exist?).with(main_config_file_default_location).and_return(false)
706
891
  expect(Puppet::FileSystem).not_to receive(:exist?).with(user_config_file_default_location)
707
892
 
708
- @settings.send(:parse_config_files)
893
+ @settings.initialize_global_settings
709
894
  end
710
895
  end
711
896
 
@@ -715,7 +900,7 @@ describe Puppet::Settings do
715
900
 
716
901
  expect(Puppet::FileSystem).to receive(:exist?).with(user_config_file_default_location).and_return(false)
717
902
 
718
- @settings.send(:parse_config_files)
903
+ @settings.initialize_global_settings
719
904
  end
720
905
  end
721
906
 
@@ -724,7 +909,7 @@ describe Puppet::Settings do
724
909
  expect(Puppet::FileSystem).to receive(:exist?).with(user_config_file_default_location).and_return(true)
725
910
  expect(@settings).to receive(:read_file).and_raise('Permission denied')
726
911
 
727
- expect{ @settings.send(:parse_config_files) }.to raise_error(RuntimeError, /Could not load #{user_config_file_default_location}: Permission denied/)
912
+ expect{ @settings.initialize_global_settings }.to raise_error(RuntimeError, /Could not load #{user_config_file_default_location}: Permission denied/)
728
913
  end
729
914
 
730
915
  it "does not fail if the file is not readable and when `require_config` is false" do
@@ -734,7 +919,7 @@ describe Puppet::Settings do
734
919
  expect(@settings).not_to receive(:parse_config)
735
920
  expect(Puppet).to receive(:log_exception)
736
921
 
737
- expect{ @settings.send(:parse_config_files, false) }.not_to raise_error
922
+ expect{ @settings.initialize_global_settings([], false) }.not_to raise_error
738
923
  end
739
924
 
740
925
  it "reads the file if it is readable" do
@@ -742,7 +927,7 @@ describe Puppet::Settings do
742
927
  expect(@settings).to receive(:read_file).and_return('server = host.string')
743
928
  expect(@settings).to receive(:parse_config)
744
929
 
745
- @settings.send(:parse_config_files)
930
+ @settings.initialize_global_settings
746
931
  end
747
932
  end
748
933
 
@@ -751,7 +936,7 @@ describe Puppet::Settings do
751
936
  expect(Puppet::FileSystem).to receive(:exist?).with(user_config_file_default_location).and_return(false)
752
937
  expect(@settings).not_to receive(:parse_config)
753
938
 
754
- @settings.send(:parse_config_files)
939
+ @settings.initialize_global_settings
755
940
  end
756
941
  end
757
942
  end
@@ -761,43 +946,41 @@ describe Puppet::Settings do
761
946
  @settings = Puppet::Settings.new
762
947
  allow(@settings).to receive(:service_user_available?).and_return(true)
763
948
  allow(@settings).to receive(:service_group_available?).and_return(true)
764
- @file = make_absolute("/some/file")
765
- @userconfig = make_absolute("/test/userconfigfile")
949
+ @file = tmpfile("somefile")
766
950
  @settings.define_settings :section, :user => { :default => "suser", :desc => "doc" }, :group => { :default => "sgroup", :desc => "doc" }
767
951
  @settings.define_settings :section,
768
952
  :config => { :type => :file, :default => @file, :desc => "eh" },
769
953
  :one => { :default => "ONE", :desc => "a" },
770
954
  :two => { :default => "$one TWO", :desc => "b" },
771
955
  :three => { :default => "$one $two THREE", :desc => "c" }
772
- allow(@settings).to receive(:user_config_file).and_return(@userconfig)
773
- allow(Puppet::FileSystem).to receive(:exist?).with(@file).and_return(true)
774
- allow(Puppet::FileSystem).to receive(:exist?).with(@userconfig).and_return(false)
956
+
957
+ userconfig = tmpfile("userconfig")
958
+ allow(@settings).to receive(:user_config_file).and_return(userconfig)
775
959
  end
776
960
 
777
961
  it "should not ignore the report setting" do
778
962
  @settings.define_settings :section, :report => { :default => "false", :desc => "a" }
779
- # This is needed in order to make sure we pass on windows
780
- myfile = File.expand_path(@file)
781
- @settings[:config] = myfile
782
- text = <<-CONF
963
+ File.write(@file, <<~CONF)
783
964
  [puppetd]
784
- report=true
965
+ report=true
785
966
  CONF
786
- expect(Puppet::FileSystem).to receive(:exist?).with(myfile).and_return(true)
787
- expect(@settings).to receive(:read_file).and_return(text)
788
- @settings.send(:parse_config_files)
967
+
968
+ @settings.initialize_global_settings
969
+
789
970
  expect(@settings[:report]).to be_truthy
790
971
  end
791
972
 
792
973
  it "should use its current ':config' value for the file to parse" do
793
- myfile = make_absolute("/my/file")
794
- @settings[:config] = myfile
795
-
796
- expect(Puppet::FileSystem).to receive(:exist?).with(myfile).and_return(true)
974
+ myfile = tmpfile('myfile')
975
+ File.write(myfile, <<~CONF)
976
+ [main]
977
+ one=myfile
978
+ CONF
797
979
 
798
- expect(Puppet::FileSystem).to receive(:read).with(myfile, :encoding => 'utf-8').and_return("[main]")
980
+ @settings[:config] = myfile
981
+ @settings.initialize_global_settings
799
982
 
800
- @settings.send(:parse_config_files)
983
+ expect(@settings[:one]).to eq('myfile')
801
984
  end
802
985
 
803
986
  it "should not try to parse non-existent files" do
@@ -805,42 +988,50 @@ describe Puppet::Settings do
805
988
 
806
989
  expect(File).not_to receive(:read).with(@file)
807
990
 
808
- @settings.send(:parse_config_files)
991
+ @settings.initialize_global_settings
809
992
  end
810
993
 
811
994
  it "should return values set in the configuration file" do
812
- text = "[main]
813
- one = fileval
814
- "
815
- expect(@settings).to receive(:read_file).and_return(text)
816
- @settings.send(:parse_config_files)
995
+ File.write(@file, <<~CONF)
996
+ [main]
997
+ one = fileval
998
+ CONF
999
+
1000
+ @settings.initialize_global_settings
817
1001
  expect(@settings[:one]).to eq("fileval")
818
1002
  end
819
1003
 
820
1004
  #484 - this should probably be in the regression area
821
1005
  it "should not throw an exception on unknown parameters" do
822
- text = "[main]\nnosuchparam = mval\n"
823
- expect(@settings).to receive(:read_file).and_return(text)
824
- expect { @settings.send(:parse_config_files) }.not_to raise_error
1006
+ File.write(@file, <<~CONF)
1007
+ [main]
1008
+ nosuchparam = mval
1009
+ CONF
1010
+
1011
+ expect { @settings.initialize_global_settings }.not_to raise_error
825
1012
  end
826
1013
 
827
1014
  it "should convert booleans in the configuration file into Ruby booleans" do
828
- text = "[main]
829
- one = true
830
- two = false
831
- "
832
- expect(@settings).to receive(:read_file).and_return(text)
833
- @settings.send(:parse_config_files)
1015
+ File.write(@file, <<~CONF)
1016
+ [main]
1017
+ one = true
1018
+ two = false
1019
+ CONF
1020
+
1021
+ @settings.initialize_global_settings
1022
+
834
1023
  expect(@settings[:one]).to eq(true)
835
1024
  expect(@settings[:two]).to eq(false)
836
1025
  end
837
1026
 
838
1027
  it "should convert integers in the configuration file into Ruby Integers" do
839
- text = "[main]
840
- one = 65
841
- "
842
- expect(@settings).to receive(:read_file).and_return(text)
843
- @settings.send(:parse_config_files)
1028
+ File.write(@file, <<~CONF)
1029
+ [main]
1030
+ one = 65
1031
+ CONF
1032
+
1033
+ @settings.initialize_global_settings
1034
+
844
1035
  expect(@settings[:one]).to eq(65)
845
1036
  end
846
1037
 
@@ -871,25 +1062,21 @@ describe Puppet::Settings do
871
1062
  end
872
1063
 
873
1064
  it "should support loading metadata (owner, group, or mode) from a run_mode section in the configuration file" do
874
- default_values = {}
875
- PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS.keys.each do |key|
876
- default_values[key] = 'default value'
877
- end
878
1065
  @settings.define_settings :main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS
879
1066
  @settings.define_settings :server, :myfile => { :type => :file, :default => make_absolute("/myfile"), :desc => "a" }
880
1067
 
881
1068
  otherfile = make_absolute("/other/file")
882
- text = "[server]
883
- myfile = #{otherfile} {mode = 664}
884
- "
885
- expect(@settings).to receive(:read_file).and_return(text)
1069
+ File.write(@file, <<~CONF)
1070
+ [server]
1071
+ myfile = #{otherfile} {mode = 664}
1072
+ CONF
886
1073
 
887
1074
  # will start initialization as user
888
1075
  expect(@settings.preferred_run_mode).to eq(:user)
889
- @settings.send(:parse_config_files)
1076
+ @settings.initialize_global_settings
890
1077
 
891
1078
  # change app run_mode to server
892
- @settings.initialize_app_defaults(default_values.merge(:run_mode => :server))
1079
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.merge(:run_mode => :server))
893
1080
  expect(@settings.preferred_run_mode).to eq(:server)
894
1081
 
895
1082
  # initializing the app should have reloaded the metadata based on run_mode
@@ -897,30 +1084,170 @@ describe Puppet::Settings do
897
1084
  expect(metadata(@settings.setting(:myfile))).to eq({:mode => "664"})
898
1085
  end
899
1086
 
900
- it "does not use the metadata from the same setting in a different section" do
901
- default_values = {}
902
- PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS.keys.each do |key|
903
- default_values[key] = 'default value'
1087
+ context "when setting serverport and masterport" do
1088
+ before(:each) do
1089
+ @settings.define_settings :main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS
1090
+ @settings.define_settings :server, :masterport => { :desc => "a", :default => 1000 }
1091
+ @settings.define_settings :server, :serverport => { :type => :alias, :alias_for => :masterport }
1092
+ @settings.define_settings :server, :ca_port => { :desc => "a", :default => "$serverport" }
1093
+ @settings.define_settings :server, :report_port => { :desc => "a", :default => "$serverport" }
1094
+
1095
+ config_file = tmpfile('config')
1096
+ @settings[:config] = config_file
1097
+ File.write(config_file, text)
1098
+
1099
+ @settings.initialize_global_settings
1100
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.merge(:run_mode => :agent))
1101
+ expect(@settings.preferred_run_mode).to eq(:agent)
1102
+ end
1103
+
1104
+ context 'with serverport in main and masterport in agent' do
1105
+ let(:text) do
1106
+ "[main]
1107
+ serverport = 444
1108
+ [agent]
1109
+ masterport = 445
1110
+ "
1111
+ end
1112
+
1113
+ it { expect(@settings[:serverport]).to eq(444) }
1114
+ it { expect(@settings[:ca_port]).to eq("444") }
1115
+ it { expect(@settings[:report_port]).to eq("444") }
1116
+ it { expect(@settings[:masterport]).to eq(445) }
1117
+ end
1118
+
1119
+ context 'with serverport and masterport in main' do
1120
+ let(:text) do
1121
+ "[main]
1122
+ serverport = 445
1123
+ masterport = 444
1124
+ "
1125
+ end
1126
+
1127
+ it { expect(@settings[:serverport]).to eq(445) }
1128
+ it { expect(@settings[:ca_port]).to eq("445") }
1129
+ it { expect(@settings[:report_port]).to eq("445") }
1130
+ it { expect(@settings[:masterport]).to eq(444) }
1131
+ end
1132
+
1133
+ context 'with serverport and masterport in agent' do
1134
+ let(:text) do
1135
+ "[agent]
1136
+ serverport = 445
1137
+ masterport = 444
1138
+ "
1139
+ end
1140
+
1141
+ it { expect(@settings[:serverport]).to eq(445) }
1142
+ it { expect(@settings[:ca_port]).to eq("445") }
1143
+ it { expect(@settings[:report_port]).to eq("445") }
1144
+ it { expect(@settings[:masterport]).to eq(444) }
1145
+ end
1146
+
1147
+ context 'with both serverport and masterport in main and agent' do
1148
+ let(:text) do
1149
+ "[main]
1150
+ serverport = 447
1151
+ masterport = 442
1152
+ [agent]
1153
+ serverport = 445
1154
+ masterport = 444
1155
+ "
1156
+ end
1157
+
1158
+ it { expect(@settings[:serverport]).to eq(445) }
1159
+ it { expect(@settings[:ca_port]).to eq("445") }
1160
+ it { expect(@settings[:report_port]).to eq("445") }
1161
+ it { expect(@settings[:masterport]).to eq(444) }
1162
+ end
1163
+
1164
+ context 'with serverport in agent and masterport in main' do
1165
+ let(:text) do
1166
+ "[agent]
1167
+ serverport = 444
1168
+ [main]
1169
+ masterport = 445
1170
+ "
1171
+ end
1172
+
1173
+ it { expect(@settings[:serverport]).to eq(444) }
1174
+ it { expect(@settings[:ca_port]).to eq("444") }
1175
+ it { expect(@settings[:report_port]).to eq("444") }
1176
+ it { expect(@settings[:masterport]).to eq(445) }
1177
+ end
1178
+
1179
+ context 'with masterport in main' do
1180
+ let(:text) do
1181
+ "[main]
1182
+ masterport = 445
1183
+ "
1184
+ end
1185
+
1186
+ it { expect(@settings[:serverport]).to eq(445) }
1187
+ it { expect(@settings[:ca_port]).to eq("445") }
1188
+ it { expect(@settings[:report_port]).to eq("445") }
1189
+ it { expect(@settings[:masterport]).to eq(445) }
1190
+ end
1191
+
1192
+ context 'with masterport in agent' do
1193
+ let(:text) do
1194
+ "[agent]
1195
+ masterport = 445
1196
+ "
1197
+ end
1198
+
1199
+ it { expect(@settings[:serverport]).to eq(445) }
1200
+ it { expect(@settings[:ca_port]).to eq("445") }
1201
+ it { expect(@settings[:report_port]).to eq("445") }
1202
+ it { expect(@settings[:masterport]).to eq(445) }
1203
+ end
1204
+
1205
+ context 'with serverport in agent' do
1206
+ let(:text) do
1207
+ "[agent]
1208
+ serverport = 445
1209
+ "
1210
+ end
1211
+
1212
+ it { expect(@settings[:serverport]).to eq(445) }
1213
+ it { expect(@settings[:masterport]).to eq(1000) }
1214
+ it { expect(@settings[:ca_port]).to eq("445") }
1215
+ it { expect(@settings[:report_port]).to eq("445") }
1216
+ end
1217
+
1218
+ context 'with serverport in main' do
1219
+ let(:text) do
1220
+ "[main]
1221
+ serverport = 445
1222
+ "
1223
+ end
1224
+
1225
+ it { expect(@settings[:serverport]).to eq(445) }
1226
+ it { expect(@settings[:masterport]).to eq(1000) }
1227
+ it { expect(@settings[:ca_port]).to eq("445") }
1228
+ it { expect(@settings[:report_port]).to eq("445") }
904
1229
  end
1230
+ end
905
1231
 
1232
+ it "does not use the metadata from the same setting in a different section" do
906
1233
  file = make_absolute("/file")
907
1234
  default_mode = "0600"
908
1235
  @settings.define_settings :main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS
909
1236
  @settings.define_settings :server, :myfile => { :type => :file, :default => file, :desc => "a", :mode => default_mode }
910
1237
 
911
- text = "[server]
912
- myfile = #{file}/foo
913
- [agent]
914
- myfile = #{file} {mode = 664}
915
- "
916
- expect(@settings).to receive(:read_file).and_return(text)
1238
+ File.write(@file, <<~CONF)
1239
+ [server]
1240
+ myfile = #{file}/foo
1241
+ [agent]
1242
+ myfile = #{file} {mode = 664}
1243
+ CONF
917
1244
 
918
1245
  # will start initialization as user
919
1246
  expect(@settings.preferred_run_mode).to eq(:user)
920
- @settings.send(:parse_config_files)
1247
+ @settings.initialize_global_settings
921
1248
 
922
1249
  # change app run_mode to server
923
- @settings.initialize_app_defaults(default_values.merge(:run_mode => :server))
1250
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.merge(:run_mode => :server))
924
1251
  expect(@settings.preferred_run_mode).to eq(:server)
925
1252
 
926
1253
  # initializing the app should have reloaded the metadata based on run_mode
@@ -932,11 +1259,12 @@ describe Puppet::Settings do
932
1259
  values = []
933
1260
  @settings.define_settings :section, :mysetting => {:default => "defval", :desc => "a", :hook => proc { |v| values << v }}
934
1261
 
935
- text = "[main]
936
- mysetting = setval
937
- "
938
- expect(@settings).to receive(:read_file).and_return(text)
939
- @settings.send(:parse_config_files)
1262
+ File.write(@file, <<~CONF)
1263
+ [main]
1264
+ mysetting = setval
1265
+ CONF
1266
+ @settings.initialize_global_settings
1267
+
940
1268
  expect(values).to eq(["setval"])
941
1269
  end
942
1270
 
@@ -944,13 +1272,14 @@ describe Puppet::Settings do
944
1272
  values = []
945
1273
  @settings.define_settings :section, :mysetting => {:default => "defval", :desc => "a", :hook => proc { |v| values << v }}
946
1274
 
947
- text = "[user]
948
- mysetting = setval
949
- [main]
950
- mysetting = other
951
- "
952
- expect(@settings).to receive(:read_file).and_return(text)
953
- @settings.send(:parse_config_files)
1275
+ File.write(@file, <<~CONF)
1276
+ [user]
1277
+ mysetting = setval
1278
+ [main]
1279
+ mysetting = other
1280
+ CONF
1281
+ @settings.initialize_global_settings
1282
+
954
1283
  expect(values).to eq(["setval"])
955
1284
  end
956
1285
 
@@ -959,11 +1288,12 @@ describe Puppet::Settings do
959
1288
  @settings.define_settings :section, :base => {:default => "yay", :desc => "a", :hook => proc { |v| values << v }}
960
1289
  @settings.define_settings :section, :mysetting => {:default => "defval", :desc => "a", :hook => proc { |v| values << v }}
961
1290
 
962
- text = "[main]
963
- mysetting = $base/setval
964
- "
965
- expect(@settings).to receive(:read_file).and_return(text)
966
- @settings.send(:parse_config_files)
1291
+ File.write(@file, <<~CONF)
1292
+ [main]
1293
+ mysetting = $base/setval
1294
+ CONF
1295
+ @settings.initialize_global_settings
1296
+
967
1297
  expect(values).to eq(["yay/setval"])
968
1298
  end
969
1299
 
@@ -973,23 +1303,25 @@ describe Puppet::Settings do
973
1303
  :hook => proc { |v| hook_invoked = true },
974
1304
  :call_hook => :on_initialize_and_write, }
975
1305
 
1306
+ # This test relies on `confdir` defaulting to nil which causes the default
1307
+ # value of `deferred=$confdir/goose` to raise an interpolation error during
1308
+ # global initialization, and the hook to be skipped
976
1309
  @settings.define_settings(:main,
977
- :logdir => { :type => :directory, :default => nil, :desc => "logdir" },
978
- :confdir => { :type => :directory, :default => nil, :desc => "confdir" },
979
- :codedir => { :type => :directory, :default => nil, :desc => "codedir" },
980
- :vardir => { :type => :directory, :default => nil, :desc => "vardir" })
1310
+ PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS.merge(
1311
+ :confdir => { :type => :directory, :default => nil, :desc => "confdir" }))
981
1312
 
982
- text = <<-EOD
983
- [main]
984
- deferred=$confdir/goose
1313
+ File.write(@file, <<~EOD)
1314
+ [main]
1315
+ deferred=$confdir/goose
985
1316
  EOD
986
1317
 
987
- allow(@settings).to receive(:read_file).and_return(text)
988
1318
  @settings.initialize_global_settings
989
1319
 
990
1320
  expect(hook_invoked).to be_falsey
991
1321
 
992
- @settings.initialize_app_defaults(:logdir => '/path/to/logdir', :confdir => '/path/to/confdir', :vardir => '/path/to/vardir', :codedir => '/path/to/codedir')
1322
+ # And now that we initialize app defaults with `confdir`, then `deferred`
1323
+ # can be interpolated and its hook called
1324
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.merge(:confdir => '/path/to/confdir'))
993
1325
 
994
1326
  expect(hook_invoked).to be_truthy
995
1327
  expect(@settings[:deferred]).to eq(File.expand_path('/path/to/confdir/goose'))
@@ -998,45 +1330,33 @@ describe Puppet::Settings do
998
1330
  it "does not require the value for a setting without a hook to resolve during global setup" do
999
1331
  @settings.define_settings :section, :can_cause_problems => {:desc => '' }
1000
1332
 
1001
- @settings.define_settings(:main,
1002
- :logdir => { :type => :directory, :default => nil, :desc => "logdir" },
1003
- :confdir => { :type => :directory, :default => nil, :desc => "confdir" },
1004
- :codedir => { :type => :directory, :default => nil, :desc => "codedir" },
1005
- :vardir => { :type => :directory, :default => nil, :desc => "vardir" })
1333
+ @settings.define_settings(:main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS)
1006
1334
 
1007
- text = <<-EOD
1335
+ File.write(@file, <<~EOD)
1008
1336
  [main]
1009
1337
  can_cause_problems=$confdir/goose
1010
1338
  EOD
1011
1339
 
1012
- allow(@settings).to receive(:read_file).and_return(text)
1013
1340
  @settings.initialize_global_settings
1014
- @settings.initialize_app_defaults(:logdir => '/path/to/logdir', :confdir => '/path/to/confdir', :vardir => '/path/to/vardir', :codedir => '/path/to/codedir')
1341
+ @settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES.merge(:confdir => '/path/to/confdir'))
1015
1342
 
1016
- expect(@settings[:can_cause_problems]).to eq(File.expand_path('/path/to/confdir/goose'))
1343
+ expect(@settings[:can_cause_problems]).to eq('/path/to/confdir/goose')
1017
1344
  end
1018
1345
 
1019
1346
  it "should allow empty values" do
1020
1347
  @settings.define_settings :section, :myarg => { :default => "myfile", :desc => "a" }
1021
1348
 
1022
- text = "[main]
1023
- myarg =
1024
- "
1025
- allow(@settings).to receive(:read_file).and_return(text)
1026
- @settings.send(:parse_config_files)
1349
+ File.write(@file, <<~CONF)
1350
+ [main]
1351
+ myarg =
1352
+ CONF
1353
+ @settings.initialize_global_settings
1354
+
1027
1355
  expect(@settings[:myarg]).to eq("")
1028
1356
  end
1029
1357
 
1030
1358
  describe "deprecations" do
1031
1359
  let(:settings) { Puppet::Settings.new }
1032
- let(:app_defaults) {
1033
- {
1034
- :logdir => "/dev/null",
1035
- :confdir => "/dev/null",
1036
- :codedir => "/dev/null",
1037
- :vardir => "/dev/null",
1038
- }
1039
- }
1040
1360
 
1041
1361
  def assert_accessing_setting_is_deprecated(settings, setting)
1042
1362
  expect(Puppet).to receive(:deprecation_warning).with("Accessing '#{setting}' as a setting is deprecated.")
@@ -1046,12 +1366,7 @@ describe Puppet::Settings do
1046
1366
  end
1047
1367
 
1048
1368
  before(:each) do
1049
- settings.define_settings(:main, {
1050
- :logdir => { :default => 'a', :desc => 'a' },
1051
- :confdir => { :default => 'b', :desc => 'b' },
1052
- :vardir => { :default => 'c', :desc => 'c' },
1053
- :codedir => { :default => 'd', :desc => 'd' },
1054
- })
1369
+ settings.define_settings(:main, PuppetSpec::Settings::TEST_APP_DEFAULT_DEFINITIONS)
1055
1370
  end
1056
1371
 
1057
1372
  context "complete" do
@@ -1072,7 +1387,7 @@ describe Puppet::Settings do
1072
1387
  completely_deprecated_settings.parse_config(<<-CONF)
1073
1388
  completely_deprecated_setting='should warn'
1074
1389
  CONF
1075
- completely_deprecated_settings.initialize_app_defaults(app_defaults)
1390
+ completely_deprecated_settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES)
1076
1391
  end
1077
1392
 
1078
1393
  it "warns when set on the commandline" do
@@ -1080,7 +1395,7 @@ describe Puppet::Settings do
1080
1395
 
1081
1396
  args = ["--completely_deprecated_setting", "/some/value"]
1082
1397
  completely_deprecated_settings.send(:parse_global_options, args)
1083
- completely_deprecated_settings.initialize_app_defaults(app_defaults)
1398
+ completely_deprecated_settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES)
1084
1399
  end
1085
1400
 
1086
1401
  it "warns when set in code" do
@@ -1105,7 +1420,7 @@ describe Puppet::Settings do
1105
1420
  partially_deprecated_settings.parse_config(<<-CONF)
1106
1421
  partially_deprecated_setting='should warn'
1107
1422
  CONF
1108
- partially_deprecated_settings.initialize_app_defaults(app_defaults)
1423
+ partially_deprecated_settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES)
1109
1424
  end
1110
1425
 
1111
1426
  it "does not warn when manifest is set on command line" do
@@ -1113,7 +1428,7 @@ describe Puppet::Settings do
1113
1428
 
1114
1429
  args = ["--partially_deprecated_setting", "/some/value"]
1115
1430
  partially_deprecated_settings.send(:parse_global_options, args)
1116
- partially_deprecated_settings.initialize_app_defaults(app_defaults)
1431
+ partially_deprecated_settings.initialize_app_defaults(PuppetSpec::Settings::TEST_APP_DEFAULT_VALUES)
1117
1432
  end
1118
1433
 
1119
1434
  it "warns when set in code" do
@@ -1206,23 +1521,24 @@ describe Puppet::Settings do
1206
1521
 
1207
1522
  describe "when reparsing its configuration" do
1208
1523
  before do
1209
- @file = make_absolute("/test/file")
1210
- @userconfig = make_absolute("/test/userconfigfile")
1524
+ @file = tmpfile("testfile")
1525
+ Puppet::FileSystem.touch(@file)
1526
+
1211
1527
  @settings = Puppet::Settings.new
1212
1528
  @settings.define_settings :section,
1213
1529
  :config => { :type => :file, :default => @file, :desc => "a" },
1214
1530
  :one => { :default => "ONE", :desc => "a" },
1215
1531
  :two => { :default => "$one TWO", :desc => "b" },
1216
1532
  :three => { :default => "$one $two THREE", :desc => "c" }
1217
- allow(Puppet::FileSystem).to receive(:exist?).with(@file).and_return(true)
1218
- allow(Puppet::FileSystem).to receive(:exist?).with(@userconfig).and_return(false)
1219
- allow(@settings).to receive(:user_config_file).and_return(@userconfig)
1533
+
1534
+ userconfig = tmpfile("userconfig")
1535
+ allow(@settings).to receive(:user_config_file).and_return(userconfig)
1220
1536
  end
1221
1537
 
1222
1538
  it "does not create the WatchedFile instance and should not parse if the file does not exist" do
1223
- expect(Puppet::FileSystem).to receive(:exist?).with(@file).and_return(false)
1224
- expect(Puppet::Util::WatchedFile).not_to receive(:new)
1539
+ Puppet::FileSystem.unlink(@file)
1225
1540
 
1541
+ expect(Puppet::Util::WatchedFile).not_to receive(:new)
1226
1542
  expect(@settings).not_to receive(:parse_config_files)
1227
1543
 
1228
1544
  @settings.reparse_config_files
@@ -1261,8 +1577,8 @@ describe Puppet::Settings do
1261
1577
  @settings[:one] = "init"
1262
1578
 
1263
1579
  # Now replace the value
1264
- text = "[main]\none = disk-replace\n"
1265
- allow(@settings).to receive(:read_file).and_return(text)
1580
+ File.write(@file, "[main]\none = disk-replace\n")
1581
+
1266
1582
  @settings.reparse_config_files
1267
1583
  expect(@settings[:one]).to eq("disk-replace")
1268
1584
  end
@@ -1271,23 +1587,20 @@ describe Puppet::Settings do
1271
1587
  it "should retain parameters set by cli when configuration files are reparsed" do
1272
1588
  @settings.handlearg("--one", "clival")
1273
1589
 
1274
- text = "[main]\none = on-disk\n"
1275
- allow(@settings).to receive(:read_file).and_return(text)
1276
- @settings.send(:parse_config_files)
1590
+ File.write(@file, "[main]\none = on-disk\n")
1591
+ @settings.initialize_global_settings
1277
1592
 
1278
1593
  expect(@settings[:one]).to eq("clival")
1279
1594
  end
1280
1595
 
1281
1596
  it "should remove in-memory values that are no longer set in the file" do
1282
1597
  # Init the value
1283
- text = "[main]\none = disk-init\n"
1284
- expect(@settings).to receive(:read_file).and_return(text)
1598
+ File.write(@file, "[main]\none = disk-init\n")
1285
1599
  @settings.send(:parse_config_files)
1286
1600
  expect(@settings[:one]).to eq("disk-init")
1287
1601
 
1288
1602
  # Now replace the value
1289
- text = "[main]\ntwo = disk-replace\n"
1290
- expect(@settings).to receive(:read_file).and_return(text)
1603
+ File.write(@file, "[main]\ntwo = disk-replace\n")
1291
1604
  @settings.send(:parse_config_files)
1292
1605
 
1293
1606
  # The originally-overridden value should be replaced with the default
@@ -1299,14 +1612,12 @@ describe Puppet::Settings do
1299
1612
 
1300
1613
  it "should retain in-memory values if the file has a syntax error" do
1301
1614
  # Init the value
1302
- text = "[main]\none = initial-value\n"
1303
- expect(@settings).to receive(:read_file).with(@file).and_return(text)
1304
- @settings.send(:parse_config_files)
1615
+ File.write(@file, "[main]\none = initial-value\n")
1616
+ @settings.initialize_global_settings
1305
1617
  expect(@settings[:one]).to eq("initial-value")
1306
1618
 
1307
1619
  # Now replace the value with something bogus
1308
- text = "[main]\nkenny = killed-by-what-follows\n1 is 2, blah blah florp\n"
1309
- expect(@settings).to receive(:read_file).with(@file).and_return(text)
1620
+ File.write(@file, "[main]\nkenny = killed-by-what-follows\n1 is 2, blah blah florp\n")
1310
1621
  @settings.send(:parse_config_files)
1311
1622
 
1312
1623
  # The originally-overridden value should not be replaced with the default
@@ -1318,46 +1629,49 @@ describe Puppet::Settings do
1318
1629
  end
1319
1630
 
1320
1631
  it "should provide a method for creating a catalog of resources from its configuration" do
1321
- expect(Puppet::Settings.new).to respond_to(:to_catalog)
1632
+ expect(Puppet::Settings.new.to_catalog).to be_an_instance_of(Puppet::Resource::Catalog)
1322
1633
  end
1323
1634
 
1324
1635
  describe "when creating a catalog" do
1636
+ let(:maindir) { make_absolute('/maindir') }
1637
+ let(:seconddir) { make_absolute('/seconddir') }
1638
+ let(:otherdir) { make_absolute('/otherdir') }
1639
+
1325
1640
  before do
1326
1641
  @settings = Puppet::Settings.new
1327
1642
  allow(@settings).to receive(:service_user_available?).and_return(true)
1328
- @prefix = Puppet.features.posix? ? "" : "C:"
1329
1643
  end
1330
1644
 
1331
1645
  it "should add all file resources to the catalog if no sections have been specified" do
1332
1646
  @settings.define_settings :main,
1333
- :maindir => { :type => :directory, :default => @prefix+"/maindir", :desc => "a"},
1334
- :seconddir => { :type => :directory, :default => @prefix+"/seconddir", :desc => "a"}
1647
+ :maindir => { :type => :directory, :default => maindir, :desc => "a"},
1648
+ :seconddir => { :type => :directory, :default => seconddir, :desc => "a"}
1335
1649
  @settings.define_settings :other,
1336
- :otherdir => { :type => :directory, :default => @prefix+"/otherdir", :desc => "a" }
1650
+ :otherdir => { :type => :directory, :default => otherdir, :desc => "a" }
1337
1651
 
1338
1652
  catalog = @settings.to_catalog
1339
1653
 
1340
- [@prefix+"/maindir", @prefix+"/seconddir", @prefix+"/otherdir"].each do |path|
1654
+ [maindir, seconddir, otherdir].each do |path|
1341
1655
  expect(catalog.resource(:file, path)).to be_instance_of(Puppet::Resource)
1342
1656
  end
1343
1657
  end
1344
1658
 
1345
1659
  it "should add only files in the specified sections if section names are provided" do
1346
- @settings.define_settings :main, :maindir => { :type => :directory, :default => @prefix+"/maindir", :desc => "a" }
1347
- @settings.define_settings :other, :otherdir => { :type => :directory, :default => @prefix+"/otherdir", :desc => "a" }
1660
+ @settings.define_settings :main, :maindir => { :type => :directory, :default => maindir, :desc => "a" }
1661
+ @settings.define_settings :other, :otherdir => { :type => :directory, :default => otherdir, :desc => "a" }
1348
1662
  catalog = @settings.to_catalog(:main)
1349
- expect(catalog.resource(:file, @prefix+"/otherdir")).to be_nil
1350
- expect(catalog.resource(:file, @prefix+"/maindir")).to be_instance_of(Puppet::Resource)
1663
+ expect(catalog.resource(:file, otherdir)).to be_nil
1664
+ expect(catalog.resource(:file, maindir)).to be_instance_of(Puppet::Resource)
1351
1665
  end
1352
1666
 
1353
1667
  it "should not try to add the same file twice" do
1354
- @settings.define_settings :main, :maindir => { :type => :directory, :default => @prefix+"/maindir", :desc => "a" }
1355
- @settings.define_settings :other, :otherdir => { :type => :directory, :default => @prefix+"/maindir", :desc => "a" }
1668
+ @settings.define_settings :main, :maindir => { :type => :directory, :default => maindir, :desc => "a" }
1669
+ @settings.define_settings :other, :otherdir => { :type => :directory, :default => maindir, :desc => "a" }
1356
1670
  expect { @settings.to_catalog }.not_to raise_error
1357
1671
  end
1358
1672
 
1359
1673
  it "should ignore files whose :to_resource method returns nil" do
1360
- @settings.define_settings :main, :maindir => { :type => :directory, :default => @prefix+"/maindir", :desc => "a" }
1674
+ @settings.define_settings :main, :maindir => { :type => :directory, :default => maindir, :desc => "a" }
1361
1675
  expect(@settings.setting(:maindir)).to receive(:to_resource).and_return(nil)
1362
1676
 
1363
1677
  expect_any_instance_of(Puppet::Resource::Catalog).not_to receive(:add_resource)
@@ -1387,6 +1701,7 @@ describe Puppet::Settings do
1387
1701
  describe "adding default directory environment to the catalog" do
1388
1702
  let(:tmpenv) { tmpdir("envs") }
1389
1703
  let(:default_path) { "#{tmpenv}/environments" }
1704
+
1390
1705
  before(:each) do
1391
1706
  @settings.define_settings :main,
1392
1707
  :environment => { :default => "production", :desc => "env"},