summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Webb <dan.webb@damacus.io>2020-04-18 17:03:39 +0100
committerDan Webb <dan.webb@damacus.io>2020-04-20 15:52:34 +0100
commitd22ae13fc4d51fd024d0c5e85ef8845215a27ce3 (patch)
treeeb7777f6363a03cda87e69a75655091d494ee0ca
parentfb43c19e2c827cae458578386349651ec8b5588a (diff)
downloadchef-d22ae13fc4d51fd024d0c5e85ef8845215a27ce3.tar.gz
Stop handling the deprecated Chef version constraints
handle_deprecated_constraints has been a work around since Chef 10 Remove old specs that checked that the metadata was transformed correctly Signed-off-by: Daniel Webb <dan.webb@damacus.io>
-rw-r--r--lib/chef/cookbook/metadata.rb41
-rw-r--r--spec/unit/cookbook/metadata_spec.rb12
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)