diff options
author | Thom May <thom@may.lt> | 2016-01-21 11:14:49 +0000 |
---|---|---|
committer | Thom May <thom@may.lt> | 2016-01-21 11:14:49 +0000 |
commit | b2287acca8df58079205979ab2ba956d0e281fe5 (patch) | |
tree | 471e241d05effbe9d2b470588c1ff0f647952741 /spec | |
parent | 38e4b8ad4a1d701878595c7822636f3cbb7f7af9 (diff) | |
parent | 3458740dc59959e0eaa88543883756d041435d56 (diff) | |
download | chef-b2287acca8df58079205979ab2ba956d0e281fe5.tar.gz |
Merge pull request #4423 from chef/tm/rest_deprecation
Add deprecation warnings to Chef::REST and all json_creates
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functional/rest_spec.rb | 1 | ||||
-rw-r--r-- | spec/unit/api_client_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/data_bag_item_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/data_bag_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/environment_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/handler/json_file_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/json_compat_spec.rb | 7 | ||||
-rw-r--r-- | spec/unit/node_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/rest_spec.rb | 7 |
9 files changed, 22 insertions, 7 deletions
diff --git a/spec/functional/rest_spec.rb b/spec/functional/rest_spec.rb index e2d472c1d5..752e71d7e3 100644 --- a/spec/functional/rest_spec.rb +++ b/spec/functional/rest_spec.rb @@ -80,6 +80,7 @@ describe Chef::REST do before do Chef::Config[:node_name] = "webmonkey.example.com" Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem" + Chef::Config[:treat_deprecation_warnings_as_errors] = false end before(:all) do diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb index 1f313d7447..0451541f14 100644 --- a/spec/unit/api_client_spec.rb +++ b/spec/unit/api_client_spec.rb @@ -181,7 +181,7 @@ describe Chef::ApiClient do end let(:client) do - Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(client_hash)) + Chef::ApiClient.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(client_hash))) end it "should deserialize to a Chef::ApiClient object" do diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb index 0329264718..5605763806 100644 --- a/spec/unit/data_bag_item_spec.rb +++ b/spec/unit/data_bag_item_spec.rb @@ -174,7 +174,7 @@ describe Chef::DataBagItem do data_bag_item } - let(:deserial) { Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(data_bag_item)) } + let(:deserial) { Chef::DataBagItem.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(data_bag_item))) } it "should deserialize to a Chef::DataBagItem object" do diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb index 4e06a31911..8dc716460b 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -59,7 +59,7 @@ describe Chef::DataBag do describe "deserialize" do before(:each) do @data_bag.name("mars_volta") - @deserial = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@data_bag)) + @deserial = Chef::DataBag.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@data_bag))) end it "should deserialize to a Chef::DataBag object" do diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb index 04f54688de..ddbcf1d2b3 100644 --- a/spec/unit/environment_spec.rb +++ b/spec/unit/environment_spec.rb @@ -226,7 +226,7 @@ describe Chef::Environment do "json_class" => "Chef::Environment", "chef_type" => "environment", } - @environment = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@data)) + @environment = Chef::Environment.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@data))) end it "should return a Chef::Environment" do diff --git a/spec/unit/handler/json_file_spec.rb b/spec/unit/handler/json_file_spec.rb index 76098e2522..d66c3ef120 100644 --- a/spec/unit/handler/json_file_spec.rb +++ b/spec/unit/handler/json_file_spec.rb @@ -53,7 +53,7 @@ describe Chef::Handler::JsonFile do it "saves run status data to a file as JSON" do expect(@handler).to receive(:build_report_dir) @handler.run_report_unsafe(@run_status) - reported_data = Chef::JSONCompat.from_json(@file_mock.string) + reported_data = Chef::JSONCompat.parse(@file_mock.string) expect(reported_data["exception"]).to eq("Exception: Boy howdy!") expect(reported_data["start_time"]).to eq(@expected_time.to_s) expect(reported_data["end_time"]).to eq((@expected_time + 5).to_s) diff --git a/spec/unit/json_compat_spec.rb b/spec/unit/json_compat_spec.rb index 524b71f09a..042ac09069 100644 --- a/spec/unit/json_compat_spec.rb +++ b/spec/unit/json_compat_spec.rb @@ -20,10 +20,17 @@ require File.expand_path("../../spec_helper", __FILE__) require "chef/json_compat" describe Chef::JSONCompat do + before { Chef::Config[:treat_deprecation_warnings_as_errors] = false } describe "#from_json with JSON containing an existing class" do let(:json) { '{"json_class": "Chef::Role"}' } + it "emits a deprecation warning" do + Chef::Config[:treat_deprecation_warnings_as_errors] = true + expect { Chef::JSONCompat.from_json(json) }.to raise_error Chef::Exceptions::DeprecatedFeatureError, + /Auto inflation of JSON data is deprecated. Please use Chef::Role#from_hash/ + end + it "returns an instance of the class instead of a Hash" do expect(Chef::JSONCompat.from_json(json).class).to eq Chef::Role end diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index dcee5f8eb5..59bd1a1081 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -1207,7 +1207,7 @@ describe Chef::Node do it "should deserialize itself from json", :json => true do node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA)) json = Chef::JSONCompat.to_json(node) - serialized_node = Chef::JSONCompat.from_json(json) + serialized_node = Chef::Node.from_hash(Chef::JSONCompat.parse(json)) expect(serialized_node).to be_a_kind_of(Chef::Node) expect(serialized_node.name).to eql(node.name) expect(serialized_node.chef_environment).to eql(node.chef_environment) @@ -1246,7 +1246,7 @@ describe Chef::Node do end it "parses policyfile attributes from JSON" do - round_tripped_node = Chef::Node.json_create(node.for_json) + round_tripped_node = Chef::Node.from_hash(node.for_json) expect(round_tripped_node.policy_name).to eq("my-application") expect(round_tripped_node.policy_group).to eq("staging") diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb index 8e6a3be79c..86572c7034 100644 --- a/spec/unit/rest_spec.rb +++ b/spec/unit/rest_spec.rb @@ -74,6 +74,7 @@ describe Chef::REST do before(:each) do Chef::Log.init(log_stringio) + Chef::Config[:treat_deprecation_warnings_as_errors] = false end it "should have content length validation middleware after compressor middleware" do @@ -92,6 +93,12 @@ describe Chef::REST do Chef::REST.new(base_url, nil, nil, options) end + it "emits a deprecation warning" do + Chef::Config[:treat_deprecation_warnings_as_errors] = true + expect { Chef::REST.new(base_url) }.to raise_error Chef::Exceptions::DeprecatedFeatureError, + /Chef::REST is deprecated. Please use Chef::ServerAPI, or investigate Ridley or ChefAPI./ + end + context "when created with a chef zero URL" do let(:url) { "chefzero://localhost:1" } |