summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2015-12-02 12:19:33 +0000
committerThom May <thom@chef.io>2016-01-11 15:40:42 +0000
commitd99e306a41b1402209d320cb7119b12a3bbb962f (patch)
treef65940702826deb991e6198967d3e9e96cb2857a /spec
parent1b71aeb423b009f6d1a44215c89e9976957b47e9 (diff)
downloadchef-d99e306a41b1402209d320cb7119b12a3bbb962f.tar.gz
Convert all uses of Chef::REST to Chef::ServerAPItm/no_more_rest
In the process, stop auto-expanding JSON in the HTTP client, and let individual classes control that themselves. Fixes #2737, Fixes #3518
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/resource/registry_spec.rb2
-rw-r--r--spec/functional/tiny_server_spec.rb4
-rw-r--r--spec/support/shared/context/client.rb20
-rw-r--r--spec/unit/api_client_spec.rb2
-rw-r--r--spec/unit/audit/audit_reporter_spec.rb9
-rw-r--r--spec/unit/client_spec.rb18
-rw-r--r--spec/unit/cookbook/file_vendor_spec.rb2
-rw-r--r--spec/unit/cookbook/synchronizer_spec.rb43
-rw-r--r--spec/unit/cookbook_uploader_spec.rb6
-rw-r--r--spec/unit/data_bag_item_spec.rb28
-rw-r--r--spec/unit/data_bag_spec.rb20
-rw-r--r--spec/unit/environment_spec.rb6
-rw-r--r--spec/unit/key_spec.rb28
-rw-r--r--spec/unit/knife/bootstrap/client_builder_spec.rb26
-rw-r--r--spec/unit/knife/configure_spec.rb2
-rw-r--r--spec/unit/knife/cookbook_bulk_delete_spec.rb16
-rw-r--r--spec/unit/knife/cookbook_delete_spec.rb6
-rw-r--r--spec/unit/knife/cookbook_download_spec.rb7
-rw-r--r--spec/unit/knife/cookbook_list_spec.rb8
-rw-r--r--spec/unit/knife/cookbook_show_spec.rb30
-rw-r--r--spec/unit/knife/cookbook_site_download_spec.rb10
-rw-r--r--spec/unit/knife/cookbook_site_share_spec.rb10
-rw-r--r--spec/unit/knife/cookbook_site_unshare_spec.rb12
-rw-r--r--spec/unit/knife/data_bag_create_spec.rb12
-rw-r--r--spec/unit/knife/data_bag_edit_spec.rb4
-rw-r--r--spec/unit/knife/data_bag_from_file_spec.rb2
-rw-r--r--spec/unit/knife/data_bag_show_spec.rb2
-rw-r--r--spec/unit/knife/environment_compare_spec.rb2
-rw-r--r--spec/unit/knife/index_rebuild_spec.rb6
-rw-r--r--spec/unit/knife_spec.rb6
-rw-r--r--spec/unit/node_spec.rb56
-rw-r--r--spec/unit/org_spec.rb14
-rw-r--r--spec/unit/policy_builder/expand_node_object_spec.rb8
-rw-r--r--spec/unit/policy_builder/policyfile_spec.rb6
-rw-r--r--spec/unit/provider/http_request_spec.rb4
-rw-r--r--spec/unit/resource_reporter_spec.rb44
-rw-r--r--spec/unit/role_spec.rb4
-rw-r--r--spec/unit/run_list_spec.rb23
-rw-r--r--spec/unit/search/query_spec.rb36
-rw-r--r--spec/unit/shell/shell_session_spec.rb4
-rw-r--r--spec/unit/user_v1_spec.rb4
41 files changed, 272 insertions, 280 deletions
diff --git a/spec/functional/resource/registry_spec.rb b/spec/functional/resource/registry_spec.rb
index f112ad9b00..c0682fefc8 100644
--- a/spec/functional/resource/registry_spec.rb
+++ b/spec/functional/resource/registry_spec.rb
@@ -111,7 +111,7 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do
before do
@node.name("windowsbox")
- @rest_client = double("Chef::REST (mock)")
+ @rest_client = double("Chef::ServerAPI (mock)")
allow(@rest_client).to receive(:create_url).and_return("reports/nodes/windowsbox/runs/#{@run_id}");
allow(@rest_client).to receive(:raw_http_request).and_return({"result"=>"ok"});
allow(@rest_client).to receive(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/windowsbox/runs/#{@run_id}"});
diff --git a/spec/functional/tiny_server_spec.rb b/spec/functional/tiny_server_spec.rb
index 87be948a0d..d21248062a 100644
--- a/spec/functional/tiny_server_spec.rb
+++ b/spec/functional/tiny_server_spec.rb
@@ -70,8 +70,8 @@ describe TinyServer::Manager do
TinyServer::API.instance.get("/index", 200, "[\"hello\"]")
- rest = Chef::REST.new('http://localhost:9000', false, false)
- expect(rest.get_rest("index")).to eq(["hello"])
+ rest = Chef::HTTP.new('http://localhost:9000')
+ expect(rest.get("index")).to eq("[\"hello\"]")
@server.stop
end
diff --git a/spec/support/shared/context/client.rb b/spec/support/shared/context/client.rb
index eb537e9889..cb387a9478 100644
--- a/spec/support/shared/context/client.rb
+++ b/spec/support/shared/context/client.rb
@@ -68,9 +68,9 @@ shared_context "a client run" do
let(:api_client_exists?) { false }
let(:enable_fork) { false }
- let(:http_cookbook_sync) { double("Chef::REST (cookbook sync)") }
- let(:http_node_load) { double("Chef::REST (node)") }
- let(:http_node_save) { double("Chef::REST (node save)") }
+ let(:http_cookbook_sync) { double("Chef::ServerAPI (cookbook sync)") }
+ let(:http_node_load) { double("Chef::ServerAPI (node)") }
+ let(:http_node_save) { double("Chef::ServerAPI (node save)") }
let(:runner) { instance_double("Chef::Runner") }
let(:audit_runner) { instance_double("Chef::Audit::Runner", :failed? => false) }
@@ -93,10 +93,11 @@ shared_context "a client run" do
def stub_for_node_load
# Client.register will then turn around create another
- # Chef::REST object, this time with the client key it got from the
+ # Chef::ServerAPI object, this time with the client key it got from the
# previous step.
- expect(Chef::REST).to receive(:new).
- with(Chef::Config[:chef_server_url], fqdn, Chef::Config[:client_key]).
+ expect(Chef::ServerAPI).to receive(:new).
+ with(Chef::Config[:chef_server_url], client_name: fqdn,
+ signing_key_filename: Chef::Config[:client_key]).
exactly(:once).
and_return(http_node_load)
@@ -115,7 +116,7 @@ shared_context "a client run" do
# ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
#
expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
expect(http_cookbook_sync).to receive(:post).
with("environments/_default/cookbook_versions", {:run_list => []}).
and_return({})
@@ -175,8 +176,9 @@ shared_context "converge completed" do
allow(node).to receive(:data_for_save).and_return(node.for_json)
# --Client#save_updated_node
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url], fqdn, Chef::Config[:client_key], validate_utf8: false).and_return(http_node_save)
- expect(http_node_save).to receive(:put_rest).with("nodes/#{fqdn}", node.for_json).and_return(true)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], client_name: fqdn,
+ signing_key_filename: Chef::Config[:client_key], validate_utf8: false).and_return(http_node_save)
+ expect(http_node_save).to receive(:put).with("nodes/#{fqdn}", node.for_json).and_return(true)
end
end
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb
index a0e399b470..810c806af5 100644
--- a/spec/unit/api_client_spec.rb
+++ b/spec/unit/api_client_spec.rb
@@ -275,7 +275,7 @@ describe Chef::ApiClient do
describe "when requesting a new key" do
before do
- @http_client = double("Chef::REST mock")
+ @http_client = double("Chef::ServerAPI mock")
allow(Chef::ServerAPI).to receive(:new).and_return(@http_client)
end
diff --git a/spec/unit/audit/audit_reporter_spec.rb b/spec/unit/audit/audit_reporter_spec.rb
index 46c2a96b4c..1a8cee1cd5 100644
--- a/spec/unit/audit/audit_reporter_spec.rb
+++ b/spec/unit/audit/audit_reporter_spec.rb
@@ -57,7 +57,6 @@ describe Chef::Audit::AuditReporter do
before do
allow(reporter).to receive(:auditing_enabled?).and_return(true)
allow(reporter).to receive(:run_status).and_return(run_status)
- allow(rest).to receive(:create_url).and_return(true)
allow(rest).to receive(:post).and_return(true)
allow(reporter).to receive(:audit_data).and_return(audit_data)
allow(reporter).to receive(:run_status).and_return(run_status)
@@ -75,16 +74,12 @@ describe Chef::Audit::AuditReporter do
end
it "posts audit data to server endpoint" do
- endpoint = "api.opscode.us/orgname/controls"
headers = {
'X-Ops-Audit-Report-Protocol-Version' => Chef::Audit::AuditReporter::PROTOCOL_VERSION
}
- expect(rest).to receive(:create_url).
- with("controls").
- and_return(endpoint)
expect(rest).to receive(:post).
- with(endpoint, run_data, headers)
+ with("controls", run_data, headers)
reporter.run_completed(node)
end
@@ -255,7 +250,6 @@ EOM
context "when no prior exception is stored" do
it "reports no error" do
- expect(rest).to receive(:create_url)
expect(rest).to receive(:post)
reporter.run_failed(run_error)
expect(run_data).to_not have_key(:error)
@@ -268,7 +262,6 @@ EOM
end
it "reports the prior error" do
- expect(rest).to receive(:create_url)
expect(rest).to receive(:post)
reporter.run_failed(run_error)
expect(run_data).to have_key(:error)
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index c270ddc092..ca7440061e 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -23,7 +23,7 @@ require 'spec/support/shared/context/client'
require 'spec/support/shared/examples/client'
require 'chef/run_context'
-require 'chef/rest'
+require 'chef/server_api'
require 'rbconfig'
class FooError < RuntimeError
@@ -169,7 +169,7 @@ describe Chef::Client do
# ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
#
expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
expect(http_cookbook_sync).to receive(:post).
with("environments/_default/cookbook_versions", {:run_list => ["override_recipe"]}).
and_return({})
@@ -203,7 +203,7 @@ describe Chef::Client do
# ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
#
expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
expect(http_cookbook_sync).to receive(:post).
with("environments/_default/cookbook_versions", {:run_list => ["new_run_list_recipe"]}).
and_return({})
@@ -336,9 +336,9 @@ describe Chef::Client do
# build_node will call Node#expand! with server, which will
# eventually hit the server to expand the included role.
- mock_chef_rest = double("Chef::REST")
- expect(mock_chef_rest).to receive(:get_rest).with("roles/role_containing_cookbook1").and_return(role_containing_cookbook1)
- expect(Chef::REST).to receive(:new).and_return(mock_chef_rest)
+ mock_chef_rest = double("Chef::ServerAPI")
+ expect(mock_chef_rest).to receive(:get).with("roles/role_containing_cookbook1").and_return(role_containing_cookbook1.to_hash)
+ expect(Chef::ServerAPI).to receive(:new).and_return(mock_chef_rest)
# check pre-conditions.
expect(node[:roles]).to be_nil
@@ -372,9 +372,9 @@ describe Chef::Client do
test_env = Chef::Environment.new
test_env.name("A")
- mock_chef_rest = double("Chef::REST")
- expect(mock_chef_rest).to receive(:get_rest).with("environments/A").and_return(test_env)
- expect(Chef::REST).to receive(:new).and_return(mock_chef_rest)
+ mock_chef_rest = double("Chef::ServerAPI")
+ expect(mock_chef_rest).to receive(:get).with("environments/A").and_return(test_env)
+ expect(Chef::ServerAPI).to receive(:new).and_return(mock_chef_rest)
allow(client.policy_builder).to receive(:node).and_return(node)
client.policy_builder.select_implementation(node)
allow(client.policy_builder.implementation).to receive(:node).and_return(node)
diff --git a/spec/unit/cookbook/file_vendor_spec.rb b/spec/unit/cookbook/file_vendor_spec.rb
index 145541a63f..8bf2d3c2a3 100644
--- a/spec/unit/cookbook/file_vendor_spec.rb
+++ b/spec/unit/cookbook/file_vendor_spec.rb
@@ -23,7 +23,7 @@ describe Chef::Cookbook::FileVendor do
context "when configured to fetch files over http" do
- let(:http) { double("Chef::REST") }
+ let(:http) { double("Chef::ServerAPI") }
before do
file_vendor_class.fetch_from_remote(http)
diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb
index 2b040f3c95..30ddaad1d7 100644
--- a/spec/unit/cookbook/synchronizer_spec.rb
+++ b/spec/unit/cookbook/synchronizer_spec.rb
@@ -38,7 +38,6 @@ describe Chef::CookbookCacheCleaner do
unused_template_files.each do |cbf|
expect(file_cache).to receive(:delete).with(cbf)
end
- cookbook_hash = {"valid1"=> {}, "valid2" => {}}
allow(cleaner).to receive(:cache).and_return(file_cache)
cleaner.cleanup_file_cache
end
@@ -224,8 +223,8 @@ describe Chef::CookbookSynchronizer do
and_return(false)
# Fetch and copy default.rb recipe
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/abc123', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/abc123').
and_return(cookbook_a_default_recipe_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
@@ -234,8 +233,8 @@ describe Chef::CookbookSynchronizer do
and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
# Fetch and copy default.rb attribute file
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/abc456', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/abc456').
and_return(cookbook_a_default_attribute_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
@@ -252,8 +251,8 @@ describe Chef::CookbookSynchronizer do
with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
and_return(false)
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/megaman.conf', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/megaman.conf').
and_return(cookbook_a_file_default_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
@@ -261,8 +260,8 @@ describe Chef::CookbookSynchronizer do
with("cookbooks/cookbook_a/files/default/megaman.conf", false).
and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/ffffff', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/ffffff').
and_return(cookbook_a_template_default_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
@@ -281,8 +280,8 @@ describe Chef::CookbookSynchronizer do
and_return(true)
# Fetch and copy default.rb recipe
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/abc123', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/abc123').
and_return(cookbook_a_default_recipe_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
@@ -297,8 +296,8 @@ describe Chef::CookbookSynchronizer do
and_return("fff000")
# Fetch and copy default.rb attribute file
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/abc456', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/abc456').
and_return(cookbook_a_default_attribute_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
@@ -323,8 +322,8 @@ describe Chef::CookbookSynchronizer do
and_return(true)
# Fetch and copy megaman.conf
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/megaman.conf', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/megaman.conf').
and_return(cookbook_a_file_default_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
@@ -334,8 +333,8 @@ describe Chef::CookbookSynchronizer do
and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
# Fetch and copy apache2.conf template
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/ffffff', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/ffffff').
and_return(cookbook_a_template_default_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
@@ -416,7 +415,7 @@ describe Chef::CookbookSynchronizer do
end
describe "when syncing cookbooks with the server" do
- let(:server_api) { double("Chef::REST (mock)") }
+ let(:server_api) { double("Chef::ServerAPI (mock)") }
let(:file_cache) { double("Chef::FileCache (mock)") }
@@ -442,8 +441,8 @@ describe Chef::CookbookSynchronizer do
it "does not fetch templates or cookbook files" do
# Implicitly tested in previous test; this test is just for behavior specification.
- expect(server_api).not_to receive(:get_rest).
- with('http://chef.example.com/ffffff', true)
+ expect(server_api).not_to receive(:streaming_request).
+ with('http://chef.example.com/ffffff')
synchronizer.sync_cookbooks
end
@@ -502,7 +501,7 @@ describe Chef::CookbookSynchronizer do
it "does not update files" do
expect(file_cache).not_to receive(:move_to)
- expect(server_api).not_to receive(:get_rest)
+ expect(server_api).not_to receive(:streaming_request)
synchronizer.sync_cookbooks
end
end
@@ -512,7 +511,7 @@ describe Chef::CookbookSynchronizer do
it "does not update files" do
expect(file_cache).not_to receive(:move_to)
- expect(server_api).not_to receive(:get_rest)
+ expect(server_api).not_to receive(:streaming_request)
synchronizer.sync_cookbooks
end
end
diff --git a/spec/unit/cookbook_uploader_spec.rb b/spec/unit/cookbook_uploader_spec.rb
index 76727c18e2..a08b6b29d0 100644
--- a/spec/unit/cookbook_uploader_spec.rb
+++ b/spec/unit/cookbook_uploader_spec.rb
@@ -20,7 +20,7 @@ require 'spec_helper'
describe Chef::CookbookUploader do
- let(:http_client) { double("Chef::REST") }
+ let(:http_client) { double("Chef::ServerAPI") }
let(:cookbook_loader) do
loader = Chef::CookbookLoader.new(File.join(CHEF_SPEC_DATA, "cookbooks"))
@@ -64,8 +64,8 @@ describe Chef::CookbookUploader do
end
it "creates an HTTP client with default configuration when not initialized with one" do
- default_http_client = double("Chef::REST")
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(default_http_client)
+ default_http_client = double("Chef::ServerAPI")
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(default_http_client)
uploader = described_class.new(cookbooks_to_upload)
expect(uploader.rest).to eq(default_http_client)
end
diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb
index 497817ecf1..47042aa7ba 100644
--- a/spec/unit/data_bag_item_spec.rb
+++ b/spec/unit/data_bag_item_spec.rb
@@ -214,7 +214,7 @@ describe Chef::DataBagItem do
end
describe "save" do
- let(:server) { instance_double(Chef::REST) }
+ let(:server) { instance_double(Chef::ServerAPI) }
let(:data_bag_item) {
data_bag_item = Chef::DataBagItem.new
@@ -225,18 +225,18 @@ describe Chef::DataBagItem do
}
before do
- expect(Chef::REST).to receive(:new).and_return(server)
+ expect(Chef::ServerAPI).to receive(:new).and_return(server)
end
it "should update the item when it already exists" do
- expect(server).to receive(:put_rest).with("data/books/heart_of_darkness", data_bag_item)
+ expect(server).to receive(:put).with("data/books/heart_of_darkness", data_bag_item)
data_bag_item.save
end
it "should create if the item is not found" do
exception = double("404 error", :code => "404")
- expect(server).to receive(:put_rest).and_raise(Net::HTTPServerException.new("foo", exception))
- expect(server).to receive(:post_rest).with("data/books", data_bag_item)
+ expect(server).to receive(:put).and_raise(Net::HTTPServerException.new("foo", exception))
+ expect(server).to receive(:post).with("data/books", data_bag_item)
data_bag_item.save
end
@@ -249,8 +249,8 @@ describe Chef::DataBagItem do
end
it "should not save" do
- expect(server).not_to receive(:put_rest)
- expect(server).not_to receive(:post_rest)
+ expect(server).not_to receive(:put)
+ expect(server).not_to receive(:post)
data_bag_item.data_bag("books")
data_bag_item.save
end
@@ -259,7 +259,7 @@ describe Chef::DataBagItem do
end
describe "destroy" do
- let(:server) { instance_double(Chef::REST) }
+ let(:server) { instance_double(Chef::ServerAPI) }
let(:data_bag_item) {
data_bag_item = Chef::DataBagItem.new
@@ -269,8 +269,8 @@ describe Chef::DataBagItem do
}
it "should set default parameters" do
- expect(Chef::REST).to receive(:new).and_return(server)
- expect(server).to receive(:delete_rest).with("data/a_baggy_bag/data_bag_item_a_baggy_bag_some_id")
+ expect(Chef::ServerAPI).to receive(:new).and_return(server)
+ expect(server).to receive(:delete).with("data/a_baggy_bag/data_bag_item_a_baggy_bag_some_id")
data_bag_item.destroy
end
@@ -283,21 +283,21 @@ describe Chef::DataBagItem do
end
describe "from an API call" do
- let(:http_client) { double("Chef::REST") }
+ let(:http_client) { double("Chef::ServerAPI") }
before do
- allow(Chef::REST).to receive(:new).and_return(http_client)
+ allow(Chef::ServerAPI).to receive(:new).and_return(http_client)
end
it "converts raw data to a data bag item" do
- expect(http_client).to receive(:get_rest).with("data/users/charlie").and_return(data_bag_item.to_hash)
+ expect(http_client).to receive(:get).with("data/users/charlie").and_return(data_bag_item.to_hash)
item = Chef::DataBagItem.load(:users, "charlie")
expect(item).to be_a_kind_of(Chef::DataBagItem)
expect(item).to eq(data_bag_item)
end
it "does not convert when a DataBagItem is returned from the API call" do
- expect(http_client).to receive(:get_rest).with("data/users/charlie").and_return(data_bag_item)
+ expect(http_client).to receive(:get).with("data/users/charlie").and_return(data_bag_item)
item = Chef::DataBagItem.load(:users, "charlie")
expect(item).to be_a_kind_of(Chef::DataBagItem)
expect(item).to equal(data_bag_item)
diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb
index 13b835d120..a325b1260f 100644
--- a/spec/unit/data_bag_spec.rb
+++ b/spec/unit/data_bag_spec.rb
@@ -83,18 +83,18 @@ describe Chef::DataBag do
describe "when saving" do
before do
@data_bag.name('piggly_wiggly')
- @rest = double("Chef::REST")
- allow(Chef::REST).to receive(:new).and_return(@rest)
+ @rest = double("Chef::ServerAPI")
+ allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
end
it "should silently proceed when the data bag already exists" do
exception = double("409 error", :code => "409")
- expect(@rest).to receive(:post_rest).and_raise(Net::HTTPServerException.new("foo", exception))
+ expect(@rest).to receive(:post).and_raise(Net::HTTPServerException.new("foo", exception))
@data_bag.save
end
it "should create the data bag" do
- expect(@rest).to receive(:post_rest).with("data", @data_bag)
+ expect(@rest).to receive(:post).with("data", @data_bag)
@data_bag.save
end
@@ -106,7 +106,7 @@ describe Chef::DataBag do
Chef::Config[:why_run] = false
end
it "should not save" do
- expect(@rest).not_to receive(:post_rest)
+ expect(@rest).not_to receive(:post)
@data_bag.save
end
end
@@ -116,18 +116,18 @@ describe Chef::DataBag do
describe "from an API call" do
before do
Chef::Config[:chef_server_url] = 'https://myserver.example.com'
- @http_client = double('Chef::REST')
+ @http_client = double('Chef::ServerAPI')
end
it "should get the data bag from the server" do
- expect(Chef::REST).to receive(:new).with('https://myserver.example.com').and_return(@http_client)
- expect(@http_client).to receive(:get_rest).with('data/foo')
+ expect(Chef::ServerAPI).to receive(:new).with('https://myserver.example.com').and_return(@http_client)
+ expect(@http_client).to receive(:get).with('data/foo')
Chef::DataBag.load('foo')
end
it "should return the data bag" do
- allow(Chef::REST).to receive(:new).and_return(@http_client)
- expect(@http_client).to receive(:get_rest).with('data/foo').and_return({'bar' => 'https://myserver.example.com/data/foo/bar'})
+ allow(Chef::ServerAPI).to receive(:new).and_return(@http_client)
+ expect(@http_client).to receive(:get).with('data/foo').and_return({'bar' => 'https://myserver.example.com/data/foo/bar'})
data_bag = Chef::DataBag.load('foo')
expect(data_bag).to eq({'bar' => 'https://myserver.example.com/data/foo/bar'})
end
diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb
index 64617e0888..4116150d6e 100644
--- a/spec/unit/environment_spec.rb
+++ b/spec/unit/environment_spec.rb
@@ -365,8 +365,8 @@ describe Chef::Environment do
describe "api model" do
before(:each) do
- @rest = double("Chef::REST")
- allow(Chef::REST).to receive(:new).and_return(@rest)
+ @rest = double("Chef::ServerAPI")
+ allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
@query = double("Chef::Search::Query")
allow(Chef::Search::Query).to receive(:new).and_return(@query)
end
@@ -382,7 +382,7 @@ describe Chef::Environment do
end
it "should return a hash of environment names and urls" do
- expect(@rest).to receive(:get_rest).and_return({ "one" => "http://foo" })
+ expect(@rest).to receive(:get).and_return({ "one" => "http://foo" })
r = Chef::Environment.list
expect(r["one"]).to eq("http://foo")
end
diff --git a/spec/unit/key_spec.rb b/spec/unit/key_spec.rb
index 94ebbf6ae8..66f5fb9b13 100644
--- a/spec/unit/key_spec.rb
+++ b/spec/unit/key_spec.rb
@@ -342,7 +342,7 @@ EOS
Chef::Config[:chef_server_root] = "http://www.example.com"
Chef::Config[:chef_server_url] = "http://www.example.com/organizations/test_org"
r = double('rest')
- allow(Chef::REST).to receive(:new).and_return(r)
+ allow(Chef::ServerAPI).to receive(:new).and_return(r)
r
end
@@ -362,13 +362,13 @@ EOS
let(:inflated_response) { {"foobar" => user_key} }
it "lists all keys" do
- expect(rest).to receive(:get_rest).with("users/#{user_key.actor}/keys").and_return(response)
+ expect(rest).to receive(:get).with("users/#{user_key.actor}/keys").and_return(response)
expect(Chef::Key.list_by_user("foobar")).to eq(response)
end
it "inflate all keys" do
allow(Chef::Key).to receive(:load_by_user).with(user_key.actor, "foobar").and_return(user_key)
- expect(rest).to receive(:get_rest).with("users/#{user_key.actor}/keys").and_return(response)
+ expect(rest).to receive(:get).with("users/#{user_key.actor}/keys").and_return(response)
expect(Chef::Key.list_by_user("foobar", true)).to eq(inflated_response)
end
@@ -379,13 +379,13 @@ EOS
let(:inflated_response) { {"foobar" => client_key} }
it "lists all keys" do
- expect(rest).to receive(:get_rest).with("clients/#{client_key.actor}/keys").and_return(response)
+ expect(rest).to receive(:get).with("clients/#{client_key.actor}/keys").and_return(response)
expect(Chef::Key.list_by_client("foobar")).to eq(response)
end
it "inflate all keys" do
allow(Chef::Key).to receive(:load_by_client).with(client_key.actor, "foobar").and_return(client_key)
- expect(rest).to receive(:get_rest).with("clients/#{user_key.actor}/keys").and_return(response)
+ expect(rest).to receive(:get).with("clients/#{user_key.actor}/keys").and_return(response)
expect(Chef::Key.list_by_client("foobar", true)).to eq(inflated_response)
end
@@ -408,7 +408,7 @@ EOS
end
it "creates a new key via the API with the fingerprint as the name" do
- expect(rest).to receive(:post_rest).with(url,
+ expect(rest).to receive(:post).with(url,
{"name" => "12:3e:33:73:0b:f4:ec:72:dc:f0:4c:51:62:27:08:76:96:24:f4:4a",
"public_key" => key.public_key,
"expiration_date" => key.expiration_date}).and_return({})
@@ -426,7 +426,7 @@ EOS
context "when create_key is false" do
it "creates a new key via the API" do
- expect(rest).to receive(:post_rest).with(url,
+ expect(rest).to receive(:post).with(url,
{"name" => key.name,
"public_key" => key.public_key,
"expiration_date" => key.expiration_date}).and_return({})
@@ -453,13 +453,13 @@ EOS
end
it "should create a new key via the API" do
- expect(rest).to receive(:post_rest).with(url, $expected_input).and_return({})
+ expect(rest).to receive(:post).with(url, $expected_input).and_return({})
key.create
end
context "when the server returns the private_key via key.create" do
before do
- allow(rest).to receive(:post_rest).with(url, $expected_input).and_return({"private_key" => "this_private_key"})
+ allow(rest).to receive(:post).with(url, $expected_input).and_return({"private_key" => "this_private_key"})
end
it "key.create returns the original key plus the private_key" do
@@ -512,7 +512,7 @@ EOS
end
it "should update the key via the API" do
- expect(rest).to receive(:put_rest).with(url, key.to_hash).and_return({})
+ expect(rest).to receive(:put).with(url, key.to_hash).and_return({})
key.update
end
end
@@ -523,7 +523,7 @@ EOS
end
it "passes @name in the body and the arg in the PUT URL" do
- expect(rest).to receive(:put_rest).with(update_name_url, key.to_hash).and_return({})
+ expect(rest).to receive(:put).with(update_name_url, key.to_hash).and_return({})
key.update("old_name")
end
end
@@ -532,7 +532,7 @@ EOS
before do
key.name "key_name"
key.create_key true
- allow(rest).to receive(:put_rest).with(url, key.to_hash).and_return({
+ allow(rest).to receive(:put).with(url, key.to_hash).and_return({
"key" => "key_name",
"public_key" => public_key_string
})
@@ -572,7 +572,7 @@ EOS
describe "load" do
shared_examples_for "load" do
it "should load a named key from the API" do
- expect(rest).to receive(:get_rest).with(url).and_return({"user" => "foobar", "name" => "test_key_name", "public_key" => public_key_string, "expiration_date" => "infinity"})
+ expect(rest).to receive(:get).with(url).and_return({"user" => "foobar", "name" => "test_key_name", "public_key" => public_key_string, "expiration_date" => "infinity"})
key = Chef::Key.send(load_method, "foobar", "test_key_name")
expect(key.actor).to eq("foobar")
expect(key.name).to eq("test_key_name")
@@ -610,7 +610,7 @@ EOS
end
context "when name is not missing" do
it "should delete the key via the API" do
- expect(rest).to receive(:delete_rest).with(url).and_return({})
+ expect(rest).to receive(:delete).with(url).and_return({})
key.destroy
end
end
diff --git a/spec/unit/knife/bootstrap/client_builder_spec.rb b/spec/unit/knife/bootstrap/client_builder_spec.rb
index f17a6af878..6812a24c91 100644
--- a/spec/unit/knife/bootstrap/client_builder_spec.rb
+++ b/spec/unit/knife/bootstrap/client_builder_spec.rb
@@ -32,7 +32,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do
let(:node_name) { "bevell.wat" }
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:client_builder) {
client_builder = Chef::Knife::Bootstrap::ClientBuilder.new(knife_config: knife_config, chef_config: chef_config, ui: ui)
@@ -53,14 +53,14 @@ describe Chef::Knife::Bootstrap::ClientBuilder do
end
it "exits when the node exists and the user does not want to delete" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}")
+ expect(rest).to receive(:get).with("nodes/#{node_name}")
expect(ui.stdin).to receive(:readline).and_return('n')
expect { client_builder.run }.to raise_error(SystemExit)
end
it "exits when the client exists and the user does not want to delete" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}").and_raise(exception_404)
- expect(rest).to receive(:get_rest).with("clients/#{node_name}")
+ expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404)
+ expect(rest).to receive(:get).with("clients/#{node_name}")
expect(ui.stdin).to receive(:readline).and_return('n')
expect { client_builder.run }.to raise_error(SystemExit)
end
@@ -74,30 +74,30 @@ describe Chef::Knife::Bootstrap::ClientBuilder do
end
it "when both the client and node do not exist it succeeds" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}").and_raise(exception_404)
- expect(rest).to receive(:get_rest).with("clients/#{node_name}").and_raise(exception_404)
+ expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404)
+ expect(rest).to receive(:get).with("clients/#{node_name}").and_raise(exception_404)
expect { client_builder.run }.not_to raise_error
end
it "when we are allowed to delete an old node" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}")
+ expect(rest).to receive(:get).with("nodes/#{node_name}")
expect(ui.stdin).to receive(:readline).and_return('y')
- expect(rest).to receive(:get_rest).with("clients/#{node_name}").and_raise(exception_404)
+ expect(rest).to receive(:get).with("clients/#{node_name}").and_raise(exception_404)
expect(rest).to receive(:delete).with("nodes/#{node_name}")
expect { client_builder.run }.not_to raise_error
end
it "when we are allowed to delete an old client" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}").and_raise(exception_404)
- expect(rest).to receive(:get_rest).with("clients/#{node_name}")
+ expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404)
+ expect(rest).to receive(:get).with("clients/#{node_name}")
expect(ui.stdin).to receive(:readline).and_return('y')
expect(rest).to receive(:delete).with("clients/#{node_name}")
expect { client_builder.run }.not_to raise_error
end
it "when we are are allowed to delete both an old client and node" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}")
- expect(rest).to receive(:get_rest).with("clients/#{node_name}")
+ expect(rest).to receive(:get).with("nodes/#{node_name}")
+ expect(rest).to receive(:get).with("clients/#{node_name}")
expect(ui.stdin).to receive(:readline).twice.and_return('y')
expect(rest).to receive(:delete).with("nodes/#{node_name}")
expect(rest).to receive(:delete).with("clients/#{node_name}")
@@ -143,7 +143,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do
expect(node).to receive(:save)
end
- let(:client_rest) { double("Chef::REST (client)") }
+ let(:client_rest) { double("Chef::ServerAPI (client)") }
let(:node) { double("Chef::Node") }
diff --git a/spec/unit/knife/configure_spec.rb b/spec/unit/knife/configure_spec.rb
index e3ea1f052c..89874cfdf9 100644
--- a/spec/unit/knife/configure_spec.rb
+++ b/spec/unit/knife/configure_spec.rb
@@ -6,7 +6,7 @@ describe Chef::Knife::Configure do
Chef::Config[:node_name] = "webmonkey.example.com"
@knife = Chef::Knife::Configure.new
- @rest_client = double("null rest client", :post_rest => { :result => :true })
+ @rest_client = double("null rest client", :post => { :result => :true })
allow(@knife).to receive(:rest).and_return(@rest_client)
@out = StringIO.new
diff --git a/spec/unit/knife/cookbook_bulk_delete_spec.rb b/spec/unit/knife/cookbook_bulk_delete_spec.rb
index 98cd06bbbc..7d6e851589 100644
--- a/spec/unit/knife/cookbook_bulk_delete_spec.rb
+++ b/spec/unit/knife/cookbook_bulk_delete_spec.rb
@@ -36,9 +36,9 @@ describe Chef::Knife::CookbookBulkDelete do
cookbook = Chef::CookbookVersion.new(cookbook_name)
@cookbooks[cookbook_name] = cookbook
end
- @rest = double("Chef::REST")
- allow(@rest).to receive(:get_rest).and_return(@cookbooks)
- allow(@rest).to receive(:delete_rest).and_return(true)
+ @rest = double("Chef::ServerAPI")
+ allow(@rest).to receive(:get).and_return(@cookbooks)
+ allow(@rest).to receive(:delete).and_return(true)
allow(@knife).to receive(:rest).and_return(@rest)
allow(Chef::CookbookVersion).to receive(:list).and_return(@cookbooks)
@@ -49,11 +49,11 @@ describe Chef::Knife::CookbookBulkDelete do
describe "when there are several cookbooks on the server" do
before do
@cheezburger = {'cheezburger' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-cheez", "version" => "1.0.0"}]}}
- allow(@rest).to receive(:get_rest).with('cookbooks/cheezburger').and_return(@cheezburger)
+ allow(@rest).to receive(:get).with('cookbooks/cheezburger').and_return(@cheezburger)
@pizza = {'pizza' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-pizza", "version" => "2.0.0"}]}}
- allow(@rest).to receive(:get_rest).with('cookbooks/pizza').and_return(@pizza)
+ allow(@rest).to receive(:get).with('cookbooks/pizza').and_return(@pizza)
@lasagna = {'lasagna' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-lasagna", "version" => "3.0.0"}]}}
- allow(@rest).to receive(:get_rest).with('cookbooks/lasagna').and_return(@lasagna)
+ allow(@rest).to receive(:get).with('cookbooks/lasagna').and_return(@lasagna)
end
it "should print the cookbooks you are about to delete" do
@@ -69,14 +69,14 @@ describe Chef::Knife::CookbookBulkDelete do
it "should delete each cookbook" do
{"cheezburger" => "1.0.0", "pizza" => "2.0.0", "lasagna" => '3.0.0'}.each do |cookbook_name, version|
- expect(@rest).to receive(:delete_rest).with("cookbooks/#{cookbook_name}/#{version}")
+ expect(@rest).to receive(:delete).with("cookbooks/#{cookbook_name}/#{version}")
end
@knife.run
end
it "should only delete cookbooks that match the regex" do
@knife.name_args = ["cheezburger"]
- expect(@rest).to receive(:delete_rest).with('cookbooks/cheezburger/1.0.0')
+ expect(@rest).to receive(:delete).with('cookbooks/cheezburger/1.0.0')
@knife.run
end
end
diff --git a/spec/unit/knife/cookbook_delete_spec.rb b/spec/unit/knife/cookbook_delete_spec.rb
index 4e75a689e3..e9085e9512 100644
--- a/spec/unit/knife/cookbook_delete_spec.rb
+++ b/spec/unit/knife/cookbook_delete_spec.rb
@@ -134,19 +134,19 @@ describe Chef::Knife::CookbookDelete do
end
it 'should return the list of versions of the cookbook' do
- expect(@rest_mock).to receive(:get_rest).with('cookbooks/foobar').and_return(@cookbook_data)
+ expect(@rest_mock).to receive(:get).with('cookbooks/foobar').and_return(@cookbook_data)
expect(@knife.available_versions).to eq(['1.0.0', '1.1.0', '2.0.0'])
end
it 'should raise if an error other than HTTP 404 is returned' do
exception = Net::HTTPServerException.new('500 Internal Server Error', '500')
- expect(@rest_mock).to receive(:get_rest).and_raise(exception)
+ expect(@rest_mock).to receive(:get).and_raise(exception)
expect { @knife.available_versions }.to raise_error Net::HTTPServerException
end
describe "if the cookbook can't be found" do
before(:each) do
- expect(@rest_mock).to receive(:get_rest).
+ expect(@rest_mock).to receive(:get).
and_raise(Net::HTTPServerException.new('404 Not Found', '404'))
end
diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb
index 7ca1adfcb5..8b85e52b75 100644
--- a/spec/unit/knife/cookbook_download_spec.rb
+++ b/spec/unit/knife/cookbook_download_spec.rb
@@ -69,8 +69,8 @@ describe Chef::Knife::CookbookDownload do
@cookbook_mock = double('cookbook')
allow(@cookbook_mock).to receive(:version).and_return('1.0.0')
allow(@cookbook_mock).to receive(:manifest).and_return(@manifest_data)
- expect(@rest_mock).to receive(:get_rest).with('cookbooks/foobar/1.0.0').
- and_return(@cookbook_mock)
+ expect(Chef::CookbookVersion).to receive(:load).with("foobar", "1.0.0").
+ and_return(@cookbook_mock)
end
it 'should determine which version if one was not explicitly specified'do
@@ -106,11 +106,10 @@ describe Chef::Knife::CookbookDownload do
end
@files_mocks.each_pair do |file, mock|
- expect(@rest_mock).to receive(:get_rest).with("http://example.org/files/#{file}", true).
+ expect(@rest_mock).to receive(:streaming_request).with("http://example.org/files/#{file}").
and_return(mock)
end
- expect(@rest_mock).to receive(:sign_on_redirect=).with(false).at_least(:once)
@files.each do |f|
expect(FileUtils).to receive(:mv).
with("/var/tmp/#{File.basename(f)}", "/var/tmp/chef/foobar-1.0.0/#{f}")
diff --git a/spec/unit/knife/cookbook_list_spec.rb b/spec/unit/knife/cookbook_list_spec.rb
index 559f700bb4..fc07c8af3f 100644
--- a/spec/unit/knife/cookbook_list_spec.rb
+++ b/spec/unit/knife/cookbook_list_spec.rb
@@ -37,7 +37,7 @@ describe Chef::Knife::CookbookList do
describe 'run' do
it 'should display the latest version of the cookbooks' do
- expect(@rest_mock).to receive(:get_rest).with('/cookbooks?num_versions=1').
+ expect(@rest_mock).to receive(:get).with('/cookbooks?num_versions=1').
and_return(@cookbook_data)
@knife.run
@cookbook_names.each do |item|
@@ -47,7 +47,7 @@ describe Chef::Knife::CookbookList do
it 'should query cookbooks for the configured environment' do
@knife.config[:environment] = 'production'
- expect(@rest_mock).to receive(:get_rest).
+ expect(@rest_mock).to receive(:get).
with('/environments/production/cookbooks?num_versions=1').
and_return(@cookbook_data)
@knife.run
@@ -56,7 +56,7 @@ describe Chef::Knife::CookbookList do
describe 'with -w or --with-uri' do
it 'should display the cookbook uris' do
@knife.config[:with_uri] = true
- allow(@rest_mock).to receive(:get_rest).and_return(@cookbook_data)
+ allow(@rest_mock).to receive(:get).and_return(@cookbook_data)
@knife.run
@cookbook_names.each do |item|
pattern = /#{Regexp.escape(@cookbook_data[item]['versions'].first['url'])}/
@@ -75,7 +75,7 @@ describe Chef::Knife::CookbookList do
it 'should display all versions of the cookbooks' do
@knife.config[:all_versions] = true
- expect(@rest_mock).to receive(:get_rest).with('/cookbooks?num_versions=all').
+ expect(@rest_mock).to receive(:get).with('/cookbooks?num_versions=all').
and_return(@cookbook_data)
@knife.run
@cookbook_names.each do |item|
diff --git a/spec/unit/knife/cookbook_show_spec.rb b/spec/unit/knife/cookbook_show_spec.rb
index bf480e3678..a06e53b9a1 100644
--- a/spec/unit/knife/cookbook_show_spec.rb
+++ b/spec/unit/knife/cookbook_show_spec.rb
@@ -25,7 +25,7 @@ describe Chef::Knife::CookbookShow do
@knife = Chef::Knife::CookbookShow.new
@knife.config = { }
@knife.name_args = [ "cookbook_name" ]
- @rest = double(Chef::REST)
+ @rest = double(Chef::ServerAPI)
allow(@knife).to receive(:rest).and_return(@rest)
allow(@knife).to receive(:pretty_print).and_return(true)
allow(@knife).to receive(:output).and_return(true)
@@ -56,14 +56,14 @@ describe Chef::Knife::CookbookShow do
end
it "should show the raw cookbook data" do
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name").and_return(@response)
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name").and_return(@response)
expect(@knife).to receive(:format_cookbook_list_for_display).with(@response)
@knife.run
end
it "should respect the user-supplied environment" do
@knife.config[:environment] = "foo"
- expect(@rest).to receive(:get_rest).with("environments/foo/cookbooks/cookbook_name").and_return(@response)
+ expect(@rest).to receive(:get).with("environments/foo/cookbooks/cookbook_name").and_return(@response)
expect(@knife).to receive(:format_cookbook_list_for_display).with(@response)
@knife.run
end
@@ -76,7 +76,7 @@ describe Chef::Knife::CookbookShow do
end
it "should show the specific part of a cookbook" do
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@response)
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@response)
expect(@knife).to receive(:output).with(@response)
@knife.run
end
@@ -101,7 +101,7 @@ describe Chef::Knife::CookbookShow do
end
it "should print the json of the part" do
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
expect(@knife).to receive(:output).with(@cookbook_response.manifest["recipes"])
@knife.run
end
@@ -125,8 +125,8 @@ describe Chef::Knife::CookbookShow do
end
it "should print the raw result of the request (likely a file!)" do
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- expect(@rest).to receive(:get_rest).with("http://example.org/files/default.rb", true).and_return(StringIO.new(@response))
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("http://example.org/files/default.rb", true).and_return(StringIO.new(@response))
expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
@@ -177,8 +177,8 @@ describe Chef::Knife::CookbookShow do
@knife.config[:platform] = "example_platform"
@knife.config[:platform_version] = "1.0"
@knife.config[:fqdn] = "examplehost.example.org"
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- expect(@rest).to receive(:get_rest).with("http://example.org/files/1111", true).and_return(StringIO.new(@response))
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("http://example.org/files/1111", true).and_return(StringIO.new(@response))
expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
@@ -189,8 +189,8 @@ describe Chef::Knife::CookbookShow do
@knife.config[:platform] = "ubuntu"
@knife.config[:platform_version] = "1.0"
@knife.config[:fqdn] = "differenthost.example.org"
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- expect(@rest).to receive(:get_rest).with("http://example.org/files/3333", true).and_return(StringIO.new(@response))
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("http://example.org/files/3333", true).and_return(StringIO.new(@response))
expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
@@ -201,8 +201,8 @@ describe Chef::Knife::CookbookShow do
@knife.config[:platform] = "ubuntu"
@knife.config[:platform_version] = "9.10"
@knife.config[:fqdn] = "differenthost.example.org"
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- expect(@rest).to receive(:get_rest).with("http://example.org/files/2222", true).and_return(StringIO.new(@response))
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("http://example.org/files/2222", true).and_return(StringIO.new(@response))
expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
@@ -210,8 +210,8 @@ describe Chef::Knife::CookbookShow do
describe "with none of the arguments, it should use the default" do
it "should pass them all" do
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- expect(@rest).to receive(:get_rest).with("http://example.org/files/4444", true).and_return(StringIO.new(@response))
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("http://example.org/files/4444", true).and_return(StringIO.new(@response))
expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
diff --git a/spec/unit/knife/cookbook_site_download_spec.rb b/spec/unit/knife/cookbook_site_download_spec.rb
index fdf4c2197b..35c6544d58 100644
--- a/spec/unit/knife/cookbook_site_download_spec.rb
+++ b/spec/unit/knife/cookbook_site_download_spec.rb
@@ -35,7 +35,7 @@ describe Chef::Knife::CookbookSiteDownload do
allow(@knife.ui).to receive(:stderr).and_return(@stderr)
allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest)
- expect(@noauth_rest).to receive(:get_rest).
+ expect(@noauth_rest).to receive(:get).
with("#{@cookbook_api_url}/apache2").
and_return(@current_data)
end
@@ -66,10 +66,10 @@ describe Chef::Knife::CookbookSiteDownload do
context 'downloading the latest version' do
before do
- expect(@noauth_rest).to receive(:get_rest).
+ expect(@noauth_rest).to receive(:get).
with(@current_data['latest_version']).
and_return(@cookbook_data)
- expect(@noauth_rest).to receive(:get_rest).
+ expect(@noauth_rest).to receive(:get).
with(@cookbook_data['file'], true).
and_return(@temp_file)
end
@@ -131,10 +131,10 @@ describe Chef::Knife::CookbookSiteDownload do
end
it 'should download the desired version' do
- expect(@noauth_rest).to receive(:get_rest).
+ expect(@noauth_rest).to receive(:get).
with("#{@cookbook_api_url}/apache2/versions/#{@version_us}").
and_return(@cookbook_data)
- expect(@noauth_rest).to receive(:get_rest).
+ expect(@noauth_rest).to receive(:get).
with(@cookbook_data['file'], true).
and_return(@temp_file)
expect(FileUtils).to receive(:cp).with(@temp_file.path, @file)
diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb
index a7caca9744..1b2ffd10fb 100644
--- a/spec/unit/knife/cookbook_site_share_spec.rb
+++ b/spec/unit/knife/cookbook_site_share_spec.rb
@@ -36,7 +36,7 @@ describe Chef::Knife::CookbookSiteShare do
allow(@cookbook_loader).to receive(:[]).and_return(@cookbook)
allow(Chef::CookbookLoader).to receive(:new).and_return(@cookbook_loader)
- @noauth_rest = double(Chef::REST)
+ @noauth_rest = double(Chef::ServerAPI)
allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest)
@cookbook_uploader = Chef::CookbookUploader.new('herpderp', :rest => "norest")
@@ -78,21 +78,21 @@ describe Chef::Knife::CookbookSiteShare do
it 'should not fail when given only 1 argument and can determine category' do
@knife.name_args = ['cookbook_name']
- expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@category_response)
+ expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@category_response)
expect(@knife).to receive(:do_upload)
@knife.run
end
it 'should print error and exit when given only 1 argument and cannot determine category' do
@knife.name_args = ['cookbook_name']
- expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response)
+ expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response)
expect(@knife.ui).to receive(:fatal)
expect { @knife.run }.to raise_error(SystemExit)
end
- it 'should print error and exit when given only 1 argument and Chef::REST throws an exception' do
+ it 'should print error and exit when given only 1 argument and Chef::ServerAPI throws an exception' do
@knife.name_args = ['cookbook_name']
- expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Errno::ECONNREFUSED, "Connection refused" }
+ expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Errno::ECONNREFUSED, "Connection refused" }
expect(@knife.ui).to receive(:fatal)
expect { @knife.run }.to raise_error(SystemExit)
end
diff --git a/spec/unit/knife/cookbook_site_unshare_spec.rb b/spec/unit/knife/cookbook_site_unshare_spec.rb
index ec46a8705c..aafb7c1507 100644
--- a/spec/unit/knife/cookbook_site_unshare_spec.rb
+++ b/spec/unit/knife/cookbook_site_unshare_spec.rb
@@ -26,8 +26,8 @@ describe Chef::Knife::CookbookSiteUnshare do
@knife.name_args = ['cookbook_name']
allow(@knife).to receive(:confirm).and_return(true)
- @rest = double('Chef::REST')
- allow(@rest).to receive(:delete_rest).and_return(true)
+ @rest = double('Chef::ServerAPI')
+ allow(@rest).to receive(:delete).and_return(true)
allow(@knife).to receive(:rest).and_return(@rest)
@stdout = StringIO.new
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
@@ -50,20 +50,20 @@ describe Chef::Knife::CookbookSiteUnshare do
end
it 'should send a delete request to the cookbook site' do
- expect(@rest).to receive(:delete_rest)
+ expect(@rest).to receive(:delete)
@knife.run
end
it 'should log an error and exit when forbidden' do
exception = double('403 "Forbidden"', :code => '403')
- allow(@rest).to receive(:delete_rest).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception))
+ allow(@rest).to receive(:delete).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception))
expect(@knife.ui).to receive(:error)
expect { @knife.run }.to raise_error(SystemExit)
end
- it 'should re-raise any non-forbidden errors on delete_rest' do
+ it 'should re-raise any non-forbidden errors on delete' do
exception = double('500 "Application Error"', :code => '500')
- allow(@rest).to receive(:delete_rest).and_raise(Net::HTTPServerException.new('500 "Application Error"', exception))
+ allow(@rest).to receive(:delete).and_raise(Net::HTTPServerException.new('500 "Application Error"', exception))
expect { @knife.run }.to raise_error(Net::HTTPServerException)
end
diff --git a/spec/unit/knife/data_bag_create_spec.rb b/spec/unit/knife/data_bag_create_spec.rb
index c31c88577d..d022cc7f7d 100644
--- a/spec/unit/knife/data_bag_create_spec.rb
+++ b/spec/unit/knife/data_bag_create_spec.rb
@@ -28,7 +28,7 @@ describe Chef::Knife::DataBagCreate do
k
end
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:stdout) { StringIO.new }
let(:bag_name) { "sudoing_admins" }
@@ -58,7 +58,7 @@ describe Chef::Knife::DataBagCreate do
end
it "creates a data bag" do
- expect(rest).to receive(:post_rest).with("data", {"name" => bag_name})
+ expect(rest).to receive(:post).with("data", {"name" => bag_name})
expect(knife.ui).to receive(:info).with("Created data_bag[#{bag_name}]")
knife.run
@@ -75,8 +75,8 @@ describe Chef::Knife::DataBagCreate do
it "creates a data bag item" do
expect(knife).to receive(:create_object).and_yield(raw_hash)
expect(knife).to receive(:encryption_secret_provided?).and_return(false)
- expect(rest).to receive(:post_rest).with("data", {'name' => bag_name}).ordered
- expect(rest).to receive(:post_rest).with("data/#{bag_name}", item).ordered
+ expect(rest).to receive(:post).with("data", {'name' => bag_name}).ordered
+ expect(rest).to receive(:post).with("data/#{bag_name}", item).ordered
knife.run
end
@@ -99,8 +99,8 @@ describe Chef::Knife::DataBagCreate do
.to receive(:encrypt_data_bag_item)
.with(raw_hash, secret)
.and_return(encoded_data)
- expect(rest).to receive(:post_rest).with("data", {"name" => bag_name}).ordered
- expect(rest).to receive(:post_rest).with("data/#{bag_name}", item).ordered
+ expect(rest).to receive(:post).with("data", {"name" => bag_name}).ordered
+ expect(rest).to receive(:post).with("data/#{bag_name}", item).ordered
knife.run
end
diff --git a/spec/unit/knife/data_bag_edit_spec.rb b/spec/unit/knife/data_bag_edit_spec.rb
index 6f19b5e63e..f1bcae990b 100644
--- a/spec/unit/knife/data_bag_edit_spec.rb
+++ b/spec/unit/knife/data_bag_edit_spec.rb
@@ -37,7 +37,7 @@ describe Chef::Knife::DataBagEdit do
let(:db) { Chef::DataBagItem.from_hash(raw_hash)}
let(:raw_edited_hash) { {"login_name" => "rho", "id" => "item_name", "new_key" => "new_value"} }
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:stdout) { StringIO.new }
let(:bag_name) { "sudoing_admins" }
@@ -56,7 +56,7 @@ describe Chef::Knife::DataBagEdit do
expect(Chef::DataBagItem).to receive(:load).with(bag_name, item_name).and_return(db)
expect(knife).to receive(:encrypted?).with(db.raw_data).and_return(is_encrypted?)
expect(knife).to receive(:edit_data).with(data_to_edit).and_return(raw_edited_hash)
- expect(rest).to receive(:put_rest).with("data/#{bag_name}/#{item_name}", transmitted_hash).ordered
+ expect(rest).to receive(:put).with("data/#{bag_name}/#{item_name}", transmitted_hash).ordered
knife.run
end
diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb
index 8b6502145c..dc65a3e64c 100644
--- a/spec/unit/knife/data_bag_from_file_spec.rb
+++ b/spec/unit/knife/data_bag_from_file_spec.rb
@@ -79,7 +79,7 @@ describe Chef::Knife::DataBagFromFile do
} }
let(:enc_data) { Chef::EncryptedDataBagItem.encrypt_data_bag_item(plain_data, secret) }
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:stdout) { StringIO.new }
let(:bag_name) { "sudoing_admins" }
diff --git a/spec/unit/knife/data_bag_show_spec.rb b/spec/unit/knife/data_bag_show_spec.rb
index 1125d99c2a..48a0071b49 100644
--- a/spec/unit/knife/data_bag_show_spec.rb
+++ b/spec/unit/knife/data_bag_show_spec.rb
@@ -39,7 +39,7 @@ describe Chef::Knife::DataBagShow do
k
end
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:stdout) { StringIO.new }
let(:bag_name) { "sudoing_admins" }
diff --git a/spec/unit/knife/environment_compare_spec.rb b/spec/unit/knife/environment_compare_spec.rb
index 6d4d3ead52..81ec19d7af 100644
--- a/spec/unit/knife/environment_compare_spec.rb
+++ b/spec/unit/knife/environment_compare_spec.rb
@@ -51,7 +51,7 @@ describe Chef::Knife::EnvironmentCompare do
'url' => "#{@base_url}/#{item}/1.0.1"}]}
end
- allow(@rest_double).to receive(:get_rest).with("/cookbooks?num_versions=1").and_return(@cookbook_data)
+ allow(@rest_double).to receive(:get).with("/cookbooks?num_versions=1").and_return(@cookbook_data)
@stdout = StringIO.new
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
diff --git a/spec/unit/knife/index_rebuild_spec.rb b/spec/unit/knife/index_rebuild_spec.rb
index 6c3b60bd88..d8a0dd72d7 100644
--- a/spec/unit/knife/index_rebuild_spec.rb
+++ b/spec/unit/knife/index_rebuild_spec.rb
@@ -21,7 +21,7 @@ require 'spec_helper'
describe Chef::Knife::IndexRebuild do
let(:knife){Chef::Knife::IndexRebuild.new}
- let(:rest_client){double(Chef::REST)}
+ let(:rest_client){double(Chef::ServerAPI)}
let(:stub_rest!) do
expect(knife).to receive(:rest).and_return(rest_client)
@@ -45,7 +45,7 @@ describe Chef::Knife::IndexRebuild do
before(:each) do
stub_rest!
- allow(rest_client).to receive(:get_rest).and_raise(http_server_exception)
+ allow(rest_client).to receive(:get).and_raise(http_server_exception)
end
context "against a Chef 11 server" do
@@ -110,7 +110,7 @@ describe Chef::Knife::IndexRebuild do
let(:api_info){ {} }
let(:server_specific_stubs!) do
stub_rest!
- expect(rest_client).to receive(:post_rest).with("/search/reindex", {}).and_return("representative output")
+ expect(rest_client).to receive(:post).with("/search/reindex", {}).and_return("representative output")
expect(knife).not_to receive(:unsupported_server_message)
expect(knife).to receive(:deprecated_server_message)
expect(knife).to receive(:nag)
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb
index 5ab8e84eac..c2127fdfd5 100644
--- a/spec/unit/knife_spec.rb
+++ b/spec/unit/knife_spec.rb
@@ -156,8 +156,8 @@ describe Chef::Knife do
"Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
'X-Chef-Version' => Chef::VERSION,
"Host"=>"api.opscode.piab",
- "X-REMOTE-REQUEST-ID"=>request_id,
- 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION}}
+ "X-REMOTE-REQUEST-ID"=>request_id
+ }}
let(:request_id) {"1234"}
@@ -201,7 +201,7 @@ describe Chef::Knife do
it "confirms that the headers include X-Remote-Request-Id" do
expect(Net::HTTP::Get).to receive(:new).with("/monkey", headers).and_return(request_mock)
- rest.get_rest("monkey")
+ rest.get("monkey")
end
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index 76cf451323..d7cee80d40 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -1271,8 +1271,8 @@ describe Chef::Node do
describe "api model" do
before(:each) do
- @rest = double("Chef::REST")
- allow(Chef::REST).to receive(:new).and_return(@rest)
+ @rest = double("Chef::ServerAPI")
+ allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
@query = double("Chef::Search::Query")
allow(Chef::Search::Query).to receive(:new).and_return(@query)
end
@@ -1281,6 +1281,7 @@ describe Chef::Node do
describe "inflated" do
it "should return a hash of node names and objects" do
n1 = double("Chef::Node", :name => "one")
+ allow(n1).to receive(:kind_of?).with(Chef::Node) { true }
expect(@query).to receive(:search).with(:node).and_yield(n1)
r = Chef::Node.list(true)
expect(r["one"]).to eq(n1)
@@ -1288,7 +1289,7 @@ describe Chef::Node do
end
it "should return a hash of node names and urls" do
- expect(@rest).to receive(:get_rest).and_return({ "one" => "http://foo" })
+ expect(@rest).to receive(:get).and_return({ "one" => "http://foo" })
r = Chef::Node.list
expect(r["one"]).to eq("http://foo")
end
@@ -1296,14 +1297,19 @@ describe Chef::Node do
describe "load" do
it "should load a node by name" do
- expect(@rest).to receive(:get_rest).with("nodes/monkey").and_return("foo")
- expect(Chef::Node.load("monkey")).to eq("foo")
+ node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
+ json = Chef::JSONCompat.to_json(node)
+ parsed = Chef::JSONCompat.parse(json)
+ expect(@rest).to receive(:get).with("nodes/test.example.com").and_return(parsed)
+ serialized_node = Chef::Node.load("test.example.com")
+ expect(serialized_node).to be_a_kind_of(Chef::Node)
+ expect(serialized_node.name).to eql(node.name)
end
end
describe "destroy" do
it "should destroy a node" do
- expect(@rest).to receive(:delete_rest).with("nodes/monkey").and_return("foo")
+ expect(@rest).to receive(:delete).with("nodes/monkey").and_return("foo")
node.name("monkey")
node.destroy
end
@@ -1313,15 +1319,15 @@ describe Chef::Node do
it "should update a node if it already exists" do
node.name("monkey")
allow(node).to receive(:data_for_save).and_return({})
- expect(@rest).to receive(:put_rest).with("nodes/monkey", {}).and_return("foo")
+ expect(@rest).to receive(:put).with("nodes/monkey", {}).and_return("foo")
node.save
end
it "should not try and create if it can update" do
node.name("monkey")
allow(node).to receive(:data_for_save).and_return({})
- expect(@rest).to receive(:put_rest).with("nodes/monkey", {}).and_return("foo")
- expect(@rest).not_to receive(:post_rest)
+ expect(@rest).to receive(:put).with("nodes/monkey", {}).and_return("foo")
+ expect(@rest).not_to receive(:post)
node.save
end
@@ -1329,8 +1335,8 @@ describe Chef::Node do
node.name("monkey")
allow(node).to receive(:data_for_save).and_return({})
exception = double("404 error", :code => "404")
- expect(@rest).to receive(:put_rest).and_raise(Net::HTTPServerException.new("foo", exception))
- expect(@rest).to receive(:post_rest).with("nodes", {})
+ expect(@rest).to receive(:put).and_raise(Net::HTTPServerException.new("foo", exception))
+ expect(@rest).to receive(:post).with("nodes", {})
node.save
end
@@ -1343,8 +1349,8 @@ describe Chef::Node do
end
it "should not save" do
node.name("monkey")
- expect(@rest).not_to receive(:put_rest)
- expect(@rest).not_to receive(:post_rest)
+ expect(@rest).not_to receive(:put)
+ expect(@rest).not_to receive(:post)
node.save
end
end
@@ -1388,7 +1394,7 @@ describe Chef::Node do
node.name("picky-monkey")
allow(node).to receive(:for_json).and_return(data)
- expect(@rest).to receive(:put_rest).with("nodes/picky-monkey", selected_data).and_return("foo")
+ expect(@rest).to receive(:put).with("nodes/picky-monkey", selected_data).and_return("foo")
node.save
end
@@ -1422,7 +1428,7 @@ describe Chef::Node do
node.name("falsey-monkey")
allow(node).to receive(:for_json).and_return(data)
- expect(@rest).to receive(:put_rest).with("nodes/falsey-monkey", selected_data).and_return("foo")
+ expect(@rest).to receive(:put).with("nodes/falsey-monkey", selected_data).and_return("foo")
node.save
end
@@ -1445,7 +1451,7 @@ describe Chef::Node do
node.name("picky-monkey")
allow(node).to receive(:for_json).and_return(data)
- expect(@rest).to receive(:put_rest).with("nodes/picky-monkey", selected_data).and_return("foo")
+ expect(@rest).to receive(:put).with("nodes/picky-monkey", selected_data).and_return("foo")
node.save
end
end
@@ -1461,12 +1467,12 @@ describe Chef::Node do
context "and the server supports policyfile attributes in node JSON" do
it "creates the object normally" do
- expect(@rest).to receive(:post_rest).with("nodes", node.for_json)
+ expect(@rest).to receive(:post).with("nodes", node.for_json)
node.create
end
it "saves the node object normally" do
- expect(@rest).to receive(:put_rest).with("nodes/example-node", node.for_json)
+ expect(@rest).to receive(:put).with("nodes/example-node", node.for_json)
node.save
end
end
@@ -1514,8 +1520,8 @@ describe Chef::Node do
context "when the node exists" do
it "falls back to saving without policyfile attributes" do
- expect(@rest).to receive(:put_rest).with("nodes/example-node", node.for_json).and_raise(http_exception)
- expect(@rest).to receive(:put_rest).with("nodes/example-node", trimmed_node).and_return(@node)
+ expect(@rest).to receive(:put).with("nodes/example-node", node.for_json).and_raise(http_exception)
+ expect(@rest).to receive(:put).with("nodes/example-node", trimmed_node).and_return(@node)
expect { node.save }.to_not raise_error
end
@@ -1536,15 +1542,15 @@ describe Chef::Node do
end
it "falls back to saving without policyfile attributes" do
- expect(@rest).to receive(:put_rest).with("nodes/example-node", node.for_json).and_raise(http_exception)
- expect(@rest).to receive(:put_rest).with("nodes/example-node", trimmed_node).and_raise(http_exception_404)
- expect(@rest).to receive(:post_rest).with("nodes", trimmed_node).and_return(@node)
+ expect(@rest).to receive(:put).with("nodes/example-node", node.for_json).and_raise(http_exception)
+ expect(@rest).to receive(:put).with("nodes/example-node", trimmed_node).and_raise(http_exception_404)
+ expect(@rest).to receive(:post).with("nodes", trimmed_node).and_return(@node)
node.save
end
it "creates the node without policyfile attributes" do
- expect(@rest).to receive(:post_rest).with("nodes", node.for_json).and_raise(http_exception)
- expect(@rest).to receive(:post_rest).with("nodes", trimmed_node).and_return(@node)
+ expect(@rest).to receive(:post).with("nodes", node.for_json).and_raise(http_exception)
+ expect(@rest).to receive(:post).with("nodes", trimmed_node).and_return(@node)
node.create
end
end
diff --git a/spec/unit/org_spec.rb b/spec/unit/org_spec.rb
index cd6cc94d91..97e1b87704 100644
--- a/spec/unit/org_spec.rb
+++ b/spec/unit/org_spec.rb
@@ -136,7 +136,7 @@ describe Chef::Org do
let(:rest) do
Chef::Config[:chef_server_root] = "http://www.example.com"
r = double('rest')
- allow(Chef::REST).to receive(:new).and_return(r)
+ allow(Chef::ServerAPI).to receive(:new).and_return(r)
r
end
@@ -151,27 +151,27 @@ describe Chef::Org do
let(:inflated_response) { {"foobar" => org } }
it "lists all orgs" do
- expect(rest).to receive(:get_rest).with("organizations").and_return(response)
+ expect(rest).to receive(:get).with("organizations").and_return(response)
expect(Chef::Org.list).to eq(response)
end
it "inflate all orgs" do
allow(Chef::Org).to receive(:load).with("foobar").and_return(org)
- expect(rest).to receive(:get_rest).with("organizations").and_return(response)
+ expect(rest).to receive(:get).with("organizations").and_return(response)
expect(Chef::Org.list(true)).to eq(inflated_response)
end
end
describe "create" do
it "creates a new org via the API" do
- expect(rest).to receive(:post_rest).with("organizations", {:name => "foobar", :full_name => "foo bar bat"}).and_return({})
+ expect(rest).to receive(:post).with("organizations", {:name => "foobar", :full_name => "foo bar bat"}).and_return({})
org.create
end
end
describe "read" do
it "loads a named org from the API" do
- expect(rest).to receive(:get_rest).with("organizations/foobar").and_return({"name" => "foobar", "full_name" => "foo bar bat", "private_key" => "private"})
+ expect(rest).to receive(:get).with("organizations/foobar").and_return({"name" => "foobar", "full_name" => "foo bar bat", "private_key" => "private"})
org = Chef::Org.load("foobar")
expect(org.name).to eq("foobar")
expect(org.full_name).to eq("foo bar bat")
@@ -181,14 +181,14 @@ describe Chef::Org do
describe "update" do
it "updates an existing org on via the API" do
- expect(rest).to receive(:put_rest).with("organizations/foobar", {:name => "foobar", :full_name => "foo bar bat"}).and_return({})
+ expect(rest).to receive(:put).with("organizations/foobar", {:name => "foobar", :full_name => "foo bar bat"}).and_return({})
org.update
end
end
describe "destroy" do
it "deletes the specified org via the API" do
- expect(rest).to receive(:delete_rest).with("organizations/foobar")
+ expect(rest).to receive(:delete).with("organizations/foobar")
org.destroy
end
end
diff --git a/spec/unit/policy_builder/expand_node_object_spec.rb b/spec/unit/policy_builder/expand_node_object_spec.rb
index 306d677108..944d4d3387 100644
--- a/spec/unit/policy_builder/expand_node_object_spec.rb
+++ b/spec/unit/policy_builder/expand_node_object_spec.rb
@@ -290,7 +290,7 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
node
end
- let(:chef_http) { double("Chef::REST") }
+ let(:chef_http) { double("Chef::ServerAPI") }
let(:cookbook_resolve_url) { "environments/#{node.chef_environment}/cookbook_versions" }
let(:cookbook_resolve_post_data) { {:run_list=>["first::default", "second::default"]} }
@@ -298,7 +298,8 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
# cookbook_hash is just a hash, but since we're passing it between mock
# objects, we get a little better test strictness by using a double (which
# will have object equality rather than semantic equality #== semantics).
- let(:cookbook_hash) { double("cookbook hash", :each => nil) }
+ let(:cookbook_hash) { double("cookbook hash") }
+ let(:expanded_cookbook_hash) { double("expanded cookbook hash", :each => nil) }
let(:cookbook_synchronizer) { double("CookbookSynchronizer") }
@@ -310,8 +311,9 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
run_list_expansion = policy_builder.run_list_expansion
+ expect(cookbook_hash).to receive(:inject).and_return(expanded_cookbook_hash)
expect(chef_http).to receive(:post).with(cookbook_resolve_url, cookbook_resolve_post_data).and_return(cookbook_hash)
- expect(Chef::CookbookSynchronizer).to receive(:new).with(cookbook_hash, events).and_return(cookbook_synchronizer)
+ expect(Chef::CookbookSynchronizer).to receive(:new).with(expanded_cookbook_hash, events).and_return(cookbook_synchronizer)
expect(cookbook_synchronizer).to receive(:sync_cookbooks)
expect_any_instance_of(Chef::RunContext).to receive(:load).with(run_list_expansion)
diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb
index ed893260c2..3dfa8d9802 100644
--- a/spec/unit/policy_builder/policyfile_spec.rb
+++ b/spec/unit/policy_builder/policyfile_spec.rb
@@ -98,10 +98,10 @@ describe Chef::PolicyBuilder::Policyfile do
let(:err_namespace) { Chef::PolicyBuilder::Policyfile }
it "configures a Chef HTTP API client" do
- http = double("Chef::REST")
+ http = double("Chef::ServerAPI")
server_url = "https://api.opscode.com/organizations/example"
Chef::Config[:chef_server_url] = server_url
- expect(Chef::REST).to receive(:new).with(server_url).and_return(http)
+ expect(Chef::ServerAPI).to receive(:new).with(server_url).and_return(http)
expect(policy_builder.http_api).to eq(http)
end
@@ -151,7 +151,7 @@ describe Chef::PolicyBuilder::Policyfile do
describe "loading policy data" do
- let(:http_api) { double("Chef::REST") }
+ let(:http_api) { double("Chef::ServerAPI") }
let(:configured_environment) { nil }
diff --git a/spec/unit/provider/http_request_spec.rb b/spec/unit/provider/http_request_spec.rb
index a84dd5e2a0..980458abd3 100644
--- a/spec/unit/provider/http_request_spec.rb
+++ b/spec/unit/provider/http_request_spec.rb
@@ -34,7 +34,7 @@ describe Chef::Provider::HttpRequest do
describe "load_current_resource" do
- it "should set up a Chef::REST client, with no authentication" do
+ it "should set up a Chef::ServerAPI client, with no authentication" do
expect(Chef::HTTP::Simple).to receive(:new).with(@new_resource.url)
@provider.load_current_resource
end
@@ -45,7 +45,7 @@ describe Chef::Provider::HttpRequest do
# run_action(x) forces load_current_resource to run;
# that would overwrite our supplied mock Chef::Rest # object
allow(@provider).to receive(:load_current_resource).and_return(true)
- @http = double("Chef::REST")
+ @http = double("Chef::ServerAPI")
@provider.http = @http
end
diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb
index f2c0b8fd8b..5b991b5f38 100644
--- a/spec/unit/resource_reporter_spec.rb
+++ b/spec/unit/resource_reporter_spec.rb
@@ -36,8 +36,8 @@ describe Chef::ResourceReporter do
before do
@node = Chef::Node.new
@node.name("spitfire")
- @rest_client = double("Chef::REST (mock)")
- allow(@rest_client).to receive(:post_rest).and_return(true)
+ @rest_client = double("Chef::ServerAPI (mock)")
+ allow(@rest_client).to receive(:post).and_return(true)
@resource_reporter = Chef::ResourceReporter.new(@rest_client)
@new_resource = Chef::Resource::File.new("/tmp/a-file.txt")
@cookbook_name = "monkey"
@@ -92,9 +92,8 @@ describe Chef::ResourceReporter do
context "when chef fails" do
before do
- allow(@rest_client).to receive(:create_url).and_return("reports/nodes/spitfire/runs/#{@run_id}");
- allow(@rest_client).to receive(:raw_http_request).and_return({"result"=>"ok"});
- allow(@rest_client).to receive(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"});
+ allow(@rest_client).to receive(:raw_request).and_return({"result"=>"ok"});
+ allow(@rest_client).to receive(:post).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"});
end
@@ -260,9 +259,8 @@ describe Chef::ResourceReporter do
describe "when generating a report for the server" do
before do
- allow(@rest_client).to receive(:create_url).and_return("reports/nodes/spitfire/runs/#{@run_id}");
- allow(@rest_client).to receive(:raw_http_request).and_return({"result"=>"ok"});
- allow(@rest_client).to receive(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"});
+ allow(@rest_client).to receive(:raw_request).and_return({"result"=>"ok"});
+ allow(@rest_client).to receive(:post).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"});
@resource_reporter.run_started(@run_status)
end
@@ -592,7 +590,7 @@ describe Chef::ResourceReporter do
# 404 getting the run_id
@response = Net::HTTPNotFound.new("a response body", "404", "Not Found")
@error = Net::HTTPServerException.new("404 message", @response)
- expect(@rest_client).to receive(:post_rest).
+ expect(@rest_client).to receive(:post).
with("reports/nodes/spitfire/runs", {:action => :start, :run_id => @run_id,
:start_time => @start_time.to_s},
{'X-Ops-Reporting-Protocol-Version' => Chef::ResourceReporter::PROTOCOL_VERSION}).
@@ -606,7 +604,7 @@ describe Chef::ResourceReporter do
it "does not send a resource report to the server" do
@resource_reporter.run_started(@run_status)
- expect(@rest_client).not_to receive(:post_rest)
+ expect(@rest_client).not_to receive(:post)
@resource_reporter.run_completed(@node)
end
@@ -622,7 +620,7 @@ describe Chef::ResourceReporter do
# 500 getting the run_id
@response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error")
@error = Net::HTTPServerException.new("500 message", @response)
- expect(@rest_client).to receive(:post_rest).
+ expect(@rest_client).to receive(:post).
with("reports/nodes/spitfire/runs", {:action => :start, :run_id => @run_id, :start_time => @start_time.to_s},
{'X-Ops-Reporting-Protocol-Version' => Chef::ResourceReporter::PROTOCOL_VERSION}).
and_raise(@error)
@@ -635,7 +633,7 @@ describe Chef::ResourceReporter do
it "does not send a resource report to the server" do
@resource_reporter.run_started(@run_status)
- expect(@rest_client).not_to receive(:post_rest)
+ expect(@rest_client).not_to receive(:post)
@resource_reporter.run_completed(@node)
end
@@ -652,7 +650,7 @@ describe Chef::ResourceReporter do
# 500 getting the run_id
@response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error")
@error = Net::HTTPServerException.new("500 message", @response)
- expect(@rest_client).to receive(:post_rest).
+ expect(@rest_client).to receive(:post).
with("reports/nodes/spitfire/runs", {:action => :start, :run_id => @run_id, :start_time => @start_time.to_s},
{'X-Ops-Reporting-Protocol-Version' => Chef::ResourceReporter::PROTOCOL_VERSION}).
and_raise(@error)
@@ -673,7 +671,7 @@ describe Chef::ResourceReporter do
context "after creating the run history document" do
before do
response = {"uri"=>"https://example.com/reports/nodes/spitfire/runs/@run_id"}
- expect(@rest_client).to receive(:post_rest).
+ expect(@rest_client).to receive(:post).
with("reports/nodes/spitfire/runs", {:action => :start, :run_id => @run_id, :start_time => @start_time.to_s},
{'X-Ops-Reporting-Protocol-Version' => Chef::ResourceReporter::PROTOCOL_VERSION}).
and_return(response)
@@ -693,16 +691,10 @@ describe Chef::ResourceReporter do
allow(@resource_reporter).to receive(:end_time).and_return(@end_time)
@expected_data = @resource_reporter.prepare_run_data
- post_url = "https://chef_server/example_url"
response = {"result"=>"ok"}
- expect(@rest_client).to receive(:create_url).
- with("reports/nodes/spitfire/runs/#{@run_id}").
- ordered.
- and_return(post_url)
- expect(@rest_client).to receive(:raw_http_request).ordered do |method, url, headers, data|
+ expect(@rest_client).to receive(:raw_request).ordered do |method, url, headers, data|
expect(method).to eq(:POST)
- expect(url).to eq(post_url)
expect(headers).to eq({'Content-Encoding' => 'gzip',
'X-Ops-Reporting-Protocol-Version' => Chef::ResourceReporter::PROTOCOL_VERSION
})
@@ -720,8 +712,6 @@ describe Chef::ResourceReporter do
before do
@enable_reporting_url_fatals = Chef::Config[:enable_reporting_url_fatals]
Chef::Config[:enable_reporting_url_fatals] = true
- # this call doesn't matter for this context
- allow(@rest_client).to receive(:create_url)
end
after do
@@ -731,7 +721,7 @@ describe Chef::ResourceReporter do
it "should log 4xx errors" do
response = Net::HTTPClientError.new("forbidden", "403", "Forbidden")
error = Net::HTTPServerException.new("403 message", response)
- allow(@rest_client).to receive(:raw_http_request).and_raise(error)
+ allow(@rest_client).to receive(:raw_request).and_raise(error)
expect(Chef::Log).to receive(:error).with(/403/)
@resource_reporter.post_reporting_data
@@ -740,14 +730,14 @@ describe Chef::ResourceReporter do
it "should log error 5xx errors" do
response = Net::HTTPServerError.new("internal error", "500", "Internal Server Error")
error = Net::HTTPFatalError.new("500 message", response)
- allow(@rest_client).to receive(:raw_http_request).and_raise(error)
+ allow(@rest_client).to receive(:raw_request).and_raise(error)
expect(Chef::Log).to receive(:error).with(/500/)
@resource_reporter.post_reporting_data
end
it "should log if a socket error happens" do
- allow(@rest_client).to receive(:raw_http_request).and_raise(SocketError.new("test socket error"))
+ allow(@rest_client).to receive(:raw_request).and_raise(SocketError.new("test socket error"))
expect(Chef::Log).to receive(:error).with(/test socket error/)
@resource_reporter.post_reporting_data
@@ -755,7 +745,7 @@ describe Chef::ResourceReporter do
end
it "should raise if an unkwown error happens" do
- allow(@rest_client).to receive(:raw_http_request).and_raise(Exception.new)
+ allow(@rest_client).to receive(:raw_request).and_raise(Exception.new)
expect {
@resource_reporter.post_reporting_data
diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb
index ecc7945a08..6e9b133c50 100644
--- a/spec/unit/role_spec.rb
+++ b/spec/unit/role_spec.rb
@@ -201,7 +201,7 @@ describe Chef::Role do
describe "and it has per-environment run lists" do
before do
@role.env_run_lists("_default" => ['one', 'two', 'role[a]'], "production" => ['role[monitoring]', 'role[auditing]', 'role[apache]'], "dev" => ["role[nginx]"])
- @serialized_role = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@role), :create_additions => false)
+ @serialized_role = Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@role), :create_additions => false)
end
it "includes the per-environment run lists" do
@@ -229,7 +229,7 @@ describe Chef::Role do
@role.run_list('one', 'two', 'role[a]')
@role.default_attributes({ 'el_groupo' => 'nuevo' })
@role.override_attributes({ 'deloused' => 'in the comatorium' })
- @deserial = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@role))
+ @deserial = Chef::Role.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@role)))
end
it "should deserialize to a Chef::Role object" do
diff --git a/spec/unit/run_list_spec.rb b/spec/unit/run_list_spec.rb
index e150579431..634b5c54cf 100644
--- a/spec/unit/run_list_spec.rb
+++ b/spec/unit/run_list_spec.rb
@@ -172,10 +172,11 @@ describe Chef::RunList do
@role.run_list "one", "two"
@role.default_attributes :one => :two
@role.override_attributes :three => :four
+ @role.env_run_list["production"] = Chef::RunList.new( "one", "two", "five")
allow(Chef::Role).to receive(:load).and_return(@role)
- @rest = double("Chef::REST", { :get_rest => @role, :url => "/" })
- allow(Chef::REST).to receive(:new).and_return(@rest)
+ @rest = double("Chef::ServerAPI", { :get => @role.to_hash, :url => "/" })
+ allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
@run_list << "role[stubby]"
@run_list << "kitty"
@@ -196,21 +197,17 @@ describe Chef::RunList do
describe "from the chef server" do
it "should load the role from the chef server" do
- #@rest.should_receive(:get_rest).with("roles/stubby")
+ #@rest.should_receive(:get).with("roles/stubby")
expansion = @run_list.expand("_default", "server")
expect(expansion.recipes).to eq(['one', 'two', 'kitty'])
end
it "should default to expanding from the server" do
- expect(@rest).to receive(:get_rest).with("roles/stubby")
+ expect(@rest).to receive(:get).with("roles/stubby")
@run_list.expand("_default")
end
describe "with an environment set" do
- before do
- @role.env_run_list["production"] = Chef::RunList.new( "one", "two", "five")
- end
-
it "expands the run list using the environment specific run list" do
expansion = @run_list.expand("production", "server")
expect(expansion.recipes).to eq(%w{one two five kitty})
@@ -218,7 +215,7 @@ describe Chef::RunList do
describe "and multiply nested roles" do
before do
- @multiple_rest_requests = double("Chef::REST")
+ @multiple_rest_requests = double("Chef::ServerAPI")
@role.env_run_list["production"] << "role[prod-base]"
@@ -233,10 +230,10 @@ describe Chef::RunList do
end
it "expands the run list using the specified environment for all nested roles" do
- allow(Chef::REST).to receive(:new).and_return(@multiple_rest_requests)
- expect(@multiple_rest_requests).to receive(:get_rest).with("roles/stubby").and_return(@role)
- expect(@multiple_rest_requests).to receive(:get_rest).with("roles/prod-base").and_return(@role_prod_base)
- expect(@multiple_rest_requests).to receive(:get_rest).with("roles/nested-deeper").and_return(@role_nested_deeper)
+ allow(Chef::ServerAPI).to receive(:new).and_return(@multiple_rest_requests)
+ expect(@multiple_rest_requests).to receive(:get).with("roles/stubby").and_return(@role.to_hash)
+ expect(@multiple_rest_requests).to receive(:get).with("roles/prod-base").and_return(@role_prod_base.to_hash)
+ expect(@multiple_rest_requests).to receive(:get).with("roles/nested-deeper").and_return(@role_nested_deeper.to_hash)
expansion = @run_list.expand("production", "server")
expect(expansion.recipes).to eq(%w{one two five prod-secret-sauce kitty})
diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb
index f85b1760d4..c390f658bc 100644
--- a/spec/unit/search/query_spec.rb
+++ b/spec/unit/search/query_spec.rb
@@ -20,7 +20,7 @@ require 'spec_helper'
require 'chef/search/query'
describe Chef::Search::Query do
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:query) { Chef::Search::Query.new }
shared_context "filtered search" do
@@ -76,8 +76,8 @@ describe Chef::Search::Query do
end
before(:each) do
- allow(Chef::REST).to receive(:new).and_return(rest)
- allow(rest).to receive(:get_rest).and_return(response)
+ allow(Chef::ServerAPI).to receive(:new).and_return(rest)
+ allow(rest).to receive(:get).and_return(response)
end
describe "search" do
@@ -91,6 +91,7 @@ describe Chef::Search::Query do
{ "name" => "my-name-is-node",
"chef_environment" => "elysium",
"platform" => "rhel",
+ "run_list" => [],
"automatic" => {
"languages" => {
"ruby" => {
@@ -104,6 +105,7 @@ describe Chef::Search::Query do
{ "name" => "my-name-is-jonas",
"chef_environment" => "hades",
"platform" => "rhel",
+ "run_list" => [],
"automatic" => {
"languages" => {
"ruby" => {
@@ -117,6 +119,7 @@ describe Chef::Search::Query do
{ "name" => "my-name-is-flipper",
"chef_environment" => "elysium",
"platform" => "rhel",
+ "run_list" => [],
"automatic" => {
"languages" => {
"ruby" => {
@@ -130,6 +133,7 @@ describe Chef::Search::Query do
{ "name" => "my-name-is-butters",
"chef_environment" => "moon",
"platform" => "rhel",
+ "run_list" => [],
"automatic" => {
"languages" => {
"ruby" => {
@@ -173,27 +177,27 @@ describe Chef::Search::Query do
end
it "queries for every object of a type by default" do
- expect(rest).to receive(:get_rest).with("search/node?q=*:*&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response)
+ expect(rest).to receive(:get).with("search/node?q=*:*&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response)
query.search(:node)
end
it "allows a custom query" do
- expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response)
+ expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response)
query.search(:node, "platform:rhel")
end
it "lets you set a sort order" do
- expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=id%20desc&start=0").and_return(response)
+ expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=id%20desc&start=0").and_return(response)
query.search(:node, "platform:rhel", sort: "id desc")
end
it "lets you set a starting object" do
- expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=2").and_return(response)
+ expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=2").and_return(response)
query.search(:node, "platform:rhel", start: 2)
end
it "lets you set how many rows to return" do
- expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=40").and_return(response)
+ expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=40").and_return(response)
query.search(:node, "platform:rhel", rows: 40)
end
@@ -211,27 +215,27 @@ describe Chef::Search::Query do
it "calls a block for each object in the response" do
@call_me = double("blocky")
- response["rows"].each { |r| expect(@call_me).to receive(:do).with(r) }
+ response["rows"].each { |r| expect(@call_me).to receive(:do).with(Chef::Node.from_hash(r)) }
query.search(:node) { |r| @call_me.do(r) }
end
it "pages through the responses" do
@call_me = double("blocky")
- response["rows"].each { |r| expect(@call_me).to receive(:do).with(r) }
+ response["rows"].each { |r| expect(@call_me).to receive(:do).with(Chef::Node.from_hash(r)) }
query.search(:node, "*:*", sort: nil, start: 0, rows: 4) { |r| @call_me.do(r) }
end
it "sends multiple API requests when the server indicates there is more data" do
- expect(rest).to receive(:get_rest).with(query_string).and_return(big_response)
- expect(rest).to receive(:get_rest).with(query_string_continue).and_return(big_response_end)
+ expect(rest).to receive(:get).with(query_string).and_return(big_response)
+ expect(rest).to receive(:get).with(query_string_continue).and_return(big_response_end)
query.search(:node, "platform:rhel") do |r|
nil
end
end
it "paginates correctly in the face of filtered nodes" do
- expect(rest).to receive(:get_rest).with(query_string_with_rows).and_return(big_response_empty)
- expect(rest).to receive(:get_rest).with(query_string_continue_with_rows).and_return(big_response_end)
+ expect(rest).to receive(:get).with(query_string_with_rows).and_return(big_response_empty)
+ expect(rest).to receive(:get).with(query_string_continue_with_rows).and_return(big_response_end)
query.search(:node, "platform:rhel", rows: 4) do |r|
nil
end
@@ -242,7 +246,7 @@ describe Chef::Search::Query do
let(:filter_key) { :filter_result }
before(:each) do
- expect(rest).to receive(:post_rest).with(query_string, args[filter_key]).and_return(response)
+ expect(rest).to receive(:post).with(query_string, args[filter_key]).and_return(response)
end
it "returns start" do
@@ -276,7 +280,7 @@ describe Chef::Search::Query do
end
it "returns an array of filtered hashes" do
- expect(rest).to receive(:post_rest).with(query_string, args[filter_key]).and_return(response)
+ expect(rest).to receive(:post).with(query_string, args[filter_key]).and_return(response)
results = query.partial_search(:node, "platform:rhel", args)
expect(results[0]).to match_array(response_rows)
end
diff --git a/spec/unit/shell/shell_session_spec.rb b/spec/unit/shell/shell_session_spec.rb
index d72e3fa1bb..d1cedb3236 100644
--- a/spec/unit/shell/shell_session_spec.rb
+++ b/spec/unit/shell/shell_session_spec.rb
@@ -50,7 +50,7 @@ end
describe Shell::ClientSession do
before do
Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] }
- @chef_rest = double("Chef::REST")
+ @chef_rest = double("Chef::ServerAPI")
@session = Shell::ClientSession.instance
@node = Chef::Node.build("foo")
@session.node = @node
@@ -67,7 +67,7 @@ describe Shell::ClientSession do
@expansion = Chef::RunList::RunListExpansion.new(@node.chef_environment, [])
expect(@node.run_list).to receive(:expand).with(@node.chef_environment).and_return(@expansion)
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(@chef_rest)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(@chef_rest)
@session.rebuild_context
end
diff --git a/spec/unit/user_v1_spec.rb b/spec/unit/user_v1_spec.rb
index 8fd370a010..a981de1d8c 100644
--- a/spec/unit/user_v1_spec.rb
+++ b/spec/unit/user_v1_spec.rb
@@ -539,8 +539,8 @@ describe Chef::UserV1 do
before (:each) do
@user = Chef::UserV1.new
@user.username "foobar"
- @http_client = double("Chef::REST mock")
- allow(Chef::REST).to receive(:new).and_return(@http_client)
+ @http_client = double("Chef::ServerAPI mock")
+ allow(Chef::ServerAPI).to receive(:new).and_return(@http_client)
end
describe "list" do