diff options
author | Bryan McLellan <btm@opscode.com> | 2011-10-10 07:48:15 -0700 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2011-10-10 07:48:15 -0700 |
commit | fb5474eed66b72950b16e055228ba62ced8b5d80 (patch) | |
tree | 388c73671dd6ae33cea2bf885d1efa69d6381e67 | |
parent | ed19f82517633bba817e3ebbc1f95696b7dab505 (diff) | |
parent | 4f3c0a38216e68c663c2eb00147d14f210db7f5c (diff) | |
download | chef-fb5474eed66b72950b16e055228ba62ced8b5d80.tar.gz |
Merge branch 'CHEF-2674'
3 files changed, 35 insertions, 24 deletions
diff --git a/chef-server-api/spec/unit/cookbooks_controller_spec.rb b/chef-server-api/spec/unit/cookbooks_controller_spec.rb index cf103b9a0f..8a72fd0a95 100644 --- a/chef-server-api/spec/unit/cookbooks_controller_spec.rb +++ b/chef-server-api/spec/unit/cookbooks_controller_spec.rb @@ -21,7 +21,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_model_helper') require 'chef/node' require 'pp' -describe "Coobkooks Controller" do +describe "Cookbooks Controller" do before do Merb.logger.set_log(StringIO.new) end diff --git a/chef-server-api/spec/unit/environments_controller_spec.rb b/chef-server-api/spec/unit/environments_controller_spec.rb index 50ad38613c..0cf26f6717 100644 --- a/chef-server-api/spec/unit/environments_controller_spec.rb +++ b/chef-server-api/spec/unit/environments_controller_spec.rb @@ -27,17 +27,21 @@ describe "Environments controller" do @env1 = make_environment("env1") - @filtered_cookbook_list_env1 = make_filtered_cookbook_hash(make_cookbook("cookbook1", "1.0.0"), - make_cookbook("cookbook2", "1.0.0")) + @cookbook1_v1 = make_cookbook("cookbook1", "1.0.0") + @cookbook2_v1 = make_cookbook("cookbook2", "1.0.0") + @filtered_cookbook_list_env1 = make_filtered_cookbook_hash(@cookbook1_v1, @cookbook2_v1) @filtered_cookbook_list_env1["cookbook_noversions"] = Array.new - @filtered_cookbook_list_env2 = make_filtered_cookbook_hash(make_cookbook("cookbook1", "2.0.0"), - make_cookbook("cookbook2", "2.0.0")) + @cookbook1_v2 = make_cookbook("cookbook1", "2.0.0") + @cookbook2_v2 = make_cookbook("cookbook2", "2.0.0") + @filtered_cookbook_list_env2 = make_filtered_cookbook_hash(@cookbook1_v2, @cookbook2_v2) - @filtered_cookbook_list_env_many_versions = make_filtered_cookbook_hash(make_cookbook("cookbook1", "1.0.0"), - make_cookbook("cookbook1", "2.0.0"), - make_cookbook("cookbook1", "3.0.0"), - make_cookbook("cookbook1", "4.0.0")) + @cookbook1_v3 = make_cookbook("cookbook1", "3.0.0") + @cookbook1_v4 = make_cookbook("cookbook1", "4.0.0") + @filtered_cookbook_list_env_many_versions = make_filtered_cookbook_hash(@cookbook1_v1, + @cookbook1_v2, + @cookbook1_v3, + @cookbook1_v4) @cookbook_deps_on_nosuch = make_cookbook("cookbook_deps_on_nosuch", "1.0.0") @cookbook_deps_on_nosuch.metadata.depends("cookbook_nosuch") @@ -48,10 +52,10 @@ describe "Environments controller" do describe "when handling Environments API calls" do it "should expand the passed-in run_list using the correct environment: one run_list item" do - # Env1 pins both versions at 1.0.0. Expect only the one we ask for, cookbook1, # back in the result. - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("env1", nil).and_return(@filtered_cookbook_list_env1) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("env1", nil).and_return(@filtered_cookbook_list_env1) + Chef::MinimalCookbookVersion.should_receive(:load_full_versions_of).with([@cookbook1_v1], nil).and_return([@cookbook1_v1]) response = post_json("/environments/env1/cookbook_versions", {"run_list" => ["recipe[cookbook1]"]}) response.should be_kind_of(Hash) response.keys.size.should == 1 @@ -62,7 +66,8 @@ describe "Environments controller" do it "should expect the passed-in run_list using the correct environment: two run_list items" do # Ask for both cookbook1 and cookbook2 back. Expect version 2.0.0 for # each, as those are what's appropriate for the environment. - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("env2", nil).and_return(@filtered_cookbook_list_env2) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("env2", nil).and_return(@filtered_cookbook_list_env2) + Chef::MinimalCookbookVersion.should_receive(:load_full_versions_of).with([@cookbook2_v2, @cookbook1_v2], nil).and_return([@cookbook2_v2, @cookbook1_v2]) response = post_json("/environments/env2/cookbook_versions", {"run_list" => ["recipe[cookbook2]", "recipe[cookbook1]"]}) response.should be_kind_of(Hash) response.keys.size.should == 2 @@ -73,7 +78,8 @@ describe "Environments controller" do end it "should return the newest version of a cookbook when given multiple versions" do - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("env_many_versions", nil).and_return(@filtered_cookbook_list_env_many_versions) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("env_many_versions", nil).and_return(@filtered_cookbook_list_env_many_versions) + Chef::MinimalCookbookVersion.should_receive(:load_full_versions_of).with([@cookbook1_v4], nil).and_return([@cookbook1_v4]) response = post_json("/environments/env_many_versions/cookbook_versions", {"run_list" => ["recipe[cookbook1]"]}) response.should be_kind_of(Hash) @@ -83,7 +89,8 @@ describe "Environments controller" do end it "should return the asked-for, older version of a cookbook if the version is specified in the run_list" do - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("env_many_versions", nil).and_return(@filtered_cookbook_list_env_many_versions) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("env_many_versions", nil).and_return(@filtered_cookbook_list_env_many_versions) + Chef::MinimalCookbookVersion.should_receive(:load_full_versions_of).with([@cookbook1_v1], nil).and_return([@cookbook1_v1]) response = post_json("/environments/env_many_versions/cookbook_versions", {"run_list" => ["recipe[cookbook1@1.0.0]"]}) response.should be_kind_of(Hash) @@ -93,7 +100,7 @@ describe "Environments controller" do end it "should report no_such_cookbook if given a dependency on a non-existant cookbook" do - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("env1", nil).and_return(@filtered_cookbook_list_env1) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("env1", nil).and_return(@filtered_cookbook_list_env1) expected_error = { "message" => "Run list contains invalid items: no such cookbook cookbook_nosuch.", "non_existent_cookbooks" => ["cookbook_nosuch"], @@ -106,7 +113,7 @@ describe "Environments controller" do end it "should report no_such_version if given a dependency on a cookbook that doesn't have any valid versions for an environment" do - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("env1", nil).and_return(@filtered_cookbook_list_env1) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("env1", nil).and_return(@filtered_cookbook_list_env1) expected_error = { "message" => "Run list contains invalid items: no versions match the constraints on cookbook cookbook_noversions.", "non_existent_cookbooks" => [], @@ -121,7 +128,7 @@ describe "Environments controller" do # TODO; have top-level cookbooks depend on other, non-existent cookbooks, # to get the other kind of exceptions. it "should report multiple failures (compound exceptions) if there is more than one error in dependencies" do - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("env1", nil).and_return(@filtered_cookbook_list_env1) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("env1", nil).and_return(@filtered_cookbook_list_env1) expected_error = { "message" => "Run list contains invalid items: no such cookbooks cookbook_nosuch_1, cookbook_nosuch_2; no versions match the constraints on cookbook cookbook_noversions.", diff --git a/chef-server-api/spec/unit/nodes_controller_environments_spec.rb b/chef-server-api/spec/unit/nodes_controller_environments_spec.rb index 5878d7414d..e635c9b465 100644 --- a/chef-server-api/spec/unit/nodes_controller_environments_spec.rb +++ b/chef-server-api/spec/unit/nodes_controller_environments_spec.rb @@ -50,9 +50,10 @@ describe "Nodes controller - environments and run_list expansion" do @role_containing_nosuch_cookbook = make_role("role_containing_nosuch_cookbook") @role_containing_nosuch_cookbook.env_run_lists({"_default" => make_runlist("recipe[cookbook_nosuch]")}) + @cb_for_default = make_cookbook("cb_for_default", "1.0.0") + @cb_for_env1 = make_cookbook("cb_for_env1", "1.0.0") @all_filtered_cookbook_list = - make_filtered_cookbook_hash(make_cookbook("cb_for_default", "1.0.0"), - make_cookbook("cb_for_env1", "1.0.0")) + make_filtered_cookbook_hash(@cb_for_default, @cb_for_env1) end describe "when handling Node API calls" do @@ -60,7 +61,8 @@ describe "Nodes controller - environments and run_list expansion" do # Test that node@_default resolves to use cookbook cb_for_default Chef::Node.should_receive(:cdb_load).with("node1").and_return(@node1) Chef::Role.should_receive(:cdb_load).with("role1", nil).and_return(@role1) - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("_default", nil).and_return(@all_filtered_cookbook_list) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("_default", nil).and_return(@all_filtered_cookbook_list) + Chef::MinimalCookbookVersion.should_receive(:load_full_versions_of).with([@cb_for_default], nil).and_return([@cb_for_default]) response = get_json("/nodes/node1/cookbooks") response.should be_kind_of(Hash) @@ -73,7 +75,8 @@ describe "Nodes controller - environments and run_list expansion" do @node1.chef_environment("env1") Chef::Node.should_receive(:cdb_load).with("node1").and_return(@node1) Chef::Role.should_receive(:cdb_load).with("role1", nil).and_return(@role1) - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("env1", nil).and_return(@all_filtered_cookbook_list) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("env1", nil).and_return(@all_filtered_cookbook_list) + Chef::MinimalCookbookVersion.should_receive(:load_full_versions_of).with([@cb_for_env1], nil).and_return([@cb_for_env1]) response = get_json("/nodes/node1/cookbooks") response.should be_kind_of(Hash) @@ -87,7 +90,8 @@ describe "Nodes controller - environments and run_list expansion" do @node1.chef_environment("env_fallback") Chef::Node.should_receive(:cdb_load).with("node1").and_return(@node1) Chef::Role.should_receive(:cdb_load).with("role1", nil).and_return(@role1) - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("env_fallback", nil).and_return(@all_filtered_cookbook_list) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("env_fallback", nil).and_return(@all_filtered_cookbook_list) + Chef::MinimalCookbookVersion.should_receive(:load_full_versions_of).with([@cb_for_default], nil).and_return([@cb_for_default]) response = get_json("/nodes/node1/cookbooks") response.should be_kind_of(Hash) @@ -103,7 +107,7 @@ describe "Nodes controller - environments and run_list expansion" do }.to_json Chef::Node.should_receive(:cdb_load).with("node_containing_nosuch_cookbook").and_return(@node_containing_nosuch_cookbook) - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("_default", nil).and_return(@all_filtered_cookbook_list) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("_default", nil).and_return(@all_filtered_cookbook_list) lambda { response = get_json("/nodes/node_containing_nosuch_cookbook/cookbooks") @@ -120,7 +124,7 @@ describe "Nodes controller - environments and run_list expansion" do Chef::Node.should_receive(:cdb_load).with("node_containing_role_containing_nosuch_cookbook").and_return(@node_containing_role_containing_nosuch_cookbook) Chef::Role.should_receive(:cdb_load).with("role_containing_nosuch_cookbook", nil).and_return(@role_containing_nosuch_cookbook) - Chef::Environment.should_receive(:cdb_load_filtered_cookbook_versions).with("_default", nil).and_return(@all_filtered_cookbook_list) + Chef::Environment.should_receive(:cdb_minimal_filtered_versions).with("_default", nil).and_return(@all_filtered_cookbook_list) lambda { response = get_json("/nodes/node_containing_role_containing_nosuch_cookbook/cookbooks") |