diff options
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 10 | ||||
-rw-r--r-- | spec/integration/knife/upload_spec.rb | 18 | ||||
-rw-r--r-- | spec/unit/cookbook/metadata_spec.rb | 15 |
3 files changed, 40 insertions, 3 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index 4f12275a82..01a98fda39 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -286,9 +286,13 @@ class Chef # === Returns # versions<Array>:: Returns the list of versions for the platform def depends(cookbook, *version_args) - version = new_args_format(:depends, cookbook, version_args) - constraint = validate_version_constraint(:depends, cookbook, version) - @dependencies[cookbook] = constraint.to_s + if cookbook == name + Chef::Log.warn "Ignoring self-dependency in cookbook #{name}, please remove it (in the future this will be fatal)." + else + version = new_args_format(:depends, cookbook, version_args) + constraint = validate_version_constraint(:depends, cookbook, version) + @dependencies[cookbook] = constraint.to_s + end @dependencies[cookbook] end diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb index cef4f54e97..826ecec364 100644 --- a/spec/integration/knife/upload_spec.rb +++ b/spec/integration/knife/upload_spec.rb @@ -154,6 +154,24 @@ EOM end end + context 'when cookbook metadata has a self-dependency' do + before do + file 'cookbooks/x/metadata.rb', "name 'x'; version '1.0.0'; depends 'x'" + end + + it "should warn", :chef_lt_13_only do + knife('upload /cookbooks').should_succeed( + stdout: "Updated /cookbooks/x\n", + stderr: "WARN: Ignoring self-dependency in cookbook x, please remove it (in the future this will be fatal).\n" + ) + knife('diff --name-status /').should_succeed '' + end + it "should fail in Chef 13", :chef_gte_13_only do + knife('upload /cookbooks').should_fail '' + # FIXME: include the error message here + end + end + context 'as well as one extra copy of each thing' do before do file 'clients/y.json', { 'public_key' => ChefZero::PUBLIC_KEY } diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index 760ae5dd2a..d2954726e8 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -304,6 +304,21 @@ describe Chef::Cookbook::Metadata do end end end + + it "strips out self-dependencies", :chef_lt_13_only do + metadata.name('foo') + expect(Chef::Log).to receive(:warn).with( + "Ignoring self-dependency in cookbook foo, please remove it (in the future this will be fatal)." + ) + metadata.depends('foo') + expect(metadata.dependencies).to eql({}) + end + + it "errors on self-dependencies", :chef_gte_13_only do + metadata.name('foo') + expect { metadata.depends('foo') }.to raise_error + # FIXME: add the error type + end end describe "attribute groupings" do |