diff options
author | James Casey <james@opscode.com> | 2014-02-18 14:29:29 -0800 |
---|---|---|
committer | James Casey <james@opscode.com> | 2014-02-18 14:29:29 -0800 |
commit | cc0ac93046dd6104bfc5dde8c77f7d9fcf9b48c4 (patch) | |
tree | 9f6c86eee9dcdd27b6db9c9779fa31148acb66fd | |
parent | 3283be36412a3e6b1c674d61e06444d51ca69b9c (diff) | |
download | chef-cc0ac93046dd6104bfc5dde8c77f7d9fcf9b48c4.tar.gz |
Add --validator option to create validator client via knife
Also update tests to check the defaults for admin/validator
-rw-r--r-- | lib/chef/knife/client_create.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/client_create_spec.rb | 30 |
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/chef/knife/client_create.rb b/lib/chef/knife/client_create.rb index 285254aef0..b2bac36081 100644 --- a/lib/chef/knife/client_create.rb +++ b/lib/chef/knife/client_create.rb @@ -38,6 +38,11 @@ class Chef :description => "Create the client as an admin", :boolean => true + option :validator, + :long => "--validator", + :description => "Create the client as a validator", + :boolean => true + banner "knife client create CLIENT (options)" def run @@ -52,6 +57,7 @@ class Chef client = Chef::ApiClient.new client.name(@client_name) client.admin(config[:admin]) + client.validator(config[:validator]) output = edit_data(client) diff --git a/spec/unit/knife/client_create_spec.rb b/spec/unit/knife/client_create_spec.rb index 69c55ba015..897cee8974 100644 --- a/spec/unit/knife/client_create_spec.rb +++ b/spec/unit/knife/client_create_spec.rb @@ -25,7 +25,9 @@ describe Chef::Knife::ClientCreate do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::ClientCreate.new @knife.config = { - :file => nil + :file => nil, + :admin => false, + :validator => false } @knife.name_args = [ "adam" ] @client = Chef::ApiClient.new @@ -49,6 +51,16 @@ describe Chef::Knife::ClientCreate do @knife.run end + it "by default it is not an admin" do + @client.should_receive(:admin).with(false) + @knife.run + end + + it "by default it is not a validator" do + @client.should_receive(:validator).with(false) + @knife.run + end + it "should allow you to edit the data" do @knife.should_receive(:edit_data).with(@client) @knife.run @@ -70,5 +82,21 @@ describe Chef::Knife::ClientCreate do end end + describe "with -a or --admin" do + it "should create an admin client" do + @knife.config[:admin] = true + @client.should_receive(:admin).with(true) + @knife.run + end + end + + describe "with --validator" do + it "should create an validator client" do + @knife.config[:validator] = true + @client.should_receive(:validator).with(true) + @knife.run + end + end + end end |