Provisioner config tests, fixed some bugs
This commit is contained in:
parent
eca25d1802
commit
658affe8cd
|
@ -9,7 +9,8 @@ module Vagrant
|
||||||
|
|
||||||
def initialize(shortcut, options=nil, &block)
|
def initialize(shortcut, options=nil, &block)
|
||||||
@shortcut = shortcut
|
@shortcut = shortcut
|
||||||
@provisioner = Provisioners::Base.registered[shortcut]
|
@provisioner = shortcut
|
||||||
|
@provisioner = Provisioners::Base.registered[shortcut] if shortcut.is_a?(Symbol)
|
||||||
@config = nil
|
@config = nil
|
||||||
|
|
||||||
configure(options, &block)
|
configure(options, &block)
|
||||||
|
@ -19,10 +20,10 @@ module Vagrant
|
||||||
def configure(options=nil, &block)
|
def configure(options=nil, &block)
|
||||||
# We assume that every provisioner has a `Config` class beneath
|
# We assume that every provisioner has a `Config` class beneath
|
||||||
# it for configuring.
|
# it for configuring.
|
||||||
return if !defined?(@provisioner::Config)
|
return if !@provisioner || !@provisioner.const_defined?("Config", false)
|
||||||
|
|
||||||
# Instantiate the config class and configure it
|
# Instantiate the config class and configure it
|
||||||
@config = @provisioner::Config.new
|
@config = @provisioner.const_get("Config", false).new
|
||||||
block.call(@config) if block
|
block.call(@config) if block
|
||||||
|
|
||||||
# TODO: Deal with the options hash
|
# TODO: Deal with the options hash
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ConfigVMProvisionerTest < Test::Unit::TestCase
|
||||||
|
setup do
|
||||||
|
@klass = Vagrant::Config::VMConfig::Provisioner
|
||||||
|
end
|
||||||
|
|
||||||
|
context "initializing" do
|
||||||
|
should "expose the shortcut used" do
|
||||||
|
instance = @klass.new(:chef_solo)
|
||||||
|
assert_equal :chef_solo, instance.shortcut
|
||||||
|
end
|
||||||
|
|
||||||
|
should "expose the provisioner class if its a valid shortcut" do
|
||||||
|
instance = @klass.new(:chef_solo)
|
||||||
|
assert_equal Vagrant::Provisioners::ChefSolo, instance.provisioner
|
||||||
|
end
|
||||||
|
|
||||||
|
should "expose the provisioner class if its a valid class" do
|
||||||
|
instance = @klass.new(Vagrant::Provisioners::ChefSolo)
|
||||||
|
assert_equal Vagrant::Provisioners::ChefSolo, instance.provisioner
|
||||||
|
end
|
||||||
|
|
||||||
|
should "have a nil provisioner class if invalid" do
|
||||||
|
instance = @klass.new(:i_shall_never_exist)
|
||||||
|
assert_nil instance.provisioner
|
||||||
|
end
|
||||||
|
|
||||||
|
should "have a nil config instance if invalid" do
|
||||||
|
instance = @klass.new(:i_shall_never_exist)
|
||||||
|
assert_nil instance.config
|
||||||
|
end
|
||||||
|
|
||||||
|
should "configure the provisioner if valid" do
|
||||||
|
instance = @klass.new(:chef_solo) do |chef|
|
||||||
|
chef.cookbooks_path = "foo"
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal "foo", instance.config.cookbooks_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "validation" do
|
||||||
|
setup do
|
||||||
|
@errors = Vagrant::Config::ErrorRecorder.new
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be invalid if provisioner is valid" do
|
||||||
|
instance = @klass.new(:i_shall_never_exist)
|
||||||
|
instance.validate(@errors)
|
||||||
|
assert !@errors.errors.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be invalid if provisioner doesn't inherit from provisioners base" do
|
||||||
|
klass = Class.new
|
||||||
|
instance = @klass.new(klass)
|
||||||
|
instance.validate(@errors)
|
||||||
|
assert !@errors.errors.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be valid with a valid provisioner" do
|
||||||
|
instance = @klass.new(:chef_solo) do |chef|
|
||||||
|
chef.add_recipe "foo"
|
||||||
|
end
|
||||||
|
|
||||||
|
instance.validate(@errors)
|
||||||
|
assert @errors.errors.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be invalid if a provisioner's config is invalid" do
|
||||||
|
instance = @klass.new(:chef_solo)
|
||||||
|
instance.validate(@errors)
|
||||||
|
assert !@errors.errors.empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue