From ebca0e7e44d54fb35d442871e57582299424fcbb Mon Sep 17 00:00:00 2001 From: Shawn Neal Date: Fri, 25 Apr 2014 18:56:54 -0700 Subject: [PATCH] Fixed bug in CommandBuilderWindows CommandBuilderWindows would not include the Chef binary in the command when the binary_path was specified in the config. Backfilled unit tests for CommandBuilderWindows --- .../chef/command_builder_windows.rb | 3 +- .../chef/command_build_windows_spec.rb | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/unit/plugins/provisioners/chef/command_build_windows_spec.rb diff --git a/plugins/provisioners/chef/command_builder_windows.rb b/plugins/provisioners/chef/command_builder_windows.rb index f8add1931..4c5439d62 100644 --- a/plugins/provisioners/chef/command_builder_windows.rb +++ b/plugins/provisioners/chef/command_builder_windows.rb @@ -26,7 +26,8 @@ module VagrantPlugins def win_path(path) path.gsub!("/", "\\") - "c:#{path}" if path.start_with?("\\") + path = "c:#{path}" if path.start_with?("\\") + path end end end diff --git a/test/unit/plugins/provisioners/chef/command_build_windows_spec.rb b/test/unit/plugins/provisioners/chef/command_build_windows_spec.rb new file mode 100644 index 000000000..5b8d4f325 --- /dev/null +++ b/test/unit/plugins/provisioners/chef/command_build_windows_spec.rb @@ -0,0 +1,55 @@ +require_relative "../../../base" + +require Vagrant.source_root.join("plugins/provisioners/chef/command_builder_windows") + +describe VagrantPlugins::Chef::CommandBuilderWindows do + + let(:machine) { double("machine") } + let(:chef_config) { double("chef_config") } + + subject do + VagrantPlugins::Chef::CommandBuilderWindows.new(machine, chef_config, :client) + end + + before(:each) do + allow(chef_config).to receive(:provisioning_path).and_return('/tmp/vagrant-chef-1') + allow(chef_config).to receive(:arguments).and_return(nil) + allow(chef_config).to receive(:binary_env).and_return(nil) + allow(chef_config).to receive(:binary_path).and_return(nil) + end + + describe '.initialize' do + it 'should raise when chef type is not client or solo' do + expect { VagrantPlugins::Chef::CommandBuilderWindows.new(machine, chef_config, :client_bad) }. + to raise_error + end + end + + describe '.build_command' do + it "executes the chef-client in PATH by default" do + expect(subject.build_command()).to match(/^chef-client/) + end + + it "executes the chef-client using full path if binary_path is specified" do + allow(chef_config).to receive(:binary_path).and_return( + "c:\\opscode\\chef\\bin\\chef-client") + expect(subject.build_command()).to match(/^c:\\opscode\\chef\\bin\\chef-client\\chef-client/) + end + + it "builds a windows friendly client.rb path" do + expect(subject.build_command()).to include( + '-c c:\\tmp\\vagrant-chef-1\\client.rb') + end + + it "builds a windows friendly solo.json path" do + expect(subject.build_command()).to include( + '-j c:\\tmp\\vagrant-chef-1\\dna.json') + end + + it 'includes Chef arguments if specified' do + allow(chef_config).to receive(:arguments).and_return("-l DEBUG") + expect(subject.build_command()).to include( + '-l DEBUG') + end + end +end