Helper methods on chef config `add_recipe` and `add_role` and `run_list`

This commit is contained in:
Mitchell Hashimoto 2010-03-11 01:05:57 -08:00
parent 5f695d8f4d
commit df2f76297d
2 changed files with 58 additions and 1 deletions

View File

@ -31,6 +31,28 @@ module Vagrant
}
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
# Overridden so that the 'json' key could be removed, since its just
# merged into the config anyways

View File

@ -21,13 +21,48 @@ class ChefProvisionerTest < Test::Unit::TestCase
context "config" do
setup do
@config = Vagrant::Provisioners::Chef::ChefConfig.new
@config.json = "HEY"
@config.run_list.clear
end
should "not include the 'json' key in the config dump" do
result = JSON.parse(@config.to_json)
assert !result.has_key?("json")
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
context "permissions on provisioning folder" do