vmpooler/spec/unit/vmpooler_spec.rb
adamdav 878c93f646 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.
2018-01-23 15:51:10 -08:00

39 lines
1.1 KiB
Ruby

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