Get rid of ActionException usage in provisioners
This commit is contained in:
parent
b2c2c76b55
commit
ff7e9dc2ae
|
@ -72,7 +72,7 @@ module Vagrant
|
|||
Config.configures :chef, ChefConfig
|
||||
|
||||
def prepare
|
||||
raise Actions::ActionException.new(:chef_base_invalid_provisioner)
|
||||
action_env.error!(:chef_base_invalid_provisioner)
|
||||
end
|
||||
|
||||
def verify_binary(binary)
|
||||
|
|
|
@ -5,13 +5,11 @@ module Vagrant
|
|||
class ChefServer < Chef
|
||||
def prepare
|
||||
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)
|
||||
raise Actions::ActionException.new(:chef_server_validation_key_doesnt_exist)
|
||||
end
|
||||
|
||||
if env.config.chef.chef_server_url.nil?
|
||||
raise Actions::ActionException.new(:chef_server_url_required)
|
||||
action_env.error!(:chef_server_validation_key_doesnt_exist)
|
||||
elsif env.config.chef.chef_server_url.nil?
|
||||
action_env.error!(:chef_server_url_required)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -36,19 +36,20 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
|
|||
|
||||
@action.stubs(:env).returns(@env)
|
||||
|
||||
assert_nothing_raised { @action.prepare }
|
||||
@action.prepare
|
||||
assert !@action_env.error?
|
||||
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|
|
||||
config.chef.validation_key_path = nil
|
||||
end
|
||||
|
||||
@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
|
||||
|
||||
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")
|
||||
|
||||
File.expects(:file?).with(@action.validation_key_path).returns(true)
|
||||
assert_nothing_raised { @action.prepare }
|
||||
@action.prepare
|
||||
assert !@action_env.error?
|
||||
end
|
||||
|
||||
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")
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
assert_nothing_raised { @action.prepare }
|
||||
@action.prepare
|
||||
assert !@action_env.error?
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
context "preparing" do
|
||||
should "raise an ActionException" do
|
||||
assert_raises(Vagrant::Actions::ActionException) {
|
||||
@action.prepare
|
||||
}
|
||||
should "error the environment" do
|
||||
@action.prepare
|
||||
assert @action_env.error?
|
||||
assert_equal :chef_base_invalid_provisioner, @action_env.error.first
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue