chef-config 12.4.0.rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/README.md +4 -0
- data/Rakefile +55 -0
- data/lib/chef-config.rb +20 -0
- data/lib/chef-config/config.rb +744 -0
- data/lib/chef-config/exceptions.rb +26 -0
- data/lib/chef-config/logger.rb +62 -0
- data/lib/chef-config/path_helper.rb +233 -0
- data/lib/chef-config/version.rb +25 -0
- data/lib/chef-config/windows.rb +29 -0
- data/spec/spec_helper.rb +75 -0
- data/spec/unit/config_spec.rb +581 -0
- data/spec/unit/path_helper_spec.rb +291 -0
- metadata +143 -0
@@ -0,0 +1,581 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Author:: Kyle Goodwin (<kgoodwin@primerevenue.com>)
|
4
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
require 'chef-config/config'
|
22
|
+
|
23
|
+
RSpec.describe ChefConfig::Config do
|
24
|
+
before(:each) do
|
25
|
+
ChefConfig::Config.reset
|
26
|
+
|
27
|
+
# By default, treat deprecation warnings as errors in tests.
|
28
|
+
ChefConfig::Config.treat_deprecation_warnings_as_errors(true)
|
29
|
+
|
30
|
+
# Set environment variable so the setting persists in child processes
|
31
|
+
ENV['CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS'] = "1"
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "config attribute writer: chef_server_url" do
|
35
|
+
before do
|
36
|
+
ChefConfig::Config.chef_server_url = "https://junglist.gen.nz"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "sets the server url" do
|
40
|
+
expect(ChefConfig::Config.chef_server_url).to eq("https://junglist.gen.nz")
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when the url has a leading space" do
|
44
|
+
before do
|
45
|
+
ChefConfig::Config.chef_server_url = " https://junglist.gen.nz"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "strips the space from the url when setting" do
|
49
|
+
expect(ChefConfig::Config.chef_server_url).to eq("https://junglist.gen.nz")
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when the url is a frozen string" do
|
55
|
+
before do
|
56
|
+
ChefConfig::Config.chef_server_url = " https://junglist.gen.nz".freeze
|
57
|
+
end
|
58
|
+
|
59
|
+
it "strips the space from the url when setting without raising an error" do
|
60
|
+
expect(ChefConfig::Config.chef_server_url).to eq("https://junglist.gen.nz")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when configuring formatters" do
|
66
|
+
# if TTY and not(force-logger)
|
67
|
+
# formatter = configured formatter or default formatter
|
68
|
+
# formatter goes to STDOUT/ERR
|
69
|
+
# if log file is writeable
|
70
|
+
# log level is configured level or info
|
71
|
+
# log location is file
|
72
|
+
# else
|
73
|
+
# log level is warn
|
74
|
+
# log location is STDERR
|
75
|
+
# end
|
76
|
+
# elsif not(TTY) and force formatter
|
77
|
+
# formatter = configured formatter or default formatter
|
78
|
+
# if log_location specified
|
79
|
+
# formatter goes to log_location
|
80
|
+
# else
|
81
|
+
# formatter goes to STDOUT/ERR
|
82
|
+
# end
|
83
|
+
# else
|
84
|
+
# formatter = "null"
|
85
|
+
# log_location = configured-value or defualt
|
86
|
+
# log_level = info or defualt
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
it "has an empty list of formatters by default" do
|
90
|
+
expect(ChefConfig::Config.formatters).to eq([])
|
91
|
+
end
|
92
|
+
|
93
|
+
it "configures a formatter with a short name" do
|
94
|
+
ChefConfig::Config.add_formatter(:doc)
|
95
|
+
expect(ChefConfig::Config.formatters).to eq([[:doc, nil]])
|
96
|
+
end
|
97
|
+
|
98
|
+
it "configures a formatter with a file output" do
|
99
|
+
ChefConfig::Config.add_formatter(:doc, "/var/log/formatter.log")
|
100
|
+
expect(ChefConfig::Config.formatters).to eq([[:doc, "/var/log/formatter.log"]])
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
[ false, true ].each do |is_windows|
|
106
|
+
|
107
|
+
context "On #{is_windows ? 'Windows' : 'Unix'}" do
|
108
|
+
def to_platform(*args)
|
109
|
+
ChefConfig::Config.platform_specific_path(*args)
|
110
|
+
end
|
111
|
+
|
112
|
+
before :each do
|
113
|
+
allow(ChefConfig).to receive(:windows?).and_return(is_windows)
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "class method: platform_specific_path" do
|
117
|
+
if is_windows
|
118
|
+
it "should return a windows path on windows systems" do
|
119
|
+
path = "/etc/chef/cookbooks"
|
120
|
+
allow(ChefConfig::Config).to receive(:env).and_return({ 'SYSTEMDRIVE' => 'C:' })
|
121
|
+
# match on a regex that looks for the base path with an optional
|
122
|
+
# system drive at the beginning (c:)
|
123
|
+
# system drive is not hardcoded b/c it can change and b/c it is not present on linux systems
|
124
|
+
expect(ChefConfig::Config.platform_specific_path(path)).to eq("C:\\chef\\cookbooks")
|
125
|
+
end
|
126
|
+
else
|
127
|
+
it "should return given path on non-windows systems" do
|
128
|
+
path = "/etc/chef/cookbooks"
|
129
|
+
expect(ChefConfig::Config.platform_specific_path(path)).to eq("/etc/chef/cookbooks")
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "default values" do
|
135
|
+
let :primary_cache_path do
|
136
|
+
if is_windows
|
137
|
+
"#{ChefConfig::Config.env['SYSTEMDRIVE']}\\chef"
|
138
|
+
else
|
139
|
+
"/var/chef"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
let :secondary_cache_path do
|
144
|
+
if is_windows
|
145
|
+
"#{ChefConfig::Config[:user_home]}\\.chef"
|
146
|
+
else
|
147
|
+
"#{ChefConfig::Config[:user_home]}/.chef"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
before do
|
152
|
+
if is_windows
|
153
|
+
allow(ChefConfig::Config).to receive(:env).and_return({ 'SYSTEMDRIVE' => 'C:' })
|
154
|
+
ChefConfig::Config[:user_home] = 'C:\Users\charlie'
|
155
|
+
else
|
156
|
+
ChefConfig::Config[:user_home] = '/Users/charlie'
|
157
|
+
end
|
158
|
+
|
159
|
+
allow(ChefConfig::Config).to receive(:path_accessible?).and_return(false)
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "ChefConfig::Config[:chef_server_root]" do
|
163
|
+
context "when chef_server_url isn't set manually" do
|
164
|
+
it "returns the default of 'https://localhost:443'" do
|
165
|
+
expect(ChefConfig::Config[:chef_server_root]).to eq("https://localhost:443")
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "when chef_server_url matches '../organizations/*' without a trailing slash" do
|
170
|
+
before do
|
171
|
+
ChefConfig::Config[:chef_server_url] = "https://example.com/organizations/myorg"
|
172
|
+
end
|
173
|
+
it "returns the full URL without /organizations/*" do
|
174
|
+
expect(ChefConfig::Config[:chef_server_root]).to eq("https://example.com")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "when chef_server_url matches '../organizations/*' with a trailing slash" do
|
179
|
+
before do
|
180
|
+
ChefConfig::Config[:chef_server_url] = "https://example.com/organizations/myorg/"
|
181
|
+
end
|
182
|
+
it "returns the full URL without /organizations/*" do
|
183
|
+
expect(ChefConfig::Config[:chef_server_root]).to eq("https://example.com")
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context "when chef_server_url matches '..organizations..' but not '../organizations/*'" do
|
188
|
+
before do
|
189
|
+
ChefConfig::Config[:chef_server_url] = "https://organizations.com/organizations"
|
190
|
+
end
|
191
|
+
it "returns the full URL without any modifications" do
|
192
|
+
expect(ChefConfig::Config[:chef_server_root]).to eq(ChefConfig::Config[:chef_server_url])
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "when chef_server_url is a standard URL without the string organization(s)" do
|
197
|
+
before do
|
198
|
+
ChefConfig::Config[:chef_server_url] = "https://example.com/some_other_string"
|
199
|
+
end
|
200
|
+
it "returns the full URL without any modifications" do
|
201
|
+
expect(ChefConfig::Config[:chef_server_root]).to eq(ChefConfig::Config[:chef_server_url])
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "ChefConfig::Config[:cache_path]" do
|
207
|
+
context "when /var/chef exists and is accessible" do
|
208
|
+
it "defaults to /var/chef" do
|
209
|
+
allow(ChefConfig::Config).to receive(:path_accessible?).with(to_platform("/var/chef")).and_return(true)
|
210
|
+
expect(ChefConfig::Config[:cache_path]).to eq(primary_cache_path)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "when /var/chef does not exist and /var is accessible" do
|
215
|
+
it "defaults to /var/chef" do
|
216
|
+
allow(File).to receive(:exists?).with(to_platform("/var/chef")).and_return(false)
|
217
|
+
allow(ChefConfig::Config).to receive(:path_accessible?).with(to_platform("/var")).and_return(true)
|
218
|
+
expect(ChefConfig::Config[:cache_path]).to eq(primary_cache_path)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "when /var/chef does not exist and /var is not accessible" do
|
223
|
+
it "defaults to $HOME/.chef" do
|
224
|
+
allow(File).to receive(:exists?).with(to_platform("/var/chef")).and_return(false)
|
225
|
+
allow(ChefConfig::Config).to receive(:path_accessible?).with(to_platform("/var")).and_return(false)
|
226
|
+
expect(ChefConfig::Config[:cache_path]).to eq(secondary_cache_path)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context "when /var/chef exists and is not accessible" do
|
231
|
+
it "defaults to $HOME/.chef" do
|
232
|
+
allow(File).to receive(:exists?).with(to_platform("/var/chef")).and_return(true)
|
233
|
+
allow(File).to receive(:readable?).with(to_platform("/var/chef")).and_return(true)
|
234
|
+
allow(File).to receive(:writable?).with(to_platform("/var/chef")).and_return(false)
|
235
|
+
|
236
|
+
expect(ChefConfig::Config[:cache_path]).to eq(secondary_cache_path)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context "when chef is running in local mode" do
|
241
|
+
before do
|
242
|
+
ChefConfig::Config.local_mode = true
|
243
|
+
end
|
244
|
+
|
245
|
+
context "and config_dir is /a/b/c" do
|
246
|
+
before do
|
247
|
+
ChefConfig::Config.config_dir to_platform('/a/b/c')
|
248
|
+
end
|
249
|
+
|
250
|
+
it "cache_path is /a/b/c/local-mode-cache" do
|
251
|
+
expect(ChefConfig::Config.cache_path).to eq(to_platform('/a/b/c/local-mode-cache'))
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context "and config_dir is /a/b/c/" do
|
256
|
+
before do
|
257
|
+
ChefConfig::Config.config_dir to_platform('/a/b/c/')
|
258
|
+
end
|
259
|
+
|
260
|
+
it "cache_path is /a/b/c/local-mode-cache" do
|
261
|
+
expect(ChefConfig::Config.cache_path).to eq(to_platform('/a/b/c/local-mode-cache'))
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
it "ChefConfig::Config[:file_backup_path] defaults to /var/chef/backup" do
|
268
|
+
allow(ChefConfig::Config).to receive(:cache_path).and_return(primary_cache_path)
|
269
|
+
backup_path = is_windows ? "#{primary_cache_path}\\backup" : "#{primary_cache_path}/backup"
|
270
|
+
expect(ChefConfig::Config[:file_backup_path]).to eq(backup_path)
|
271
|
+
end
|
272
|
+
|
273
|
+
it "ChefConfig::Config[:ssl_verify_mode] defaults to :verify_peer" do
|
274
|
+
expect(ChefConfig::Config[:ssl_verify_mode]).to eq(:verify_peer)
|
275
|
+
end
|
276
|
+
|
277
|
+
it "ChefConfig::Config[:ssl_ca_path] defaults to nil" do
|
278
|
+
expect(ChefConfig::Config[:ssl_ca_path]).to be_nil
|
279
|
+
end
|
280
|
+
|
281
|
+
# On Windows, we'll detect an omnibus build and set this to the
|
282
|
+
# cacert.pem included in the package, but it's nil if you're on Windows
|
283
|
+
# w/o omnibus (e.g., doing development on Windows, custom build, etc.)
|
284
|
+
if !is_windows
|
285
|
+
it "ChefConfig::Config[:ssl_ca_file] defaults to nil" do
|
286
|
+
expect(ChefConfig::Config[:ssl_ca_file]).to be_nil
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
it "ChefConfig::Config[:data_bag_path] defaults to /var/chef/data_bags" do
|
291
|
+
allow(ChefConfig::Config).to receive(:cache_path).and_return(primary_cache_path)
|
292
|
+
data_bag_path = is_windows ? "#{primary_cache_path}\\data_bags" : "#{primary_cache_path}/data_bags"
|
293
|
+
expect(ChefConfig::Config[:data_bag_path]).to eq(data_bag_path)
|
294
|
+
end
|
295
|
+
|
296
|
+
it "ChefConfig::Config[:environment_path] defaults to /var/chef/environments" do
|
297
|
+
allow(ChefConfig::Config).to receive(:cache_path).and_return(primary_cache_path)
|
298
|
+
environment_path = is_windows ? "#{primary_cache_path}\\environments" : "#{primary_cache_path}/environments"
|
299
|
+
expect(ChefConfig::Config[:environment_path]).to eq(environment_path)
|
300
|
+
end
|
301
|
+
|
302
|
+
describe "setting the config dir" do
|
303
|
+
|
304
|
+
context "when the config file is /etc/chef/client.rb" do
|
305
|
+
|
306
|
+
before do
|
307
|
+
ChefConfig::Config.config_file = to_platform("/etc/chef/client.rb")
|
308
|
+
end
|
309
|
+
|
310
|
+
it "config_dir is /etc/chef" do
|
311
|
+
expect(ChefConfig::Config.config_dir).to eq(to_platform("/etc/chef"))
|
312
|
+
end
|
313
|
+
|
314
|
+
context "and chef is running in local mode" do
|
315
|
+
before do
|
316
|
+
ChefConfig::Config.local_mode = true
|
317
|
+
end
|
318
|
+
|
319
|
+
it "config_dir is /etc/chef" do
|
320
|
+
expect(ChefConfig::Config.config_dir).to eq(to_platform("/etc/chef"))
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
context "when config_dir is set to /other/config/dir/" do
|
325
|
+
before do
|
326
|
+
ChefConfig::Config.config_dir = to_platform("/other/config/dir/")
|
327
|
+
end
|
328
|
+
|
329
|
+
it "yields the explicit value" do
|
330
|
+
expect(ChefConfig::Config.config_dir).to eq(to_platform("/other/config/dir/"))
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
end
|
335
|
+
|
336
|
+
context "when the user's home dir is /home/charlie/" do
|
337
|
+
before do
|
338
|
+
ChefConfig::Config.user_home = to_platform("/home/charlie")
|
339
|
+
end
|
340
|
+
|
341
|
+
it "config_dir is /home/charlie/.chef/" do
|
342
|
+
expect(ChefConfig::Config.config_dir).to eq(ChefConfig::PathHelper.join(to_platform("/home/charlie/.chef"), ''))
|
343
|
+
end
|
344
|
+
|
345
|
+
context "and chef is running in local mode" do
|
346
|
+
before do
|
347
|
+
ChefConfig::Config.local_mode = true
|
348
|
+
end
|
349
|
+
|
350
|
+
it "config_dir is /home/charlie/.chef/" do
|
351
|
+
expect(ChefConfig::Config.config_dir).to eq(ChefConfig::PathHelper.join(to_platform("/home/charlie/.chef"), ''))
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
if is_windows
|
359
|
+
describe "finding the windows embedded dir" do
|
360
|
+
let(:default_config_location) { "c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
|
361
|
+
let(:alternate_install_location) { "c:/my/alternate/install/place/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
|
362
|
+
let(:non_omnibus_location) { "c:/my/dev/stuff/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
|
363
|
+
|
364
|
+
let(:default_ca_file) { "c:/opscode/chef/embedded/ssl/certs/cacert.pem" }
|
365
|
+
|
366
|
+
it "finds the embedded dir in the default location" do
|
367
|
+
allow(ChefConfig::Config).to receive(:_this_file).and_return(default_config_location)
|
368
|
+
expect(ChefConfig::Config.embedded_dir).to eq("c:/opscode/chef/embedded")
|
369
|
+
end
|
370
|
+
|
371
|
+
it "finds the embedded dir in a custom install location" do
|
372
|
+
allow(ChefConfig::Config).to receive(:_this_file).and_return(alternate_install_location)
|
373
|
+
expect(ChefConfig::Config.embedded_dir).to eq("c:/my/alternate/install/place/chef/embedded")
|
374
|
+
end
|
375
|
+
|
376
|
+
it "doesn't error when not in an omnibus install" do
|
377
|
+
allow(ChefConfig::Config).to receive(:_this_file).and_return(non_omnibus_location)
|
378
|
+
expect(ChefConfig::Config.embedded_dir).to be_nil
|
379
|
+
end
|
380
|
+
|
381
|
+
it "sets the ssl_ca_cert path if the cert file is available" do
|
382
|
+
allow(ChefConfig::Config).to receive(:_this_file).and_return(default_config_location)
|
383
|
+
allow(File).to receive(:exist?).with(default_ca_file).and_return(true)
|
384
|
+
expect(ChefConfig::Config.ssl_ca_file).to eq(default_ca_file)
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
describe "ChefConfig::Config[:user_home]" do
|
391
|
+
it "should set when HOME is provided" do
|
392
|
+
expected = to_platform("/home/kitten")
|
393
|
+
allow(ChefConfig::PathHelper).to receive(:home).and_return(expected)
|
394
|
+
expect(ChefConfig::Config[:user_home]).to eq(expected)
|
395
|
+
end
|
396
|
+
|
397
|
+
it "falls back to the current working directory when HOME and USERPROFILE is not set" do
|
398
|
+
allow(ChefConfig::PathHelper).to receive(:home).and_return(nil)
|
399
|
+
expect(ChefConfig::Config[:user_home]).to eq(Dir.pwd)
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
describe "ChefConfig::Config[:encrypted_data_bag_secret]" do
|
404
|
+
let(:db_secret_default_path){ to_platform("/etc/chef/encrypted_data_bag_secret") }
|
405
|
+
|
406
|
+
before do
|
407
|
+
allow(File).to receive(:exist?).with(db_secret_default_path).and_return(secret_exists)
|
408
|
+
end
|
409
|
+
|
410
|
+
context "/etc/chef/encrypted_data_bag_secret exists" do
|
411
|
+
let(:secret_exists) { true }
|
412
|
+
it "sets the value to /etc/chef/encrypted_data_bag_secret" do
|
413
|
+
expect(ChefConfig::Config[:encrypted_data_bag_secret]).to eq db_secret_default_path
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
context "/etc/chef/encrypted_data_bag_secret does not exist" do
|
418
|
+
let(:secret_exists) { false }
|
419
|
+
it "sets the value to nil" do
|
420
|
+
expect(ChefConfig::Config[:encrypted_data_bag_secret]).to be_nil
|
421
|
+
end
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
describe "ChefConfig::Config[:event_handlers]" do
|
426
|
+
it "sets a event_handlers to an empty array by default" do
|
427
|
+
expect(ChefConfig::Config[:event_handlers]).to eq([])
|
428
|
+
end
|
429
|
+
it "should be able to add custom handlers" do
|
430
|
+
o = Object.new
|
431
|
+
ChefConfig::Config[:event_handlers] << o
|
432
|
+
expect(ChefConfig::Config[:event_handlers]).to be_include(o)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
describe "ChefConfig::Config[:user_valid_regex]" do
|
437
|
+
context "on a platform that is not Windows" do
|
438
|
+
it "allows one letter usernames" do
|
439
|
+
any_match = ChefConfig::Config[:user_valid_regex].any? { |regex| regex.match('a') }
|
440
|
+
expect(any_match).to be_truthy
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
describe "ChefConfig::Config[:internal_locale]" do
|
446
|
+
let(:shell_out) do
|
447
|
+
cmd = instance_double("Mixlib::ShellOut", exitstatus: 0, stdout: locales, error!: nil)
|
448
|
+
allow(cmd).to receive(:run_command).and_return(cmd)
|
449
|
+
cmd
|
450
|
+
end
|
451
|
+
|
452
|
+
let(:locales) { locale_array.join("\n") }
|
453
|
+
|
454
|
+
before do
|
455
|
+
allow(Mixlib::ShellOut).to receive(:new).with("locale -a").and_return(shell_out)
|
456
|
+
end
|
457
|
+
|
458
|
+
shared_examples_for "a suitable locale" do
|
459
|
+
it "returns an English UTF-8 locale" do
|
460
|
+
expect(ChefConfig.logger).to_not receive(:warn).with(/Please install an English UTF-8 locale for Chef to use/)
|
461
|
+
expect(ChefConfig.logger).to_not receive(:debug).with(/Defaulting to locale en_US.UTF-8 on Windows/)
|
462
|
+
expect(ChefConfig.logger).to_not receive(:debug).with(/No usable locale -a command found/)
|
463
|
+
expect(ChefConfig::Config.guess_internal_locale).to eq expected_locale
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
context "when the result includes 'C.UTF-8'" do
|
468
|
+
include_examples "a suitable locale" do
|
469
|
+
let(:locale_array) { [expected_locale, "en_US.UTF-8"] }
|
470
|
+
let(:expected_locale) { "C.UTF-8" }
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
context "when the result includes 'en_US.UTF-8'" do
|
475
|
+
include_examples "a suitable locale" do
|
476
|
+
let(:locale_array) { ["en_CA.UTF-8", expected_locale, "en_NZ.UTF-8"] }
|
477
|
+
let(:expected_locale) { "en_US.UTF-8" }
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
context "when the result includes 'en_US.utf8'" do
|
482
|
+
include_examples "a suitable locale" do
|
483
|
+
let(:locale_array) { ["en_CA.utf8", "en_US.utf8", "en_NZ.utf8"] }
|
484
|
+
let(:expected_locale) { "en_US.UTF-8" }
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
context "when the result includes 'en.UTF-8'" do
|
489
|
+
include_examples "a suitable locale" do
|
490
|
+
let(:locale_array) { ["en.ISO8859-1", expected_locale] }
|
491
|
+
let(:expected_locale) { "en.UTF-8" }
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
context "when the result includes 'en_*.UTF-8'" do
|
496
|
+
include_examples "a suitable locale" do
|
497
|
+
let(:locale_array) { [expected_locale, "en_CA.UTF-8", "en_GB.UTF-8"] }
|
498
|
+
let(:expected_locale) { "en_AU.UTF-8" }
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
context "when the result includes 'en_*.utf8'" do
|
503
|
+
include_examples "a suitable locale" do
|
504
|
+
let(:locale_array) { ["en_AU.utf8", "en_CA.utf8", "en_GB.utf8"] }
|
505
|
+
let(:expected_locale) { "en_AU.UTF-8" }
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
context "when the result does not include 'en_*.UTF-8'" do
|
510
|
+
let(:locale_array) { ["af_ZA", "af_ZA.ISO8859-1", "af_ZA.ISO8859-15", "af_ZA.UTF-8"] }
|
511
|
+
|
512
|
+
it "should fall back to C locale" do
|
513
|
+
expect(ChefConfig.logger).to receive(:warn).with("Please install an English UTF-8 locale for Chef to use, falling back to C locale and disabling UTF-8 support.")
|
514
|
+
expect(ChefConfig::Config.guess_internal_locale).to eq 'C'
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
context "on error" do
|
519
|
+
let(:locale_array) { [] }
|
520
|
+
|
521
|
+
let(:shell_out_cmd) { instance_double("Mixlib::ShellOut") }
|
522
|
+
|
523
|
+
before do
|
524
|
+
allow(Mixlib::ShellOut).to receive(:new).and_return(shell_out_cmd)
|
525
|
+
allow(shell_out_cmd).to receive(:run_command)
|
526
|
+
allow(shell_out_cmd).to receive(:error!).and_raise(Mixlib::ShellOut::ShellCommandFailed, "this is an error")
|
527
|
+
end
|
528
|
+
|
529
|
+
it "should default to 'en_US.UTF-8'" do
|
530
|
+
if is_windows
|
531
|
+
expect(ChefConfig.logger).to receive(:debug).with("Defaulting to locale en_US.UTF-8 on Windows, until it matters that we do something else.")
|
532
|
+
else
|
533
|
+
expect(ChefConfig.logger).to receive(:debug).with("No usable locale -a command found, assuming you have en_US.UTF-8 installed.")
|
534
|
+
end
|
535
|
+
expect(ChefConfig::Config.guess_internal_locale).to eq "en_US.UTF-8"
|
536
|
+
end
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end
|
540
|
+
end
|
541
|
+
|
542
|
+
describe "Treating deprecation warnings as errors" do
|
543
|
+
|
544
|
+
context "when using our default RSpec configuration" do
|
545
|
+
|
546
|
+
it "defaults to treating deprecation warnings as errors" do
|
547
|
+
expect(ChefConfig::Config[:treat_deprecation_warnings_as_errors]).to be(true)
|
548
|
+
end
|
549
|
+
|
550
|
+
it "sets CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS environment variable" do
|
551
|
+
expect(ENV['CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS']).to eq("1")
|
552
|
+
end
|
553
|
+
|
554
|
+
it "treats deprecation warnings as errors in child processes when testing" do
|
555
|
+
# Doing a full integration test where we launch a child process is slow
|
556
|
+
# and liable to break for weird reasons (bundler env stuff, etc.), so
|
557
|
+
# we're just checking that the presence of the environment variable
|
558
|
+
# causes treat_deprecation_warnings_as_errors to be set to true after a
|
559
|
+
# config reset.
|
560
|
+
ChefConfig::Config.reset
|
561
|
+
expect(ChefConfig::Config[:treat_deprecation_warnings_as_errors]).to be(true)
|
562
|
+
end
|
563
|
+
|
564
|
+
end
|
565
|
+
|
566
|
+
context "outside of our test environment" do
|
567
|
+
|
568
|
+
before do
|
569
|
+
ENV.delete('CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS')
|
570
|
+
ChefConfig::Config.reset
|
571
|
+
end
|
572
|
+
|
573
|
+
it "defaults to NOT treating deprecation warnings as errors" do
|
574
|
+
expect(ChefConfig::Config[:treat_deprecation_warnings_as_errors]).to be(false)
|
575
|
+
end
|
576
|
+
end
|
577
|
+
|
578
|
+
|
579
|
+
end
|
580
|
+
|
581
|
+
end
|