1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Issue #1901: Don't crash if provided config file is empty.

Don't return result of YAML.load if false

added tests around empty config file

update changelog
This commit is contained in:
Jordan Day 2014-08-18 10:59:14 -05:00
parent 587520d0ba
commit 381e4ea429
3 changed files with 31 additions and 1 deletions

View file

@ -2,6 +2,7 @@
-----------
- Add queues list for each process to the Busy page. [davetoxa, #1897]
- Fix for crash caused by empty config file. [jordan0day, #1901]
3.2.2
-----------

View file

@ -353,7 +353,7 @@ module Sidekiq
def parse_config(cfile)
opts = {}
if File.exist?(cfile)
opts = YAML.load(ERB.new(IO.read(cfile)).result)
opts = YAML.load(ERB.new(IO.read(cfile)).result) || opts
opts = opts.merge(opts.delete(environment) || {})
parse_queues(opts, opts.delete(:queues) || [])
else

View file

@ -241,6 +241,35 @@ class TestCli < Sidekiq::Test
end
end
describe 'with an empty config file' do
before do
@tmp_file = Tempfile.new('sidekiq-test')
@tmp_path = @tmp_file.path
@tmp_file.close!
end
after do
File.unlink @tmp_path if File.exist? @tmp_path
end
it 'takes a path' do
@cli.parse(['sidekiq', '-C', @tmp_path])
assert_equal @tmp_path, Sidekiq.options[:config_file]
end
it 'should have an identical options hash, except for config_file' do
@cli.parse(['sidekiq'])
old_options = Sidekiq.options.clone
@cli.parse(['sidekiq', '-C', @tmp_path])
new_options = Sidekiq.options.clone
refute_equal old_options, new_options
new_options.delete(:config_file)
assert_equal old_options, new_options
end
end
describe 'with config file and flags' do
before do
# We need an actual file here.