diff options
author | Tim Smith <tsmith@chef.io> | 2020-04-20 12:50:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-20 12:50:45 -0700 |
commit | 33981fdc632aed95f5589f1a24af138c5fada4c0 (patch) | |
tree | af27eeb9fda5e188a44776bfdee3a59b13a06bc7 | |
parent | 9bf6ca80510d92aa8d2b7afa457f390a4d2d5ad6 (diff) | |
parent | d22ae13fc4d51fd024d0c5e85ef8845215a27ce3 (diff) | |
download | chef-33981fdc632aed95f5589f1a24af138c5fada4c0.tar.gz |
Merge pull request #9663 from damacus/remove/chef-10-metadata-param
Remove deprecated Chef-10 constraint handling
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 41 | ||||
-rw-r--r-- | spec/unit/cookbook/metadata_spec.rb | 12 |
2 files changed, 20 insertions, 33 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index 2ca769379c..ef0b920b5f 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -481,7 +481,7 @@ class Chef @maintainer_email = o[MAINTAINER_EMAIL] if o.key?(MAINTAINER_EMAIL) @license = o[LICENSE] if o.key?(LICENSE) @platforms = o[PLATFORMS] if o.key?(PLATFORMS) - @dependencies = handle_deprecated_constraints(o[DEPENDENCIES]) if o.key?(DEPENDENCIES) + @dependencies = handle_incorrect_constraints(o[DEPENDENCIES]) if o.key?(DEPENDENCIES) @providing = o[PROVIDING] if o.key?(PROVIDING) @recipes = o[RECIPES] if o.key?(RECIPES) @version = o[VERSION] if o.key?(VERSION) @@ -535,6 +535,25 @@ class Chef ) end + # This method translates version constraint strings from + # cookbooks with the old format. + # + # Before we began respecting version constraints, we allowed + # multiple constraints to be placed on cookbooks, as well as the + # << and >> operators, which are now just < and >. For + # specifications with more than one constraint, we return an + # empty array (otherwise, we're silently abiding only part of + # the contract they have specified to us). If there is only one + # constraint, we are replacing the old << and >> with the new < + # and >. + def handle_incorrect_constraints(specification) + specification.inject(Mash.new) do |acc, (cb, constraints)| + constraints = Array(constraints) + acc[cb] = (constraints.empty? || constraints.size > 1) ? [] : constraints.first + acc + end + end + # Sets the cookbook's issues URL, or returns it. # # === Parameters @@ -738,26 +757,6 @@ class Chef end end end - - # This method translates version constraint strings from - # cookbooks with the old format. - # - # Before we began respecting version constraints, we allowed - # multiple constraints to be placed on cookbooks, as well as the - # << and >> operators, which are now just < and >. For - # specifications with more than one constraint, we return an - # empty array (otherwise, we're silently abiding only part of - # the contract they have specified to us). If there is only one - # constraint, we are replacing the old << and >> with the new < - # and >. - def handle_deprecated_constraints(specification) - specification.inject(Mash.new) do |acc, (cb, constraints)| - constraints = Array(constraints) - acc[cb] = (constraints.empty? || constraints.size > 1) ? [] : constraints.first.gsub(/>>/, ">").gsub(/<</, "<") - acc - end - end - end #== Chef::Cookbook::MinimalMetadata diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index 3403a79995..0dbee4bc21 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -568,18 +568,6 @@ describe Chef::Cookbook::Metadata do @hash = metadata.to_hash end - it "should transform deprecated greater than syntax for :dependencies" do - @hash[:dependencies.to_s]["foo::bar"] = ">> 0.2" - deserial = Chef::Cookbook::Metadata.from_hash(@hash) - expect(deserial.send(:dependencies)["foo::bar"]).to eq("> 0.2") - end - - it "should transform deprecated less than syntax for :dependencies" do - @hash[:dependencies.to_s]["foo::bar"] = "<< 0.2" - deserial = Chef::Cookbook::Metadata.from_hash(@hash) - expect(deserial.send(:dependencies)["foo::bar"]).to eq("< 0.2") - end - it "should ignore multiple dependency constraints for :dependencies" do @hash[:dependencies.to_s]["foo::bar"] = [ ">= 1.0", "<= 5.2" ] deserial = Chef::Cookbook::Metadata.from_hash(@hash) |