Added file existence test for the validation key for chef server provisioning

This commit is contained in:
Mitchell Hashimoto 2010-03-10 23:06:20 -08:00
parent 9384917b81
commit 5f695d8f4d
3 changed files with 34 additions and 9 deletions

View File

@ -9,6 +9,12 @@ module Vagrant
Chef server provisioning requires that the `config.chef.validation_key_path` configuration Chef server provisioning requires that the `config.chef.validation_key_path` configuration
be set to a path on your local machine of the validation key used to register the be set to a path on your local machine of the validation key used to register the
VM with the chef server. VM with the chef server.
msg
elsif !File.file?(Vagrant.config.chef.validation_key_path)
raise Actions::ActionException.new(<<-msg)
The validation key set for `config.chef.validation_key_path` does not exist! This
file needs to exist so it can be uploaded to the virtual machine. It is
currently set to "#{Vagrant.config.chef.validation_key_path}"
msg msg
end end

View File

@ -79,8 +79,11 @@ class ProvisionActionTest < Test::Unit::TestCase
config.vm.provisioner = symbol config.vm.provisioner = symbol
end end
instance = mock("instance")
instance.expects(:prepare).once
provisioner.expects(:new).returns(instance)
assert_nothing_raised { @action.prepare } assert_nothing_raised { @action.prepare }
assert @action.provisioner.is_a?(provisioner) assert_equal instance, @action.provisioner
end end
should "raise an ActionException if its an unknown symbol" do should "raise an ActionException if its an unknown symbol" do
@ -100,14 +103,6 @@ class ProvisionActionTest < Test::Unit::TestCase
should "set :chef_server to the ChefServer provisioner" do should "set :chef_server to the ChefServer provisioner" do
provisioner_expectation(:chef_server, Vagrant::Provisioners::ChefServer) provisioner_expectation(:chef_server, Vagrant::Provisioners::ChefServer)
end end
should "call prepare on the instance" do
instance = mock("instance")
instance.expects(:prepare).once
instance.stubs(:is_a?).returns(true)
Vagrant::Provisioners::ChefSolo.expects(:new).returns(instance)
provisioner_expectation(:chef_solo, Vagrant::Provisioners::ChefSolo)
end
end end
end end
end end

View File

@ -24,6 +24,10 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
end end
context "preparing" do context "preparing" do
setup do
File.stubs(:file?).returns(true)
end
should "not raise an exception if validation_key_path is set" do should "not raise an exception if validation_key_path is set" do
mock_config do |config| mock_config do |config|
config.chef.validation_key_path = "7" config.chef.validation_key_path = "7"
@ -42,6 +46,26 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
} }
end end
should "not raise an exception if validation_key_path does exist" do
mock_config do |config|
config.chef.validation_key_path = "7"
end
File.expects(:file?).with(Vagrant.config.chef.validation_key_path).returns(true)
assert_nothing_raised { @action.prepare }
end
should "raise an exception if validation_key_path doesn't exist" do
mock_config do |config|
config.chef.validation_key_path = "7"
end
File.expects(:file?).with(Vagrant.config.chef.validation_key_path).returns(false)
assert_raises(Vagrant::Actions::ActionException) {
@action.prepare
}
end
should "not raise an exception if chef_server_url is set" do should "not raise an exception if chef_server_url is set" do
mock_config do |config| mock_config do |config|
config.chef.chef_server_url = "7" config.chef.chef_server_url = "7"