diff options
author | Seth Falcon <seth@opscode.com> | 2011-05-24 15:07:22 -0700 |
---|---|---|
committer | Seth Falcon <seth@opscode.com> | 2011-05-24 15:07:22 -0700 |
commit | 418f1aa554e2562c6e448ef56e8b6c7e877c208f (patch) | |
tree | e47c50fe676dd55f6737df2fcfa6511d2f4e31db | |
parent | 72e642c4d5557f70d64a9a623493d59f6a007373 (diff) | |
parent | 765c9fb30b19f7db5bc98eeb6cda6b38827cbaee (diff) | |
download | chef-418f1aa554e2562c6e448ef56e8b6c7e877c208f.tar.gz |
Merge branch 'CHEF-2373'
-rw-r--r-- | chef/lib/chef/environment.rb | 18 | ||||
-rw-r--r-- | chef/spec/unit/environment_spec.rb | 31 |
2 files changed, 42 insertions, 7 deletions
diff --git a/chef/lib/chef/environment.rb b/chef/lib/chef/environment.rb index cfd0af4484..8cf80f1dfc 100644 --- a/chef/lib/chef/environment.rb +++ b/chef/lib/chef/environment.rb @@ -1,6 +1,7 @@ # # Author:: Stephen Delano (<stephen@opscode.com>) # Author:: Seth Falcon (<seth@opscode.com>) +# Author:: John Keiser (<jkeiser@ospcode.com>) # Copyright:: Copyright 2010-2011 Opscode, Inc. # License:: Apache License, Version 2.0 # @@ -398,12 +399,17 @@ class Chef def self.cdb_load_filtered_recipe_list(name, couchdb=nil) cdb_load_filtered_cookbook_versions(name, couchdb).map do |cb_name, cb| - cb.first.recipe_filenames_by_name.keys.map do |recipe| - case recipe - when DEFAULT - cb_name - else - "#{cb_name}::#{recipe}" + if cb.empty? # no available versions + [] # empty list elided with flatten + else + latest_version = cb.first + latest_version.recipe_filenames_by_name.keys.map do |recipe| + case recipe + when DEFAULT + cb_name + else + "#{cb_name}::#{recipe}" + end end end end.flatten diff --git a/chef/spec/unit/environment_spec.rb b/chef/spec/unit/environment_spec.rb index a799ec2585..2bb80de7c9 100644 --- a/chef/spec/unit/environment_spec.rb +++ b/chef/spec/unit/environment_spec.rb @@ -1,7 +1,8 @@ # # Author:: Stephen Delano (<stephen@ospcode.com>) # Author:: Seth Falcon (<seth@ospcode.com>) -# Copyright:: Copyright 2010 Opscode, Inc. +# Author:: John Keiser (<jkeiser@ospcode.com>) +# Copyright:: Copyright 2010-2011 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -247,21 +248,25 @@ describe Chef::Environment do @all_cookbooks << begin cv = Chef::CookbookVersion.new("apt") cv.version = "1.0.0" + cv.recipe_filenames = ["default.rb", "only-in-1-0.rb"] cv end @all_cookbooks << begin cv = Chef::CookbookVersion.new("apt") cv.version = "1.1.0" + cv.recipe_filenames = ["default.rb", "only-in-1-1.rb"] cv end @all_cookbooks << begin cv = Chef::CookbookVersion.new("apache2") cv.version = "2.0.0" + cv.recipe_filenames = ["default.rb", "mod_ssl.rb"] cv end @all_cookbooks << begin cv = Chef::CookbookVersion.new("god") cv.version = "4.2.0" + cv.recipe_filenames = ["default.rb"] cv end Chef::CookbookVersion.stub!(:cdb_list).and_return @all_cookbooks @@ -272,9 +277,33 @@ describe Chef::Environment do Chef::Environment.cdb_load_filtered_cookbook_versions("prod") end + it "should handle cookbooks with no available version" do + @environment.cookbook_versions({ + "apt" => "> 999.0.0", + "apache2" => "= 2.0.0" + }) + Chef::Environment.should_receive(:cdb_load).with("prod", nil) + recipes = Chef::Environment.cdb_load_filtered_recipe_list("prod") + # order doesn't matter + recipes.should =~ ["god", "apache2", "apache2::mod_ssl"] + end + + it "should load all the cookbook versions" do Chef::CookbookVersion.should_receive(:cdb_list) Chef::Environment.cdb_load_filtered_cookbook_versions("prod") + recipes = Chef::Environment.cdb_load_filtered_recipe_list("prod") + recipes.should =~ ["apache2", "apache2::mod_ssl", "apt", + "apt::only-in-1-0", "god"] + end + + it "should load all the cookbook versions with no policy" do + @environment.cookbook_versions({}) + Chef::CookbookVersion.should_receive(:cdb_list) + Chef::Environment.cdb_load_filtered_cookbook_versions("prod") + recipes = Chef::Environment.cdb_load_filtered_recipe_list("prod") + recipes.should =~ ["apache2", "apache2::mod_ssl", "apt", + "apt::only-in-1-1", "god"] end it "should restrict the cookbook versions, as specified in the environment" do |