Fix command builder tests

This commit is contained in:
Seth Vargo 2015-07-09 21:36:50 -06:00
parent 4b1847acf3
commit d72306b6d5
1 changed files with 49 additions and 36 deletions

View File

@ -8,97 +8,110 @@ describe VagrantPlugins::Chef::CommandBuilder do
let(:chef_config) { double("chef_config") } let(:chef_config) { double("chef_config") }
before(:each) do before(:each) do
allow(chef_config).to receive(:provisioning_path).and_return('/tmp/vagrant-chef-1') 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(:arguments).and_return(nil)
allow(chef_config).to receive(:binary_env).and_return(nil) allow(chef_config).to receive(:binary_env).and_return(nil)
allow(chef_config).to receive(:binary_path).and_return(nil) allow(chef_config).to receive(:binary_path).and_return(nil)
allow(chef_config).to receive(:binary_env).and_return(nil) allow(chef_config).to receive(:binary_env).and_return(nil)
allow(chef_config).to receive(:log_level).and_return(:info)
end end
describe '.initialize' do describe ".initialize" do
it 'should raise when chef type is not client or solo' do it "raises an error when chef type is not client or solo" do
expect { VagrantPlugins::Chef::CommandBuilder.new(chef_config, :client_bad) }. expect { VagrantPlugins::Chef::CommandBuilder.new(chef_config, :client_bad) }.
to raise_error to raise_error
end end
it "does not raise an error for :client" do
expect {
VagrantPlugins::Chef::CommandBuilder.new(:client, chef_config)
}.to_not raise_error
end
it "does not raise an error for :solo" do
expect {
VagrantPlugins::Chef::CommandBuilder.new(:solo, chef_config)
}.to_not raise_error
end
end end
describe 'build_command' do describe "#command" do
describe 'windows' do describe "windows" do
subject do subject do
VagrantPlugins::Chef::CommandBuilder.new(chef_config, :client, true) VagrantPlugins::Chef::CommandBuilder.new(:client, chef_config, windows: true)
end end
it "executes the chef-client in PATH by default" do it "executes the chef-client in PATH by default" do
expect(subject.build_command()).to match(/^chef-client/) expect(subject.command).to match(/^chef-client/)
end end
it "executes the chef-client using full path if binary_path is specified" do it "executes the chef-client using full path if binary_path is specified" do
allow(chef_config).to receive(:binary_path).and_return( allow(chef_config).to receive(:binary_path).and_return(
"c:\\opscode\\chef\\bin\\chef-client") "c:\\opscode\\chef\\bin\\chef-client")
expect(subject.build_command()).to match(/^c:\\opscode\\chef\\bin\\chef-client\\chef-client/) expect(subject.command).to match(/^c:\\opscode\\chef\\bin\\chef-client\\chef-client/)
end end
it "builds a guest friendly client.rb path" do it "builds a guest friendly client.rb path" do
expect(subject.build_command()).to include( expect(subject.command).to include(
'-c c:\\tmp\\vagrant-chef-1\\client.rb') '--config c:\\tmp\\vagrant-chef-1\\client.rb')
end end
it "builds a guest friendly solo.json path" do it "builds a guest friendly solo.json path" do
expect(subject.build_command()).to include( expect(subject.command).to include(
'-j c:\\tmp\\vagrant-chef-1\\dna.json') '--json-attributes c:\\tmp\\vagrant-chef-1\\dna.json')
end end
it 'includes Chef arguments if specified' do it "includes Chef arguments if specified" do
allow(chef_config).to receive(:arguments).and_return("-l DEBUG") allow(chef_config).to receive(:arguments).and_return("bacon pants")
expect(subject.build_command()).to include( expect(subject.command).to include(
'-l DEBUG') " bacon pants")
end end
it 'includes --no-color if UI is not colored' do it "includes --no-color if UI is not colored" do
expect(subject.build_command()).to include( expect(subject.command).to include(
' --no-color') " --no-color")
end end
end end
describe 'linux' do describe "linux" do
subject do subject do
VagrantPlugins::Chef::CommandBuilder.new(chef_config, :client, false) VagrantPlugins::Chef::CommandBuilder.new(:client, chef_config, windows: false)
end end
it "executes the chef-client in PATH by default" do it "executes the chef-client in PATH by default" do
expect(subject.build_command()).to match(/^chef-client/) expect(subject.command).to match(/^chef-client/)
end end
it "executes the chef-client using full path if binary_path is specified" do it "executes the chef-client using full path if binary_path is specified" do
allow(chef_config).to receive(:binary_path).and_return( allow(chef_config).to receive(:binary_path).and_return(
"/opt/chef/chef-client") "/opt/chef/chef-client")
expect(subject.build_command()).to match(/^\/opt\/chef\/chef-client/) expect(subject.command).to match(/^\/opt\/chef\/chef-client/)
end end
it "builds a guest friendly client.rb path" do it "builds a guest friendly client.rb path" do
expect(subject.build_command()).to include( expect(subject.command).to include(
'-c /tmp/vagrant-chef-1/client.rb') "--config /tmp/vagrant-chef-1/client.rb")
end end
it "builds a guest friendly solo.json path" do it "builds a guest friendly solo.json path" do
expect(subject.build_command()).to include( expect(subject.command).to include(
'-j /tmp/vagrant-chef-1/dna.json') "--json-attributes /tmp/vagrant-chef-1/dna.json")
end end
it 'includes Chef arguments if specified' do it "includes Chef arguments if specified" do
allow(chef_config).to receive(:arguments).and_return("-l DEBUG") allow(chef_config).to receive(:arguments).and_return("bacon")
expect(subject.build_command()).to include( expect(subject.command).to include(
'-l DEBUG') " bacon")
end end
it 'includes --no-color if UI is not colored' do it "includes --no-color if UI is not colored" do
expect(subject.build_command()).to include( expect(subject.command).to include(
' --no-color') " --no-color")
end end
it 'includes environment variables if specified' do it "includes environment variables if specified" do
allow(chef_config).to receive(:binary_env).and_return("ENVVAR=VAL") allow(chef_config).to receive(:binary_env).and_return("ENVVAR=VAL")
expect(subject.build_command()).to match(/^ENVVAR=VAL /) expect(subject.command).to match(/^ENVVAR=VAL /)
end end
end end
end end