diff options
author | James Casey <james@opscode.com> | 2014-02-18 13:28:32 -0800 |
---|---|---|
committer | James Casey <james@opscode.com> | 2014-02-18 13:28:32 -0800 |
commit | dc47d5ab78ca3687afb00a0182f458db3f5131de (patch) | |
tree | 055d5971f56e0fb5173f1b659e30783ea7474f69 /spec/unit/api_client_spec.rb | |
parent | 3283be36412a3e6b1c674d61e06444d51ca69b9c (diff) | |
download | chef-dc47d5ab78ca3687afb00a0182f458db3f5131de.tar.gz |
Added unit test for ApiClient.load()
This is failing as it doesn't properly load all fields from the JSON
response
Diffstat (limited to 'spec/unit/api_client_spec.rb')
-rw-r--r-- | spec/unit/api_client_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb index 4ccd64bafe..22211d685f 100644 --- a/spec/unit/api_client_spec.rb +++ b/spec/unit/api_client_spec.rb @@ -164,6 +164,52 @@ describe Chef::ApiClient do end + describe "when loading from JSON", :focus => true do + before do + end + + before(:each) do + client = { + "name" => "black", + "clientname" => "black", + "public_key" => "crowes", + "private_key" => "monkeypants", + "admin" => true, + "validator" => true, + "json_class" => "Chef::ApiClient" + } + @http_client = double("Chef::REST mock") + Chef::REST.stub(:new).and_return(@http_client) + @http_client.should_receive(:get).with("clients/black").and_return(client) + @client = Chef::ApiClient.load(client['name']) + end + + it "should deserialize to a Chef::ApiClient object" do + @client.should be_a_kind_of(Chef::ApiClient) + end + + it "preserves the name" do + @client.name.should == "black" + end + + it "preserves the public key" do + @client.public_key.should == "crowes" + end + + it "preserves the admin status" do + @client.admin.should be_a_kind_of(Chef::TrueClass) + end + + it "preserves the 'validator' status" do + @client.validator.should be_a_kind_of(Chef::TrueClass) + end + + it "includes the private key if present" do + @client.private_key.should == "monkeypants" + end + + end + describe "with correctly configured API credentials" do before do Chef::Config[:node_name] = "silent-bob" |