2014-04-26 02:51:18 +00:00
|
|
|
require_relative "../../../base"
|
|
|
|
|
|
|
|
require Vagrant.source_root.join("plugins/provisioners/chef/command_builder")
|
|
|
|
|
|
|
|
describe VagrantPlugins::Chef::CommandBuilder do
|
|
|
|
|
|
|
|
let(:machine) { double("machine") }
|
|
|
|
let(:chef_config) { double("chef_config") }
|
|
|
|
|
|
|
|
before(:each) do
|
2015-07-10 03:36:50 +00:00
|
|
|
allow(chef_config).to receive(:provisioning_path).and_return("/tmp/vagrant-chef-1")
|
2014-04-26 02:51:18 +00:00
|
|
|
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)
|
|
|
|
allow(chef_config).to receive(:binary_env).and_return(nil)
|
2015-07-10 03:36:50 +00:00
|
|
|
allow(chef_config).to receive(:log_level).and_return(:info)
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
2015-07-10 03:36:50 +00:00
|
|
|
describe ".initialize" do
|
|
|
|
it "raises an error when chef type is not client or solo" do
|
2014-04-26 02:51:18 +00:00
|
|
|
expect { VagrantPlugins::Chef::CommandBuilder.new(chef_config, :client_bad) }.
|
|
|
|
to raise_error
|
|
|
|
end
|
2015-07-10 03:36:50 +00:00
|
|
|
|
|
|
|
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
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
2015-07-10 03:36:50 +00:00
|
|
|
describe "#command" do
|
|
|
|
describe "windows" do
|
2014-04-26 02:51:18 +00:00
|
|
|
subject do
|
2015-07-10 03:36:50 +00:00
|
|
|
VagrantPlugins::Chef::CommandBuilder.new(:client, chef_config, windows: true)
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "executes the chef-client in PATH by default" do
|
2015-07-10 03:36:50 +00:00
|
|
|
expect(subject.command).to match(/^chef-client/)
|
2014-04-26 02:51:18 +00:00
|
|
|
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")
|
2015-07-10 03:36:50 +00:00
|
|
|
expect(subject.command).to match(/^c:\\opscode\\chef\\bin\\chef-client\\chef-client/)
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "builds a guest friendly client.rb path" do
|
2015-07-10 03:36:50 +00:00
|
|
|
expect(subject.command).to include(
|
|
|
|
'--config c:\\tmp\\vagrant-chef-1\\client.rb')
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "builds a guest friendly solo.json path" do
|
2015-07-10 03:36:50 +00:00
|
|
|
expect(subject.command).to include(
|
|
|
|
'--json-attributes c:\\tmp\\vagrant-chef-1\\dna.json')
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
2015-07-10 03:36:50 +00:00
|
|
|
it "includes Chef arguments if specified" do
|
|
|
|
allow(chef_config).to receive(:arguments).and_return("bacon pants")
|
|
|
|
expect(subject.command).to include(
|
|
|
|
" bacon pants")
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
2015-07-10 03:36:50 +00:00
|
|
|
it "includes --no-color if UI is not colored" do
|
|
|
|
expect(subject.command).to include(
|
|
|
|
" --no-color")
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-10 03:36:50 +00:00
|
|
|
describe "linux" do
|
2014-04-26 02:51:18 +00:00
|
|
|
subject do
|
2015-07-10 03:36:50 +00:00
|
|
|
VagrantPlugins::Chef::CommandBuilder.new(:client, chef_config, windows: false)
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "executes the chef-client in PATH by default" do
|
2015-07-10 03:36:50 +00:00
|
|
|
expect(subject.command).to match(/^chef-client/)
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "executes the chef-client using full path if binary_path is specified" do
|
|
|
|
allow(chef_config).to receive(:binary_path).and_return(
|
|
|
|
"/opt/chef/chef-client")
|
2015-07-10 03:36:50 +00:00
|
|
|
expect(subject.command).to match(/^\/opt\/chef\/chef-client/)
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "builds a guest friendly client.rb path" do
|
2015-07-10 03:36:50 +00:00
|
|
|
expect(subject.command).to include(
|
|
|
|
"--config /tmp/vagrant-chef-1/client.rb")
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "builds a guest friendly solo.json path" do
|
2015-07-10 03:36:50 +00:00
|
|
|
expect(subject.command).to include(
|
|
|
|
"--json-attributes /tmp/vagrant-chef-1/dna.json")
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
2015-07-10 03:36:50 +00:00
|
|
|
it "includes Chef arguments if specified" do
|
|
|
|
allow(chef_config).to receive(:arguments).and_return("bacon")
|
|
|
|
expect(subject.command).to include(
|
|
|
|
" bacon")
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
2015-07-10 03:36:50 +00:00
|
|
|
it "includes --no-color if UI is not colored" do
|
|
|
|
expect(subject.command).to include(
|
|
|
|
" --no-color")
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
|
2015-07-10 03:36:50 +00:00
|
|
|
it "includes environment variables if specified" do
|
2014-04-26 02:51:18 +00:00
|
|
|
allow(chef_config).to receive(:binary_env).and_return("ENVVAR=VAL")
|
2015-07-10 03:36:50 +00:00
|
|
|
expect(subject.command).to match(/^ENVVAR=VAL /)
|
2014-04-26 02:51:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|