summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Casey <james@opscode.com>2014-02-21 11:32:43 -0800
committerJames Casey <james@opscode.com>2014-02-21 11:32:43 -0800
commit2a8c2c1146dd714bfe18efc1917177b1ea6dae7e (patch)
treecb86a0ddf7a2402e197f6e395fe21a201a291284
parentb3b677d3164861376e01c230eae94c3fa26a2234 (diff)
parentcc0ac93046dd6104bfc5dde8c77f7d9fcf9b48c4 (diff)
downloadchef-2a8c2c1146dd714bfe18efc1917177b1ea6dae7e.tar.gz
Merge pull request #1270 from opscode/jc/OC-130/knife-create-validator
New command line option for knife client create to create validator
-rw-r--r--lib/chef/knife/client_create.rb6
-rw-r--r--spec/unit/knife/client_create_spec.rb30
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