diff options
author | danielsdeleo <dan@opscode.com> | 2012-11-07 15:33:39 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2012-11-07 15:33:39 -0800 |
commit | 627b8684221b07227ef4983fd58170f5e02b4431 (patch) | |
tree | 7ff9a2c8b777575b1dd51414afac29353a035ca2 /spec/unit/run_context_spec.rb | |
parent | 949e584b504aa4b757eed7580512d1fcbf5e183b (diff) | |
download | chef-627b8684221b07227ef4983fd58170f5e02b4431.tar.gz |
[CHEF-2903] load attribute files in run_list order
Diffstat (limited to 'spec/unit/run_context_spec.rb')
-rw-r--r-- | spec/unit/run_context_spec.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/unit/run_context_spec.rb b/spec/unit/run_context_spec.rb index 51fa0e81f9..b742a2f1c7 100644 --- a/spec/unit/run_context_spec.rb +++ b/spec/unit/run_context_spec.rb @@ -42,6 +42,63 @@ describe Chef::RunContext do @run_context.node.should == @node end + def fixture_cb_path(rel_path) + File.expand_path(rel_path, @chef_repo_path) + end + + # This test relies on fixture data in spec/data/run_context/cookbooks. + # The behaviors described in these examples are affected by the metadata.rb + # files in those cookbooks. + describe "loading attribute files" do + + it "loads default.rb first, then other files in sort order" do + @node.run_list("dependency1::default") + @expansion = (@node.run_list.expand('_default')) + + @run_context.should_receive(:load_attribute_file).with("dependency1", fixture_cb_path("dependency1/attributes/default.rb")).ordered + @run_context.should_receive(:load_attribute_file).with("dependency1", fixture_cb_path("dependency1/attributes/aa_first.rb")).ordered + @run_context.should_receive(:load_attribute_file).with("dependency1", fixture_cb_path("dependency1/attributes/zz_last.rb")).ordered + + @run_context.load_attributes_in_run_list_order(@expansion) + end + + it "loads dependencies before loading the depending cookbook's attributes" do + # Also make sure that attributes aren't loaded twice if we have two + # recipes from the same cookbook in the run list + @node.run_list("test-with-deps::default", "test-with-deps::server") + @expansion = (@node.run_list.expand('_default')) + + # dependencies are stored in a hash so therefore unordered, but they should be loaded in sort order + @run_context.should_receive(:load_attribute_file).with("dependency1", fixture_cb_path("dependency1/attributes/default.rb")).ordered + @run_context.should_receive(:load_attribute_file).with("dependency1", fixture_cb_path("dependency1/attributes/aa_first.rb")).ordered + @run_context.should_receive(:load_attribute_file).with("dependency1", fixture_cb_path("dependency1/attributes/zz_last.rb")).ordered + @run_context.should_receive(:load_attribute_file).with("dependency2", fixture_cb_path("dependency2/attributes/default.rb")).ordered + @run_context.should_receive(:load_attribute_file).with("test-with-deps", fixture_cb_path("test-with-deps/attributes/default.rb")).ordered + + @run_context.load_attributes_in_run_list_order(@expansion) + end + + it "does not follow infinite dependency loops" do + @node.run_list("test-with-circular-deps::default") + @expansion = (@node.run_list.expand('_default')) + + # Circular deps should not cause infinite loops + @run_context.should_receive(:load_attribute_file).with("circular-dep2", fixture_cb_path("circular-dep2/attributes/default.rb")).ordered + @run_context.should_receive(:load_attribute_file).with("circular-dep1", fixture_cb_path("circular-dep1/attributes/default.rb")).ordered + @run_context.should_receive(:load_attribute_file).with("test-with-circular-deps", fixture_cb_path("test-with-circular-deps/attributes/default.rb")).ordered + + @run_context.load_attributes_in_run_list_order(@expansion) + end + + it "loads attributes from cookbooks that don't have a default.rb attribute file" do + @node.run_list("no-default-attr::default.rb") + @expansion = (@node.run_list.expand('_default')) + + @run_context.should_receive(:load_attribute_file).with("no-default-attr", fixture_cb_path("no-default-attr/attributes/server.rb")) + @run_context.load_attributes_in_run_list_order(@expansion) + end + end + describe "after loading the cookbooks" do before do @run_context.load(@node.run_list.expand('_default')) |