Helper methods on chef config `add_recipe` and `add_role` and `run_list`
This commit is contained in:
parent
5f695d8f4d
commit
df2f76297d
|
@ -31,6 +31,28 @@ module Vagrant
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the run list for the provisioning
|
||||||
|
def run_list
|
||||||
|
json[:run_list]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sets the run list to the specified value
|
||||||
|
def run_list=(value)
|
||||||
|
json[:run_list] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
# Adds a recipe to the run list
|
||||||
|
def add_recipe(name)
|
||||||
|
name = "recipe[#{name}]" unless name =~ /^recipe\[(.+?)\]$/
|
||||||
|
run_list << name
|
||||||
|
end
|
||||||
|
|
||||||
|
# Adds a role to the run list
|
||||||
|
def add_role(name)
|
||||||
|
name = "role[#{name}]" unless name =~ /^role\[(.+?)\]$/
|
||||||
|
run_list << name
|
||||||
|
end
|
||||||
|
|
||||||
def to_json
|
def to_json
|
||||||
# Overridden so that the 'json' key could be removed, since its just
|
# Overridden so that the 'json' key could be removed, since its just
|
||||||
# merged into the config anyways
|
# merged into the config anyways
|
||||||
|
|
|
@ -21,13 +21,48 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
||||||
context "config" do
|
context "config" do
|
||||||
setup do
|
setup do
|
||||||
@config = Vagrant::Provisioners::Chef::ChefConfig.new
|
@config = Vagrant::Provisioners::Chef::ChefConfig.new
|
||||||
@config.json = "HEY"
|
@config.run_list.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not include the 'json' key in the config dump" do
|
should "not include the 'json' key in the config dump" do
|
||||||
result = JSON.parse(@config.to_json)
|
result = JSON.parse(@config.to_json)
|
||||||
assert !result.has_key?("json")
|
assert !result.has_key?("json")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "provide accessors to the run list" do
|
||||||
|
@config.run_list << "foo"
|
||||||
|
assert !@config.run_list.empty?
|
||||||
|
assert_equal ["foo"], @config.run_list
|
||||||
|
end
|
||||||
|
|
||||||
|
should "provide a writer for the run list" do
|
||||||
|
data = mock("data")
|
||||||
|
|
||||||
|
assert_nothing_raised {
|
||||||
|
@config.run_list = data
|
||||||
|
assert_equal data, @config.run_list
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
should "add a recipe to the run list" do
|
||||||
|
@config.add_recipe("foo")
|
||||||
|
assert_equal "recipe[foo]", @config.run_list[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not wrap the recipe in 'recipe[]' if it was in the name" do
|
||||||
|
@config.add_recipe("recipe[foo]")
|
||||||
|
assert_equal "recipe[foo]", @config.run_list[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
should "add a role to the run list" do
|
||||||
|
@config.add_role("user")
|
||||||
|
assert_equal "role[user]", @config.run_list[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not wrap the role in 'role[]' if it was in the name" do
|
||||||
|
@config.add_role("role[user]")
|
||||||
|
assert_equal "role[user]", @config.run_list[0]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "permissions on provisioning folder" do
|
context "permissions on provisioning folder" do
|
||||||
|
|
Loading…
Reference in New Issue