summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/cookbook_version.rb33
-rw-r--r--spec/unit/cookbook_version_spec.rb39
2 files changed, 55 insertions, 17 deletions
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 4e3e8069a6..1f55ff8b72 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -63,47 +63,48 @@ class Chef
cookbook_manifest.update_from(new_manifest)
end
+ private def deprecated!(message)
+ if Chef::Config[:treat_deprecation_warnings_as_errors]
+ raise Exceptions::DeprecatedFeatureError, message
+ else
+ Chef::Log.warn(message)
+ end
+ end
+
def save_url
# TODO: double check this code suggestion
- msg = <<-WARNING
+ deprecated!(<<-DEPRECATED)
Cookbooks now have multiple save URLs based on the capabilities of the Chef Server.
To get the default save URL, use code like `Chef::CookbookManifest.new(cookbook_version).save_url`
-WARNING
- raise msg
- # TODO: change to warning
+DEPRECATED
+
cookbook_manifest.save_url
end
def force_save_url
# TODO: double check this code suggestion
- msg = <<-WARNING
+ deprecated!(<<-DEPRECATED)
Cookbooks now have multiple save URLs based on the capabilities of the Chef Server.
To get the default save URL, use code like `Chef::CookbookManifest.new(cookbook_version).force_save_url`
-WARNING
- raise msg
- # TODO: change to warning
+DEPRECATED
cookbook_manifest.force_save_url
end
def to_hash
# TODO: double check this code suggestion
- msg = <<-WARNING
+ deprecated!(<<-DEPRECATED)
Cookbooks now have multiple JSON representations based on the capabilities of the Chef Server.
To get the Hash representation, use code like `Chef::CookbookManifest.new(cookbook_version).to_hash`
-WARNING
- raise msg
- # TODO: change to warning
+DEPRECATED
cookbook_manifest.to_hash
end
def to_json(*a)
# TODO: double check this code suggestion
- msg = <<-WARNING
+ deprecated!(<<-DEPRECATED)
Cookbooks now have multiple JSON representations based on the capabilities of the Chef Server.
To get the JSON representation, use code like `Chef::CookbookManifest.new(cookbook_version).to_json`
-WARNING
- raise msg
- # TODO: change to warning
+DEPRECATED
cookbook_manifest.to_json
end
diff --git a/spec/unit/cookbook_version_spec.rb b/spec/unit/cookbook_version_spec.rb
index 95f0d68efc..1a3ec76840 100644
--- a/spec/unit/cookbook_version_spec.rb
+++ b/spec/unit/cookbook_version_spec.rb
@@ -498,7 +498,44 @@ describe Chef::CookbookVersion do
end
end
- pending "These should work when deprecation errors are changed back to warning" do
+
+ describe "when deprecation warnings are errors" do
+
+ subject(:cbv) { Chef::CookbookVersion.new("version validation", '/tmp/blah') }
+
+ it "errors on #save_url" do
+ expect { cbv.save_url }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
+ end
+
+ it "errors on #force_save_url" do
+ expect { cbv.force_save_url }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
+ end
+
+ it "errors on #to_hash" do
+ expect { cbv.to_hash }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
+ end
+
+ it "errors on #to_json" do
+ expect { cbv.to_json }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
+ end
+
+ end
+
+ describe "deprecated features" do
+
+ subject(:cbv) { Chef::CookbookVersion.new("tatft", '/tmp/blah').tap { |c| c.version = "1.2.3" } }
+
+ before do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ end
+
+ it "gives a save URL for the standard cookbook API" do
+ expect(cbv.save_url).to eq("cookbooks/tatft/1.2.3")
+ end
+
+ it "gives a force save URL for the standard cookbook API" do
+ expect(cbv.force_save_url).to eq("cookbooks/tatft/1.2.3?force=true")
+ end
include_examples "to_json equalivent to Chef::JSONCompat.to_json" do
let(:jsonable) { Chef::CookbookVersion.new("tatft", '/tmp/blah') }