Skip to content

Commit

Permalink
Fixed bug in CommandBuilderWindows
Browse files Browse the repository at this point in the history
CommandBuilderWindows would not include the Chef binary in the command when the binary_path was specified in the config.

Backfilled unit tests for CommandBuilderWindows
  • Loading branch information
sneal committed Apr 27, 2014
1 parent 68ce065 commit ebca0e7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugins/provisioners/chef/command_builder_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def provisioning_path(file)

def win_path(path)
path.gsub!("/", "\\")
"c:#{path}" if path.start_with?("\\")
path = "c:#{path}" if path.start_with?("\\")
path
end
end
end
Expand Down
55 changes: 55 additions & 0 deletions test/unit/plugins/provisioners/chef/command_build_windows_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ebca0e7

Please sign in to comment.