summaryrefslogtreecommitdiff
path: root/spec/unit/cookbook
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-01-22 14:34:22 -0800
committerTim Smith <tsmith@chef.io>2019-01-22 14:56:18 -0800
commitd5286ce763953b986b72b368d86e5fe5aa9d9106 (patch)
treec102fc8700f5ca3ad78344f25f928f196806f37b /spec/unit/cookbook
parent4db8079fdbbdb88d468d03b87529ddaf88701b50 (diff)
downloadchef-d5286ce763953b986b72b368d86e5fe5aa9d9106.tar.gz
Remove 'attributes' attribute from cookbook metadata
We have a foodcritic rule to tell people not to do this It's not being used anywhere and is just a pile of code we run for no reason We should start warning that it's an unknown attribute when cookbooks contain these as it's wasted effort on the part of cookbook authors Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec/unit/cookbook')
-rw-r--r--spec/unit/cookbook/metadata_spec.rb296
1 files changed, 2 insertions, 294 deletions
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index 0f85d82734..8d65efbd6a 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -28,9 +28,8 @@ describe Chef::Cookbook::Metadata do
before do
@fields = [ :name, :description, :long_description, :maintainer,
:maintainer_email, :license, :platforms, :dependencies,
- :providing, :attributes, :recipes, :version,
- :source_url, :issues_url, :privacy, :ohai_versions, :chef_versions,
- :gems ]
+ :providing, :recipes, :version, :source_url, :issues_url,
+ :privacy, :ohai_versions, :chef_versions, :gems ]
end
it "does not depend on object identity for equality" do
@@ -113,10 +112,6 @@ describe Chef::Cookbook::Metadata do
expect(metadata.dependencies).to eq(Mash.new)
end
- it "has an empty attributes list" do
- expect(metadata.attributes).to eq(Mash.new)
- end
-
it "has an empty recipes list" do
expect(metadata.recipes).to eq(Mash.new)
end
@@ -415,289 +410,6 @@ describe Chef::Cookbook::Metadata do
end
end
- describe "cookbook attributes" do
- it "should allow you set an attributes metadata" do
- attrs = {
- "display_name" => "MySQL Databases",
- "description" => "Description of MySQL",
- "choice" => %w{dedicated shared},
- "calculated" => false,
- "type" => "string",
- "required" => "recommended",
- "recipes" => [ "mysql::server", "mysql::master" ],
- "default" => [ ],
- "source_url" => "http://example.com",
- "issues_url" => "http://example.com/issues",
- "privacy" => true,
- }
- expect(metadata.attribute("/db/mysql/databases", attrs)).to eq(attrs)
- end
-
- it "should not accept anything but a string for display_name" do
- expect do
- metadata.attribute("db/mysql/databases", display_name: "foo")
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", display_name: Hash.new)
- end.to raise_error(ArgumentError)
- end
-
- it "should not accept anything but a string for the description" do
- expect do
- metadata.attribute("db/mysql/databases", description: "foo")
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", description: Hash.new)
- end.to raise_error(ArgumentError)
- end
-
- it "should not accept anything but a string for the source_url" do
- expect do
- metadata.attribute("db/mysql/databases", source_url: "foo")
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", source_url: Hash.new)
- end.to raise_error(ArgumentError)
- end
-
- it "should not accept anything but a string for the issues_url" do
- expect do
- metadata.attribute("db/mysql/databases", issues_url: "foo")
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", issues_url: Hash.new)
- end.to raise_error(ArgumentError)
- end
-
- it "should not accept anything but true or false for the privacy flag" do
- expect do
- metadata.attribute("db/mysql/databases", privacy: true)
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", privacy: false)
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", privacy: "true")
- end.to raise_error(ArgumentError)
- end
-
- it "should not accept anything but an array of strings for choice" do
- expect do
- metadata.attribute("db/mysql/databases", choice: %w{dedicated shared})
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", choice: [10, "shared"])
- end.to raise_error(ArgumentError)
- expect do
- metadata.attribute("db/mysql/databases", choice: Hash.new)
- end.to raise_error(ArgumentError)
- end
-
- it "should set choice to empty array by default" do
- metadata.attribute("db/mysql/databases", {})
- expect(metadata.attributes["db/mysql/databases"][:choice]).to eq([])
- end
-
- it "should let calculated be true or false" do
- expect do
- metadata.attribute("db/mysql/databases", calculated: true)
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", calculated: false)
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", calculated: Hash.new)
- end.to raise_error(ArgumentError)
- end
-
- it "should set calculated to false by default" do
- metadata.attribute("db/mysql/databases", {})
- expect(metadata.attributes["db/mysql/databases"][:calculated]).to eq(false)
- end
-
- it "accepts String for the attribute type" do
- expect do
- metadata.attribute("db/mysql/databases", type: "string")
- end.not_to raise_error
- end
-
- it "accepts Array for the attribute type" do
- expect do
- metadata.attribute("db/mysql/databases", type: "array")
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", type: Array.new)
- end.to raise_error(ArgumentError)
- end
-
- it "accepts symbol for the attribute type" do
- expect do
- metadata.attribute("db/mysql/databases", type: "symbol")
- end.not_to raise_error
- end
-
- it "should let type be hash (backwards compatibility only)" do
- expect do
- metadata.attribute("db/mysql/databases", type: "hash")
- end.not_to raise_error
- end
-
- it "should let required be required, recommended or optional" do
- expect do
- metadata.attribute("db/mysql/databases", required: "required")
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", required: "recommended")
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", required: "optional")
- end.not_to raise_error
- end
-
- it "should convert required true to required" do
- expect do
- metadata.attribute("db/mysql/databases", required: true)
- end.not_to raise_error
- # attrib = metadata.attributes["db/mysql/databases"][:required].should == "required"
- end
-
- it "should convert required false to optional" do
- expect do
- metadata.attribute("db/mysql/databases", required: false)
- end.not_to raise_error
- # attrib = metadata.attributes["db/mysql/databases"][:required].should == "optional"
- end
-
- it "should set required to 'optional' by default" do
- metadata.attribute("db/mysql/databases", {})
- expect(metadata.attributes["db/mysql/databases"][:required]).to eq("optional")
- end
-
- it "should make sure recipes is an array" do
- expect do
- metadata.attribute("db/mysql/databases", recipes: [])
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", required: Hash.new)
- end.to raise_error(ArgumentError)
- end
-
- it "should set recipes to an empty array by default" do
- metadata.attribute("db/mysql/databases", {})
- expect(metadata.attributes["db/mysql/databases"][:recipes]).to eq([])
- end
-
- it "should allow the default value to be a string, array, hash, boolean or numeric" do
- expect do
- metadata.attribute("db/mysql/databases", default: [])
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", default: {})
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", default: "alice in chains")
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", default: 1337)
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", default: true)
- end.not_to raise_error
- expect do
- metadata.attribute("db/mysql/databases", required: :not_gonna_do_it)
- end.to raise_error(ArgumentError)
- end
-
- it "should limit the types allowed in the choice array" do
- options = {
- type: "string",
- choice: %w{test1 test2},
- default: "test1",
- }
- expect do
- metadata.attribute("test_cookbook/test", options)
- end.not_to raise_error
-
- options = {
- type: "boolean",
- choice: [ true, false ],
- default: true,
- }
- expect do
- metadata.attribute("test_cookbook/test", options)
- end.not_to raise_error
-
- options = {
- type: "numeric",
- choice: [ 1337, 420 ],
- default: 1337,
- }
- expect do
- metadata.attribute("test_cookbook/test", options)
- end.not_to raise_error
-
- options = {
- type: "numeric",
- choice: [ true, "false" ],
- default: false,
- }
- expect do
- metadata.attribute("test_cookbook/test", options)
- end.to raise_error(Chef::Exceptions::ValidationFailed)
- end
-
- it "should error if default used with calculated" do
- expect do
- attrs = {
- calculated: true,
- default: [ "I thought you said calculated" ],
- }
- metadata.attribute("db/mysql/databases", attrs)
- end.to raise_error(ArgumentError)
- expect do
- attrs = {
- calculated: true,
- default: "I thought you said calculated",
- }
- metadata.attribute("db/mysql/databases", attrs)
- end.to raise_error(ArgumentError)
- end
-
- it "should allow a default that is a choice" do
- expect do
- attrs = {
- choice: %w{a b c},
- default: "b",
- }
- metadata.attribute("db/mysql/databases", attrs)
- end.not_to raise_error
- expect do
- attrs = {
- choice: %w{a b c d e},
- default: %w{b d},
- }
- metadata.attribute("db/mysql/databases", attrs)
- end.not_to raise_error
- end
-
- it "should error if default is not a choice" do
- expect do
- attrs = {
- choice: %w{a b c},
- default: "d",
- }
- metadata.attribute("db/mysql/databases", attrs)
- end.to raise_error(ArgumentError)
- expect do
- attrs = {
- choice: %w{a b c d e},
- default: %w{b z},
- }
- metadata.attribute("db/mysql/databases", attrs)
- end.to raise_error(ArgumentError)
- end
- end
-
describe "recipes" do
let(:cookbook) do
c = Chef::CookbookVersion.new("test_cookbook")
@@ -742,8 +454,6 @@ describe Chef::Cookbook::Metadata do
metadata.depends "bobotclown", "= 1.1"
metadata.provides "foo(:bar, :baz)"
metadata.recipe "test_cookbook::enlighten", "is your buddy"
- metadata.attribute "bizspark/has_login",
- display_name: "You have nothing"
metadata.version "1.2.3"
metadata.gem "foo", "~> 1.2"
metadata.gem "bar", ">= 2.2", "< 4.0"
@@ -776,7 +486,6 @@ describe Chef::Cookbook::Metadata do
platforms
dependencies
providing
- attributes
recipes
version
source_url
@@ -817,7 +526,6 @@ describe Chef::Cookbook::Metadata do
platforms
dependencies
providing
- attributes
recipes
version
source_url