Skip to content

Commit

Permalink
issue #36 - acceptance and unit tests for this issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Nov 18, 2015
1 parent 9644676 commit 57523d5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/vagrant-r10k/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ def module_path(env, prov, env_dir_path)
module_path = env[:machine].config.r10k.module_path
if prov.config.module_path.is_a?(Array) and ! prov.config.module_path.include?(module_path)
raise ErrorWrapper.new(RuntimeError.new("vagrant-r10k: module_path \"#{module_path}\" is not within the ones defined in puppet provisioner; please correct this condition"))
elsif prov.config.module_path.nil?
env[:ui].info "vagrant-r10k: Puppet provisioner module_path is nil, assuming puppet4 environment mode"
elsif ! prov.config.module_path.is_a?(Array) and prov.config.module_path != module_path
raise ErrorWrapper.new(RuntimeError.new("vagrant-r10k: module_path \"#{module_path}\" is not the same as in puppet provisioner; please correct this condition"))
raise ErrorWrapper.new(RuntimeError.new("vagrant-r10k: module_path \"#{module_path}\" is not the same as in puppet provisioner (#{prov.config.module_path}); please correct this condition"))
end
# no modulepath explict set in config, build one from the provisioner config
else
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/vagrant-r10k/vagrant-r10k_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
status("Test: vagrant up")
up_result = execute('vagrant', 'up', "--provider=#{provider}")
expect(up_result).to exit_with(1)
expect(up_result.stderr).to match('RuntimeError: vagrant-r10k: module_path "puppet/NOTmodules" is not the same as in puppet provisioner; please correct this condition')
expect(up_result.stderr).to match(/RuntimeError: vagrant-r10k: module_path "puppet\/NOTmodules" is not the same as in puppet provisioner \(puppet\/modules\); please correct this condition/)
ensure_r10k_didnt_run(up_result, environment.workdir)
ensure_puppet_didnt_run(up_result)
end
Expand Down
12 changes: 11 additions & 1 deletion spec/unit/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,17 @@
env = {:machine => double, :ui => double}
allow(env[:ui]).to receive(:info).with("vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"\". (if module_path is an array, first element is used)")
env[:machine].stub_chain(:config, :r10k, :module_path).and_return('r10kmodule/path')
expect { module_path(env, prov_dbl, '/env/dir/path') }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /module_path "r10kmodule\/path" is not the same as in puppet provisioner; please correct this condition/)
expect { module_path(env, prov_dbl, '/env/dir/path') }.to raise_error(VagrantPlugins::R10k::Helpers::ErrorWrapper, /module_path "r10kmodule\/path" is not the same as in puppet provisioner \(module\/path\); please correct this condition/)
end
end
context 'config.r10k.module_path set and provisioner module_path nil' do
it 'returns the joined module_path' do
prov_dbl = double
prov_dbl.stub_chain(:config, :module_path).and_return(nil)
env = {:machine => double, :ui => double}
allow(env[:ui]).to receive(:info).with("vagrant-r10k: Puppet provisioner module_path is nil, assuming puppet4 environment mode")
env[:machine].stub_chain(:config, :r10k, :module_path).and_return('module/path')
expect(module_path(env, prov_dbl, '/env/dir/path')).to eq('/env/dir/path/module/path')
end
end
end
Expand Down

0 comments on commit 57523d5

Please sign in to comment.