Commit c88a0d69 authored by Thomas Dudziak's avatar Thomas Dudziak Committed by Bryan McLellan
Browse files

Added tests for CHEF-3455

parent 9f265a6d
......@@ -45,6 +45,15 @@ describe Chef::Knife::Configure do
@knife.new_client_name.should == Etc.getlogin
end
it "should not ask the user for the clientname they want for the new client if -i and --node_name are specified" do
@knife.config[:initial] = true
@knife.config[:node_name] = 'testnode'
Etc.stub!(:getlogin).and_return("a-new-user")
@knife.ask_user_for_config
@out.string.should_not match(Regexp.escape("Please enter a clientname for the new client"))
@knife.new_client_name.should == 'testnode'
end
it "asks the user for the existing API username or clientname if -i is not specified" do
Etc.stub!(:getlogin).and_return("a-new-user")
@knife.ask_user_for_config
......@@ -53,30 +62,46 @@ describe Chef::Knife::Configure do
end
it "asks the user for the existing admin client's name if -i is specified" do
@knife.config[:initial] = true
@knife.ask_user_for_config
@out.string.should match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]"))
@knife.admin_client_name.should == 'chef-webui'
end
it "should not ask the user for the existing admin client's name if -i is not specified" do
@knife.ask_user_for_config
@out.string.should_not match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]"))
@knife.admin_client_name.should_not == 'chef-webui'
end
it "asks the user for the location of the existing admin key if -i is specified" do
@knife.config[:initial] = true
@knife.ask_user_for_config
@out.string.should match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]"))
@knife.admin_client_key.should == '/etc/chef/webui.pem'
end
it "should not ask the user for the location of the existing admin key if -i is not specified" do
@knife.ask_user_for_config
@out.string.should_not match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]"))
@knife.admin_client_key.should_not == '/etc/chef/webui.pem'
end
@knife.config[:initial] = true
@knife.ask_user_for_config
@out.string.should match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]"))
@knife.admin_client_name.should == 'chef-webui'
end
it "should not ask the user for the existing admin client's name if -i and --admin-client_name are specified" do
@knife.config[:initial] = true
@knife.config[:admin_client_name] = 'my-webui'
@knife.ask_user_for_config
@out.string.should_not match(Regexp.escape("Please enter the existing admin clientname:"))
@knife.admin_client_name.should == 'my-webui'
end
it "should not ask the user for the existing admin client's name if -i is not specified" do
@knife.ask_user_for_config
@out.string.should_not match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]"))
@knife.admin_client_name.should_not == 'chef-webui'
end
it "asks the user for the location of the existing admin key if -i is specified" do
@knife.config[:initial] = true
@knife.ask_user_for_config
@out.string.should match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]"))
@knife.admin_client_key.should == '/etc/chef/webui.pem'
end
it "should not ask the user for the location of the existing admin key if -i and --admin_client_key are specified" do
@knife.config[:initial] = true
@knife.config[:admin_client_key] = '/home/you/.chef/my-webui.pem'
@knife.ask_user_for_config
@out.string.should_not match(Regexp.escape("Please enter the location of the existing admin client's private key:"))
@knife.admin_client_key.should == '/home/you/.chef/my-webui.pem'
end
it "should not ask the user for the location of the existing admin key if -i is not specified" do
@knife.ask_user_for_config
@out.string.should_not match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]"))
@knife.admin_client_key.should_not == '/etc/chef/webui.pem'
end
it "asks the user for the location of a chef repo" do
@knife.ask_user_for_config
......@@ -90,14 +115,56 @@ describe Chef::Knife::Configure do
@knife.validation_client_name.should == 'chef-validator'
end
it "should not ask the users for the name of the validation client if --validation_client_name is specified" do
@knife.config[:validation_client_name] = 'my-validator'
@knife.ask_user_for_config
@out.string.should_not match(Regexp.escape("Please enter the validation clientname:"))
@knife.validation_client_name.should == 'my-validator'
end
it "asks the users for the location of the validation key" do
@knife.ask_user_for_config
@out.string.should match(Regexp.escape("Please enter the location of the validation key: [/etc/chef/validation.pem]"))
@knife.validation_key.should == '/etc/chef/validation.pem'
end
it "should not ask the users for the location of the validation key if --validation_key is specified" do
@knife.config[:validation_key] = '/home/you/.chef/my-validation.pem'
@knife.ask_user_for_config
@out.string.should_not match(Regexp.escape("Please enter the location of the validation key:"))
@knife.validation_key.should == '/home/you/.chef/my-validation.pem'
end
it "should not ask the user for anything if -i and all other properties are specified" do
@knife.config[:initial] = true
@knife.config[:chef_server_url] = 'http://localhost:5000'
@knife.config[:node_name] = 'testnode'
@knife.config[:admin_client_name] = 'my-webui'
@knife.config[:admin_client_key] = '/home/you/.chef/my-webui.pem'
@knife.config[:validation_client_name] = 'my-validator'
@knife.config[:validation_key] = '/home/you/.chef/my-validation.pem'
@knife.config[:repository] = ''
@knife.config[:client_key] = '/home/you/a-new-user.pem'
Etc.stub!(:getlogin).and_return('a-new-user')
@knife.ask_user_for_config
@out.string.should match(/\s*/)
@knife.new_client_name.should == 'testnode'
@knife.chef_server.should == 'http://localhost:5000'
@knife.admin_client_name.should == 'my-webui'
@knife.admin_client_key.should == '/home/you/.chef/my-webui.pem'
@knife.validation_client_name.should == 'my-validator'
@knife.validation_key.should == '/home/you/.chef/my-validation.pem'
@knife.chef_repo.should == ''
@knife.new_client_key.should == '/home/you/a-new-user.pem'
end
it "writes the new data to a config file" do
File.stub!(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
File.stub!(:expand_path).with("/home/you/.chef/#{Etc.getlogin}.pem").and_return("/home/you/.chef/#{Etc.getlogin}.pem")
File.stub!(:expand_path).with("/etc/chef/validation.pem").and_return("/etc/chef/validation.pem")
File.stub!(:expand_path).with("/etc/chef/webui.pem").and_return("/etc/chef/webui.pem")
FileUtils.should_receive(:mkdir_p).with("/home/you/.chef")
config_file = StringIO.new
::File.should_receive(:open).with("/home/you/.chef/knife.rb", "w").and_yield config_file
......@@ -113,6 +180,9 @@ describe Chef::Knife::Configure do
it "creates a new client when given the --initial option" do
File.stub!(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
File.stub!(:expand_path).with("/home/you/.chef/a-new-user.pem").and_return("/home/you/.chef/a-new-user.pem")
File.stub!(:expand_path).with("/etc/chef/validation.pem").and_return("/etc/chef/validation.pem")
File.stub!(:expand_path).with("/etc/chef/webui.pem").and_return("/etc/chef/webui.pem")
Chef::Config[:node_name] = "webmonkey.example.com"
client_command = Chef::Knife::ClientCreate.new
client_command.should_receive(:run)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment