summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2017-03-21 15:34:50 +0000
committerThom May <thom@chef.io>2017-04-04 07:18:17 +0100
commitdc96b2f45b8d8a0c6335c879551d8c1e94e9559c (patch)
tree434d7ce6b3e3202d318349640298a834ff82a4a3
parent8f62f18a24e3213ef4b2f13a5abf0135bf6c2429 (diff)
downloadchef-dc96b2f45b8d8a0c6335c879551d8c1e94e9559c.tar.gz
RFC 85: Remove unused metadata
Signed-off-by: Thom May <thom@chef.io>
-rw-r--r--lib/chef/cookbook/metadata.rb113
-rw-r--r--spec/unit/cookbook/metadata_spec.rb132
2 files changed, 27 insertions, 218 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index a8ec901e97..5efadd6f62 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -44,13 +44,8 @@ class Chef
LICENSE = "license".freeze
PLATFORMS = "platforms".freeze
DEPENDENCIES = "dependencies".freeze
- RECOMMENDATIONS = "recommendations".freeze
- SUGGESTIONS = "suggestions".freeze
- CONFLICTING = "conflicting".freeze
PROVIDING = "providing".freeze
- REPLACING = "replacing".freeze
ATTRIBUTES = "attributes".freeze
- GROUPINGS = "groupings".freeze
RECIPES = "recipes".freeze
VERSION = "version".freeze
SOURCE_URL = "source_url".freeze
@@ -62,17 +57,12 @@ class Chef
COMPARISON_FIELDS = [ :name, :description, :long_description, :maintainer,
:maintainer_email, :license, :platforms, :dependencies,
- :recommendations, :suggestions, :conflicting, :providing,
- :replacing, :attributes, :groupings, :recipes, :version,
+ :providing, :attributes, :recipes, :version,
:source_url, :issues_url, :privacy, :chef_versions, :ohai_versions,
:gems ]
VERSION_CONSTRAINTS = { :depends => DEPENDENCIES,
- :recommends => RECOMMENDATIONS,
- :suggests => SUGGESTIONS,
- :conflicts => CONFLICTING,
:provides => PROVIDING,
- :replaces => REPLACING,
:chef_version => CHEF_VERSIONS,
:ohai_version => OHAI_VERSIONS }
@@ -81,13 +71,8 @@ class Chef
attr_reader :platforms
attr_reader :dependencies
- attr_reader :recommendations
- attr_reader :suggestions
- attr_reader :conflicting
attr_reader :providing
- attr_reader :replacing
attr_reader :attributes
- attr_reader :groupings
attr_reader :recipes
attr_reader :version
@@ -120,13 +105,8 @@ class Chef
@platforms = Mash.new
@dependencies = Mash.new
- @recommendations = Mash.new
- @suggestions = Mash.new
- @conflicting = Mash.new
@providing = Mash.new
- @replacing = Mash.new
@attributes = Mash.new
- @groupings = Mash.new
@recipes = Mash.new
@version = Version.new("0.0.0")
@source_url = ""
@@ -315,57 +295,6 @@ class Chef
@dependencies[cookbook]
end
- # Adds a recommendation for another cookbook, with version checking strings.
- #
- # === Parameters
- # cookbook<String>:: The cookbook
- # version<String>:: A version constraint of the form "OP VERSION",
- # where OP is one of < <= = > >= ~> and VERSION has
- # the form x.y.z or x.y.
- #
- # === Returns
- # versions<Array>:: Returns the list of versions for the platform
- def recommends(cookbook, *version_args)
- version = new_args_format(:recommends, cookbook, version_args)
- constraint = validate_version_constraint(:recommends, cookbook, version)
- @recommendations[cookbook] = constraint.to_s
- @recommendations[cookbook]
- end
-
- # Adds a suggestion for another cookbook, with version checking strings.
- #
- # === Parameters
- # cookbook<String>:: The cookbook
- # version<String>:: A version constraint of the form "OP VERSION",
- # where OP is one of < <= = > >= ~> and VERSION has the
- # formx.y.z or x.y.
- #
- # === Returns
- # versions<Array>:: Returns the list of versions for the platform
- def suggests(cookbook, *version_args)
- version = new_args_format(:suggests, cookbook, version_args)
- constraint = validate_version_constraint(:suggests, cookbook, version)
- @suggestions[cookbook] = constraint.to_s
- @suggestions[cookbook]
- end
-
- # Adds a conflict for another cookbook, with version checking strings.
- #
- # === Parameters
- # cookbook<String>:: The cookbook
- # version<String>:: A version constraint of the form "OP VERSION",
- # where OP is one of < <= = > >= ~> and VERSION has
- # the form x.y.z or x.y.
- #
- # === Returns
- # versions<Array>:: Returns the list of versions for the platform
- def conflicts(cookbook, *version_args)
- version = new_args_format(:conflicts, cookbook, version_args)
- constraint = validate_version_constraint(:conflicts, cookbook, version)
- @conflicting[cookbook] = constraint.to_s
- @conflicting[cookbook]
- end
-
# Adds a recipe, definition, or resource provided by this cookbook.
#
# Recipes are specified as normal
@@ -387,22 +316,6 @@ class Chef
@providing[cookbook]
end
- # Adds a cookbook that is replaced by this one, with version checking strings.
- #
- # === Parameters
- # cookbook<String>:: The cookbook we replace
- # version<String>:: A version constraint of the form "OP VERSION",
- # where OP is one of < <= = > >= ~> and VERSION has the form x.y.z or x.y.
- #
- # === Returns
- # versions<Array>:: Returns the list of versions for the platform
- def replaces(cookbook, *version_args)
- version = new_args_format(:replaces, cookbook, version_args)
- constraint = validate_version_constraint(:replaces, cookbook, version)
- @replacing[cookbook] = constraint.to_s
- @replacing[cookbook]
- end
-
# Metadata DSL to set a valid chef_version. May be declared multiple times
# with the result being 'OR'd such that if any statements match, the version
# is considered supported. Uses Gem::Requirement for its implementation.
@@ -519,18 +432,6 @@ class Chef
@attributes[name]
end
- def grouping(name, options)
- validate(
- options,
- {
- :title => { :kind_of => String },
- :description => { :kind_of => String },
- }
- )
- @groupings[name] = options
- @groupings[name]
- end
-
# Convert an Array of Gem::Dependency objects (chef_version/ohai_version) to an Array.
#
# Gem::Dependencey#to_s is not useful, and there is no #to_json defined on it or its component
@@ -575,13 +476,8 @@ class Chef
LICENSE => license,
PLATFORMS => platforms,
DEPENDENCIES => dependencies,
- RECOMMENDATIONS => recommendations,
- SUGGESTIONS => suggestions,
- CONFLICTING => conflicting,
PROVIDING => providing,
- REPLACING => replacing,
ATTRIBUTES => attributes,
- GROUPINGS => groupings,
RECIPES => recipes,
VERSION => version,
SOURCE_URL => source_url,
@@ -612,13 +508,8 @@ class Chef
@license = o[LICENSE] if o.has_key?(LICENSE)
@platforms = o[PLATFORMS] if o.has_key?(PLATFORMS)
@dependencies = handle_deprecated_constraints(o[DEPENDENCIES]) if o.has_key?(DEPENDENCIES)
- @recommendations = handle_deprecated_constraints(o[RECOMMENDATIONS]) if o.has_key?(RECOMMENDATIONS)
- @suggestions = handle_deprecated_constraints(o[SUGGESTIONS]) if o.has_key?(SUGGESTIONS)
- @conflicting = handle_deprecated_constraints(o[CONFLICTING]) if o.has_key?(CONFLICTING)
@providing = o[PROVIDING] if o.has_key?(PROVIDING)
- @replacing = handle_deprecated_constraints(o[REPLACING]) if o.has_key?(REPLACING)
@attributes = o[ATTRIBUTES] if o.has_key?(ATTRIBUTES)
- @groupings = o[GROUPINGS] if o.has_key?(GROUPINGS)
@recipes = o[RECIPES] if o.has_key?(RECIPES)
@version = o[VERSION] if o.has_key?(VERSION)
@source_url = o[SOURCE_URL] if o.has_key?(SOURCE_URL)
@@ -726,7 +617,7 @@ class Chef
if block_given?
super
else
- Chef::Log.debug "ignoring method #{method} on cookbook with name #{name}, possible typo or future metadata?"
+ Chef::Log.debug "ignoring method #{method} on cookbook with name #{name}, possible typo or the ghosts of metadata past or future?"
end
end
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index 4a18244ea0..2fdc43c289 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -28,8 +28,7 @@ describe Chef::Cookbook::Metadata do
before do
@fields = [ :name, :description, :long_description, :maintainer,
:maintainer_email, :license, :platforms, :dependencies,
- :recommendations, :suggestions, :conflicting, :providing,
- :replacing, :attributes, :groupings, :recipes, :version,
+ :providing, :attributes, :recipes, :version,
:source_url, :issues_url, :privacy, :ohai_versions, :chef_versions,
:gems ]
end
@@ -114,30 +113,10 @@ describe Chef::Cookbook::Metadata do
expect(metadata.dependencies).to eq(Mash.new)
end
- it "has an empty recommends list" do
- expect(metadata.recommendations).to eq(Mash.new)
- end
-
- it "has an empty suggestions list" do
- expect(metadata.suggestions).to eq(Mash.new)
- end
-
- it "has an empty conflicts list" do
- expect(metadata.conflicting).to eq(Mash.new)
- end
-
- it "has an empty replaces list" do
- expect(metadata.replacing).to eq(Mash.new)
- end
-
it "has an empty attributes list" do
expect(metadata.attributes).to eq(Mash.new)
end
- it "has an empty groupings list" do
- expect(metadata.groupings).to eq(Mash.new)
- end
-
it "has an empty recipes list" do
expect(metadata.recipes).to eq(Mash.new)
end
@@ -234,11 +213,7 @@ describe Chef::Cookbook::Metadata do
dep_types = {
:depends => [ :dependencies, "foo::bar", "> 0.2" ],
- :recommends => [ :recommendations, "foo::bar", ">= 0.2" ],
- :suggests => [ :suggestions, "foo::bar", "> 0.2" ],
- :conflicts => [ :conflicting, "foo::bar", "~> 0.2" ],
:provides => [ :providing, "foo::bar", "<= 0.2" ],
- :replaces => [ :replacing, "foo::bar", "= 0.2.1" ],
}
dep_types.sort_by(&:to_s).each do |dep, dep_args|
check_with = dep_args.shift
@@ -255,11 +230,7 @@ describe Chef::Cookbook::Metadata do
dep_types = {
:depends => [ :dependencies, "foo::bar", ">0.2", "> 0.2" ],
- :recommends => [ :recommendations, "foo::bar", ">=0.2", ">= 0.2" ],
- :suggests => [ :suggestions, "foo::bar", ">0.2", "> 0.2" ],
- :conflicts => [ :conflicting, "foo::bar", "~>0.2", "~> 0.2" ],
:provides => [ :providing, "foo::bar", "<=0.2", "<= 0.2" ],
- :replaces => [ :replacing, "foo::bar", "=0.2.1", "= 0.2.1" ],
}
dep_types.sort_by(&:to_s).each do |dep, dep_args|
check_with = dep_args.shift
@@ -278,11 +249,7 @@ describe Chef::Cookbook::Metadata do
describe "in the obsoleted format" do
dep_types = {
:depends => [ "foo::bar", "> 0.2", "< 1.0" ],
- :recommends => [ "foo::bar", ">= 0.2", "< 1.0" ],
- :suggests => [ "foo::bar", "> 0.2", "< 1.0" ],
- :conflicts => [ "foo::bar", "> 0.2", "< 1.0" ],
:provides => [ "foo::bar", "> 0.2", "< 1.0" ],
- :replaces => [ "foo::bar", "> 0.2.1", "< 1.0" ],
}
dep_types.each do |dep, dep_args|
@@ -295,11 +262,7 @@ describe Chef::Cookbook::Metadata do
describe "with obsolete operators" do
dep_types = {
:depends => [ "foo::bar", ">> 0.2"],
- :recommends => [ "foo::bar", ">> 0.2"],
- :suggests => [ "foo::bar", ">> 0.2"],
- :conflicts => [ "foo::bar", ">> 0.2"],
:provides => [ "foo::bar", ">> 0.2"],
- :replaces => [ "foo::bar", ">> 0.2.1"],
}
dep_types.each do |dep, dep_args|
@@ -452,33 +415,6 @@ describe Chef::Cookbook::Metadata do
end
end
- describe "attribute groupings" do
- it "should allow you set a grouping" do
- group = {
- "title" => "MySQL Tuning",
- "description" => "Setting from the my.cnf file that allow you to tune your mysql server",
- }
- expect(metadata.grouping("/db/mysql/databases/tuning", group)).to eq(group)
- end
- it "should not accept anything but a string for display_name" do
- expect do
- metadata.grouping("db/mysql/databases", :title => "foo")
- end.not_to raise_error
- expect do
- metadata.grouping("db/mysql/databases", :title => Hash.new)
- end.to raise_error(ArgumentError)
- end
-
- it "should not accept anything but a string for the description" do
- expect do
- metadata.grouping("db/mysql/databases", :description => "foo")
- end.not_to raise_error
- expect do
- metadata.grouping("db/mysql/databases", :description => Hash.new)
- end.to raise_error(ArgumentError)
- end
- end
-
describe "cookbook attributes" do
it "should allow you set an attributes metadata" do
attrs = {
@@ -804,11 +740,7 @@ describe Chef::Cookbook::Metadata do
metadata.depends "bobo", "= 1.0"
metadata.depends "bubu", "=1.0"
metadata.depends "bobotclown", "= 1.1"
- metadata.recommends "snark", "< 3.0"
- metadata.suggests "kindness", "> 2.0"
- metadata.conflicts "hatred"
metadata.provides "foo(:bar, :baz)"
- metadata.replaces "snarkitron"
metadata.recipe "test_cookbook::enlighten", "is your buddy"
metadata.attribute "bizspark/has_login",
:display_name => "You have nothing"
@@ -843,11 +775,7 @@ describe Chef::Cookbook::Metadata do
license
platforms
dependencies
- suggestions
- recommendations
- conflicting
providing
- replacing
attributes
recipes
version
@@ -888,11 +816,7 @@ describe Chef::Cookbook::Metadata do
license
platforms
dependencies
- suggestions
- recommendations
- conflicting
providing
- replacing
attributes
recipes
version
@@ -914,40 +838,34 @@ describe Chef::Cookbook::Metadata do
@hash = metadata.to_hash
end
- [:dependencies,
- :recommendations,
- :suggestions,
- :conflicting,
- :replacing].each do |to_check|
- it "should transform deprecated greater than syntax for :#{to_check}" do
- @hash[to_check.to_s]["foo::bar"] = ">> 0.2"
- deserial = Chef::Cookbook::Metadata.from_hash(@hash)
- expect(deserial.send(to_check)["foo::bar"]).to eq("> 0.2")
- 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 :#{to_check}" do
- @hash[to_check.to_s]["foo::bar"] = "<< 0.2"
- deserial = Chef::Cookbook::Metadata.from_hash(@hash)
- expect(deserial.send(to_check)["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 :#{to_check}" do
- @hash[to_check.to_s]["foo::bar"] = [ ">= 1.0", "<= 5.2" ]
- deserial = Chef::Cookbook::Metadata.from_hash(@hash)
- expect(deserial.send(to_check)["foo::bar"]).to eq([])
- 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)
+ expect(deserial.send(:dependencies)["foo::bar"]).to eq([])
+ end
- it "should accept an empty array of dependency constraints for :#{to_check}" do
- @hash[to_check.to_s]["foo::bar"] = []
- deserial = Chef::Cookbook::Metadata.from_hash(@hash)
- expect(deserial.send(to_check)["foo::bar"]).to eq([])
- end
+ it "should accept an empty array of dependency constraints for :dependencies" do
+ @hash[:dependencies.to_s]["foo::bar"] = []
+ deserial = Chef::Cookbook::Metadata.from_hash(@hash)
+ expect(deserial.send(:dependencies)["foo::bar"]).to eq([])
+ end
- it "should accept single-element arrays of dependency constraints for :#{to_check}" do
- @hash[to_check.to_s]["foo::bar"] = [ ">= 2.0" ]
- deserial = Chef::Cookbook::Metadata.from_hash(@hash)
- expect(deserial.send(to_check)["foo::bar"]).to eq(">= 2.0")
- end
+ it "should accept single-element arrays of dependency constraints for :dependencies" do
+ @hash[:dependencies.to_s]["foo::bar"] = [ ">= 2.0" ]
+ deserial = Chef::Cookbook::Metadata.from_hash(@hash)
+ expect(deserial.send(:dependencies)["foo::bar"]).to eq(">= 2.0")
end
end