mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Allow user to specify a configuration file in VMPOOLER_CONFIG_FILE
variable Previously, there were two ways to configure Vmpooler, either by changing the contents of vmpooler.yaml or by assigning the raw YAML to the VMPOOLER_CONFIG environment variable. This commit adds a new environment variable called VMPOOLER_CONFIG_FILE that can be assigned the name of a config file to use. Also fixes #240 by whitelisting the Symbol class when calling YAML.safe_load in Vmpooler.config.
This commit is contained in:
parent
28922df28e
commit
878c93f646
8 changed files with 152 additions and 13 deletions
39
spec/unit/vmpooler_spec.rb
Normal file
39
spec/unit/vmpooler_spec.rb
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Vmpooler' do
|
||||
describe '.config' do
|
||||
let(:config_file) { File.join(fixtures_dir, 'vmpooler2.yaml') }
|
||||
let(:config) { YAML.load_file(config_file) }
|
||||
|
||||
before(:each) do
|
||||
ENV['VMPOOLER_DEBUG'] = 'true'
|
||||
ENV['VMPOOLER_CONFIG_FILE'] = nil
|
||||
ENV['VMPOOLER_CONFIG'] = nil
|
||||
end
|
||||
|
||||
context 'when no config is given' do
|
||||
it 'defaults to vmpooler.yaml' do
|
||||
default_config_file = File.join(fixtures_dir, 'vmpooler.yaml')
|
||||
default_config = YAML.load_file(default_config_file)
|
||||
|
||||
Dir.chdir(fixtures_dir) do
|
||||
expect(Vmpooler.config[:pools]).to eq(default_config[:pools])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when config variable is set' do
|
||||
it 'should use the config' do
|
||||
ENV['VMPOOLER_CONFIG'] = config.to_yaml
|
||||
expect(Vmpooler.config[:pools]).to eq(config[:pools])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when config file is set' do
|
||||
it 'should use the file' do
|
||||
ENV['VMPOOLER_CONFIG_FILE'] = config_file
|
||||
expect(Vmpooler.config[:pools]).to eq(config[:pools])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue