summaryrefslogtreecommitdiff
path: root/spec/unit/run_context_spec.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-08-01 12:29:12 -0700
committerdanielsdeleo <dan@opscode.com>2013-08-02 09:29:05 -0700
commite4fd4f0e00bc64abb5acf6517593063e2666ea7e (patch)
treef666cde81ea63c59dae13d9361ac8c1684aadec9 /spec/unit/run_context_spec.rb
parentf3262fc1d1ba12bf31de6dff421c8e77d6692bc7 (diff)
downloadchef-e4fd4f0e00bc64abb5acf6517593063e2666ea7e.tar.gz
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
Diffstat (limited to 'spec/unit/run_context_spec.rb')
-rw-r--r--spec/unit/run_context_spec.rb43
1 files changed, 42 insertions, 1 deletions
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