summaryrefslogtreecommitdiff
path: root/spec/unit/api_client_spec.rb
diff options
context:
space:
mode:
authortylercloke <tylercloke@gmail.com>2015-06-03 13:21:50 -0700
committertylercloke <tylercloke@gmail.com>2015-06-05 10:38:49 -0700
commiteb49eedb6333bc1c6b82d0c7befffb9188c5b523 (patch)
tree50272e378ea73a4692dc5b9c160a0a1fb5d1f98c /spec/unit/api_client_spec.rb
parenta929c389252d5da4c3ddc2f0cce10e43e6dc19ab (diff)
downloadchef-eb49eedb6333bc1c6b82d0c7befffb9188c5b523.tar.gz
Use Chef::ServerAPI to create versioned API requests in Chef::(User|Client).
Diffstat (limited to 'spec/unit/api_client_spec.rb')
-rw-r--r--spec/unit/api_client_spec.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb
index e1ffa9252a..a95597d40e 100644
--- a/spec/unit/api_client_spec.rb
+++ b/spec/unit/api_client_spec.rb
@@ -332,24 +332,34 @@ describe Chef::ApiClient do
end
context "and the client exists" do
+ let(:chef_rest_v0_mock) { double('chef rest root v0 object') }
+ let(:payload) {
+ {:name => "lost-my-key", :admin => false, :validator => false, :private_key => true}
+ }
+
before do
@api_client_without_key = Chef::ApiClient.new
@api_client_without_key.name("lost-my-key")
- expect(@http_client).to receive(:get).with("clients/lost-my-key").and_return(@api_client_without_key)
- end
+ allow(@api_client_without_key).to receive(:chef_rest_v0).and_return(chef_rest_v0_mock)
+ #allow(@api_client_with_key).to receive(:http_api).and_return(_api_mock)
+ allow(chef_rest_v0_mock).to receive(:put).with("clients/lost-my-key", payload).and_return(@api_client_with_key)
+ allow(chef_rest_v0_mock).to receive(:get).with("clients/lost-my-key").and_return(@api_client_without_key)
+ allow(@http_client).to receive(:get).with("clients/lost-my-key").and_return(@api_client_without_key)
+ end
context "and the client exists on a Chef 11-like server" do
before do
@api_client_with_key = Chef::ApiClient.new
@api_client_with_key.name("lost-my-key")
@api_client_with_key.private_key("the new private key")
- expect(@http_client).to receive(:put).
- with("clients/lost-my-key", :name => "lost-my-key", :admin => false, :validator => false, :private_key => true).
- and_return(@api_client_with_key)
+ allow(@api_client_with_key).to receive(:chef_rest_v0).and_return(chef_rest_v0_mock)
end
it "returns an ApiClient with a private key" do
+ expect(chef_rest_v0_mock).to receive(:put).with("clients/lost-my-key", payload).
+ and_return(@api_client_with_key)
+
response = Chef::ApiClient.reregister("lost-my-key")
# no sane == method for ApiClient :'(
expect(response).to eq(@api_client_without_key)
@@ -362,7 +372,7 @@ describe Chef::ApiClient do
context "and the client exists on a Chef 10-like server" do
before do
@api_client_with_key = {"name" => "lost-my-key", "private_key" => "the new private key"}
- expect(@http_client).to receive(:put).
+ expect(chef_rest_v0_mock).to receive(:put).
with("clients/lost-my-key", :name => "lost-my-key", :admin => false, :validator => false, :private_key => true).
and_return(@api_client_with_key)
end