From e4fd4f0e00bc64abb5acf6517593063e2666ea7e Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Thu, 1 Aug 2013 12:29:12 -0700 Subject: Add methods to query for template/file existence in run context - Convenience methods added to CookbookVersion to query if a cookbook file or template is available for a given node in that cookbook - Convenience methods added to RunContext to query the existence of cookbook files or templates --- spec/unit/run_context_spec.rb | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'spec/unit/run_context_spec.rb') diff --git a/spec/unit/run_context_spec.rb b/spec/unit/run_context_spec.rb index 51fa0e81f9..d75d6628bb 100644 --- a/spec/unit/run_context_spec.rb +++ b/spec/unit/run_context_spec.rb @@ -19,6 +19,7 @@ # require 'spec_helper' +require 'support/lib/library_load_order' Chef::Log.level = :debug @@ -42,7 +43,7 @@ describe Chef::RunContext do @run_context.node.should == @node end - describe "after loading the cookbooks" do + describe "loading cookbooks for a run list" do before do @run_context.load(@node.run_list.expand('_default')) end @@ -73,6 +74,46 @@ describe Chef::RunContext do @node.should_not_receive(:from_file) @node.include_attribute("test::george") end + + + end + + describe "querying the contents of cookbooks" do + before do + @chef_repo_path = File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks")) + cl = Chef::CookbookLoader.new(@chef_repo_path) + cl.load_cookbooks + @cookbook_collection = Chef::CookbookCollection.new(cl) + @node = Chef::Node.new + @node.set[:platform] = "ubuntu" + @node.set[:platform_version] = "13.04" + @node.name("testing") + @events = Chef::EventDispatch::Dispatcher.new + @run_context = Chef::RunContext.new(@node, @cookbook_collection, @events) + end + + + it "queries whether a given cookbook has a specific template" do + @run_context.should have_template_in_cookbook("openldap", "test.erb") + @run_context.should_not have_template_in_cookbook("openldap", "missing.erb") + end + + it "errors when querying for a template in a not-available cookbook" do + expect do + @run_context.has_template_in_cookbook?("no-such-cookbook", "foo.erb") + end.to raise_error(Chef::Exceptions::CookbookNotFound) + end + + it "queries whether a given cookbook has a specific cookbook_file" do + @run_context.should have_cookbook_file_in_cookbook("java", "java.response") + @run_context.should_not have_cookbook_file_in_cookbook("java", "missing.txt") + end + + it "errors when querying for a cookbook_file in a not-available cookbook" do + expect do + @run_context.has_cookbook_file_in_cookbook?("no-such-cookbook", "foo.txt") + end.to raise_error(Chef::Exceptions::CookbookNotFound) + end end end -- cgit v1.2.1