Get rid of ActionException usage in provisioners

This commit is contained in:
Mitchell Hashimoto 2010-07-08 20:48:01 -07:00
parent b2c2c76b55
commit ff7e9dc2ae
4 changed files with 25 additions and 24 deletions

View File

@ -72,7 +72,7 @@ module Vagrant
Config.configures :chef, ChefConfig Config.configures :chef, ChefConfig
def prepare def prepare
raise Actions::ActionException.new(:chef_base_invalid_provisioner) action_env.error!(:chef_base_invalid_provisioner)
end end
def verify_binary(binary) def verify_binary(binary)

View File

@ -5,13 +5,11 @@ module Vagrant
class ChefServer < Chef class ChefServer < Chef
def prepare def prepare
if env.config.chef.validation_key_path.nil? if env.config.chef.validation_key_path.nil?
raise Actions::ActionException.new(:chef_server_validation_key_required) action_env.error!(:chef_server_validation_key_required)
elsif !File.file?(validation_key_path) elsif !File.file?(validation_key_path)
raise Actions::ActionException.new(:chef_server_validation_key_doesnt_exist) action_env.error!(:chef_server_validation_key_doesnt_exist)
end elsif env.config.chef.chef_server_url.nil?
action_env.error!(:chef_server_url_required)
if env.config.chef.chef_server_url.nil?
raise Actions::ActionException.new(:chef_server_url_required)
end end
end end

View File

@ -36,19 +36,20 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
@action.stubs(:env).returns(@env) @action.stubs(:env).returns(@env)
assert_nothing_raised { @action.prepare } @action.prepare
assert !@action_env.error?
end end
should "raise an exception if validation_key_path is nil" do should "eraise an exception if validation_key_path is nil" do
@env = mock_environment do |config| @env = mock_environment do |config|
config.chef.validation_key_path = nil config.chef.validation_key_path = nil
end end
@action.stubs(:env).returns(@env) @action.stubs(:env).returns(@env)
assert_raises(Vagrant::Actions::ActionException) { @action.prepare
@action.prepare assert @action_env.error?
} assert_equal :chef_server_validation_key_required, @action_env.error.first
end end
should "not raise an exception if validation_key_path does exist" do should "not raise an exception if validation_key_path does exist" do
@ -60,7 +61,8 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
@action.stubs(:validation_key_path).returns("9") @action.stubs(:validation_key_path).returns("9")
File.expects(:file?).with(@action.validation_key_path).returns(true) File.expects(:file?).with(@action.validation_key_path).returns(true)
assert_nothing_raised { @action.prepare } @action.prepare
assert !@action_env.error?
end end
should "raise an exception if validation_key_path doesn't exist" do should "raise an exception if validation_key_path doesn't exist" do
@ -72,9 +74,9 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
@action.stubs(:validation_key_path).returns("9") @action.stubs(:validation_key_path).returns("9")
File.expects(:file?).with(@action.validation_key_path).returns(false) File.expects(:file?).with(@action.validation_key_path).returns(false)
assert_raises(Vagrant::Actions::ActionException) { @action.prepare
@action.prepare assert @action_env.error?
} assert_equal :chef_server_validation_key_doesnt_exist, @action_env.error.first
end 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
@ -84,7 +86,8 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
@action.stubs(:env).returns(@env) @action.stubs(:env).returns(@env)
assert_nothing_raised { @action.prepare } @action.prepare
assert !@action_env.error?
end end
should "raise an exception if chef_server_url is nil" do should "raise an exception if chef_server_url is nil" do
@ -94,9 +97,9 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
@action.stubs(:env).returns(@env) @action.stubs(:env).returns(@env)
assert_raises(Vagrant::Actions::ActionException) { @action.prepare
@action.prepare assert @action_env.error?
} assert_equal :chef_server_url_required, @action_env.error.first
end end
end end

View File

@ -11,10 +11,10 @@ class ChefProvisionerTest < Test::Unit::TestCase
end end
context "preparing" do context "preparing" do
should "raise an ActionException" do should "error the environment" do
assert_raises(Vagrant::Actions::ActionException) { @action.prepare
@action.prepare assert @action_env.error?
} assert_equal :chef_base_invalid_provisioner, @action_env.error.first
end end
end end