From 5f695d8f4d3d112d6c76af24d5d2b3ee10dc8c48 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 10 Mar 2010 23:06:20 -0800 Subject: [PATCH] Added file existence test for the validation key for chef server provisioning --- lib/vagrant/provisioners/chef_server.rb | 6 +++++ test/vagrant/actions/vm/provision_test.rb | 13 ++++------ test/vagrant/provisioners/chef_server_test.rb | 24 +++++++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/vagrant/provisioners/chef_server.rb b/lib/vagrant/provisioners/chef_server.rb index 4aa971929..88e8a93cc 100644 --- a/lib/vagrant/provisioners/chef_server.rb +++ b/lib/vagrant/provisioners/chef_server.rb @@ -9,6 +9,12 @@ module Vagrant 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 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 end diff --git a/test/vagrant/actions/vm/provision_test.rb b/test/vagrant/actions/vm/provision_test.rb index cc3448f8a..630296634 100644 --- a/test/vagrant/actions/vm/provision_test.rb +++ b/test/vagrant/actions/vm/provision_test.rb @@ -79,8 +79,11 @@ class ProvisionActionTest < Test::Unit::TestCase config.vm.provisioner = symbol end + instance = mock("instance") + instance.expects(:prepare).once + provisioner.expects(:new).returns(instance) assert_nothing_raised { @action.prepare } - assert @action.provisioner.is_a?(provisioner) + assert_equal instance, @action.provisioner end 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 provisioner_expectation(:chef_server, Vagrant::Provisioners::ChefServer) 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 diff --git a/test/vagrant/provisioners/chef_server_test.rb b/test/vagrant/provisioners/chef_server_test.rb index 8b8ddd462..7212a3604 100644 --- a/test/vagrant/provisioners/chef_server_test.rb +++ b/test/vagrant/provisioners/chef_server_test.rb @@ -24,6 +24,10 @@ class ChefServerProvisionerTest < Test::Unit::TestCase end context "preparing" do + setup do + File.stubs(:file?).returns(true) + end + should "not raise an exception if validation_key_path is set" do mock_config do |config| config.chef.validation_key_path = "7" @@ -42,6 +46,26 @@ class ChefServerProvisionerTest < Test::Unit::TestCase } 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 mock_config do |config| config.chef.chef_server_url = "7"