summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@getchef.com>2014-04-10 06:55:06 -0700
committerBryan McLellan <btm@getchef.com>2014-04-10 06:55:06 -0700
commit3ea0acdcde386751c376cde61c2bca21fa3bc3a0 (patch)
treee6b7a05ade9e16a3d659e2687c925246bccbd14e
parent726304824f427028987e76d6d7050334fe69eea3 (diff)
downloadchef-btm/CHEF-5147.tar.gz
CHEF-5147: Fix tests, but...btm/CHEF-5147
This fixes the tests for the behavior specified in CHEF-5147 that makes it so that --include-dependencies will upload dependencies if they're on disk, but and fail if they're not available on disk or the server. However, overall this change means that 'knife cookbook upload' no longer makes a dependency check, which was something we intentionally added so you would know about dependency problems at cookbook upload time rather than later when you run chef-client. See the ticket for further discussion
-rw-r--r--lib/chef/knife/cookbook_upload.rb11
-rw-r--r--spec/unit/knife/cookbook_upload_spec.rb77
2 files changed, 55 insertions, 33 deletions
diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb
index ed8f49a4ec..240fe41b23 100644
--- a/lib/chef/knife/cookbook_upload.rb
+++ b/lib/chef/knife/cookbook_upload.rb
@@ -171,7 +171,16 @@ class Chef
if ! upload_set.has_key?(cookbook_name)
upload_set[cookbook_name] = cookbook_repo[cookbook_name]
if config[:depends]
- upload_set[cookbook_name].metadata.dependencies.each { |dep, ver| @name_args << dep }
+ # If including dependencies, add each dependency to the upload_set
+ upload_set[cookbook_name].metadata.dependencies.each do |dep, ver|
+ # TODO: Should check cookbook version here?
+ if cookbook_repo[dep]
+ Chef::Log.debug("config[:depends] is true, found dependency #{dep} in local repository, adding upload list")
+ @name_args << dep
+ else
+ Chef::Log.debug("config[:depends] is true, dependency #{dep} not found in local repository, will check the server later")
+ end
+ end
end
end
rescue Exceptions::CookbookNotFoundInRepo => e
diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb
index 5c7a4c1125..4e5c5bb4f1 100644
--- a/spec/unit/knife/cookbook_upload_spec.rb
+++ b/spec/unit/knife/cookbook_upload_spec.rb
@@ -190,49 +190,62 @@ E
end
end
- describe 'when specifying a cookbook name with missing dependencies' do
+ describe 'config[:depends] is true' do
let(:cookbook_dependency) { Chef::CookbookVersion.new('dependency') }
before(:each) do
+ knife.config[:depends] = true
cookbook.metadata.depends("dependency")
- cookbook_loader.stub(:[]) do |ckbk|
- { "test_cookbook" => cookbook,
- "dependency" => cookbook_dependency}[ckbk]
- end
- knife.stub(:cookbook_names).and_return(["cookbook_dependency", "test_cookbook"])
- @stdout, @stderr, @stdin = StringIO.new, StringIO.new, StringIO.new
- knife.ui = Chef::Knife::UI.new(@stdout, @stderr, @stdin, {})
- end
-
- it 'should exit and not upload the cookbook' do
- cookbook_loader.should_receive(:[]).once.with('test_cookbook')
- cookbook_loader.should_not_receive(:load_cookbooks)
- cookbook_uploader.should_not_receive(:upload_cookbooks)
- expect {knife.run}.to raise_error(SystemExit)
+ # These are the cookbooks we are asking knife to upload now
+ # This stub returns a CookbookVersion object by name, e.g. cookbook_loader['test_cookbook']
+ cookbook_loader.stub(:[]) do |ckbk|
+ { "test_cookbook" => cookbook}[ckbk]
+ end
end
- it 'should output a message for a single missing dependency' do
- expect {knife.run}.to raise_error(SystemExit)
- @stderr.string.should include('Cookbook test_cookbook depends on cookbooks which are not currently')
- @stderr.string.should include('being uploaded and cannot be found on the server.')
- @stderr.string.should include("The missing cookbook(s) are: 'dependency' version '>= 0.0.0'")
+ it "does not add a cookbook to the upload_set if it is not in the repository" do
+ expect(knife.cookbooks_to_upload).not_to include("dependency")
end
- it 'should output a message for a multiple missing dependencies which are concatenated' do
- cookbook_dependency2 = Chef::CookbookVersion.new('dependency2')
- cookbook.metadata.depends("dependency2")
+ it "adds a cookbook to the upload_set if it is in the cookbook repository" do
cookbook_loader.stub(:[]) do |ckbk|
{ "test_cookbook" => cookbook,
- "dependency" => cookbook_dependency,
- "dependency2" => cookbook_dependency2}[ckbk]
+ "dependency" => cookbook_dependency }[ckbk]
+ end
+ expect(knife.cookbooks_to_upload).to include("dependency")
+ end
+
+ describe 'specifying a cookbook name with missing dependencies' do
+
+ before(:each) do
+ @stdout, @stderr, @stdin = StringIO.new, StringIO.new, StringIO.new
+ knife.ui = Chef::Knife::UI.new(@stdout, @stderr, @stdin, {})
+ end
+
+ it 'should exit and not upload the cookbook' do
+ cookbook_loader.should_receive(:[]).once.with('test_cookbook')
+ cookbook_loader.should_not_receive(:load_cookbooks)
+ cookbook_uploader.should_not_receive(:upload_cookbooks)
+ expect {knife.run}.to raise_error(SystemExit)
+ end
+
+ it 'should output a message for a single missing dependency' do
+ expect {knife.run}.to raise_error(SystemExit)
+ @stderr.string.should include('Cookbook test_cookbook depends on cookbooks which are not currently')
+ @stderr.string.should include('being uploaded and cannot be found on the server.')
+ @stderr.string.should include("The missing cookbook(s) are: 'dependency' version '>= 0.0.0'")
+ end
+
+ it 'should output a message for a multiple missing dependencies which are concatenated' do
+ cookbook_dependency2 = Chef::CookbookVersion.new('dependency2')
+ cookbook.metadata.depends("dependency2")
+ expect {knife.run}.to raise_error(SystemExit)
+ @stderr.string.should include('Cookbook test_cookbook depends on cookbooks which are not currently')
+ @stderr.string.should include('being uploaded and cannot be found on the server.')
+ @stderr.string.should include("The missing cookbook(s) are:")
+ @stderr.string.should include("'dependency' version '>= 0.0.0'")
+ @stderr.string.should include("'dependency2' version '>= 0.0.0'")
end
- knife.stub(:cookbook_names).and_return(["dependency", "dependency2", "test_cookbook"])
- expect {knife.run}.to raise_error(SystemExit)
- @stderr.string.should include('Cookbook test_cookbook depends on cookbooks which are not currently')
- @stderr.string.should include('being uploaded and cannot be found on the server.')
- @stderr.string.should include("The missing cookbook(s) are:")
- @stderr.string.should include("'dependency' version '>= 0.0.0'")
- @stderr.string.should include("'dependency2' version '>= 0.0.0'")
end
end