summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-12-11 20:31:24 -0800
committerdanielsdeleo <dan@opscode.com>2012-12-12 13:26:17 -0800
commitb0bd5359610355cb0c776e4de74cc0540042759b (patch)
treea683e45c1064d989a7d4fd8686120067064ea950 /spec
parentbda8bbf38241c5a1dd75cd28ad9dcb89bcf808cc (diff)
downloadchef-b0bd5359610355cb0c776e4de74cc0540042759b.tar.gz
[CHEF-3662] knife client reregister uses ApiClient#reregister
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/knife/client_reregister_spec.rb45
1 files changed, 23 insertions, 22 deletions
diff --git a/spec/unit/knife/client_reregister_spec.rb b/spec/unit/knife/client_reregister_spec.rb
index 0d284c0f58..d9fc8ec180 100644
--- a/spec/unit/knife/client_reregister_spec.rb
+++ b/spec/unit/knife/client_reregister_spec.rb
@@ -22,40 +22,41 @@ describe Chef::Knife::ClientReregister do
before(:each) do
@knife = Chef::Knife::ClientReregister.new
@knife.name_args = [ 'adam' ]
- @client_mock = mock('client_mock')
- @client_mock.stub!(:save).and_return({ 'private_key' => 'foo_key' })
- Chef::ApiClient.stub!(:load).and_return(@client_mock)
+ @client_mock = mock('client_mock', :private_key => "foo_key")
@stdout = StringIO.new
@knife.ui.stub!(:stdout).and_return(@stdout)
end
- describe 'run' do
- it 'should load and save the client' do
- Chef::ApiClient.should_receive(:load).with('adam').and_return(@client_mock)
- @client_mock.should_receive(:save).with(true).and_return({'private_key' => 'foo_key'})
- @knife.run
- end
-
- it 'should output the private key' do
- @knife.run
- @stdout.string.should match /foo_key/
+ context "when no client name is given on the command line" do
+ before do
+ @knife.name_args = []
end
it 'should print usage and exit when a client name is not provided' do
- @knife.name_args = []
@knife.should_receive(:show_usage)
@knife.ui.should_receive(:fatal)
lambda { @knife.run }.should raise_error(SystemExit)
end
+ end
+
+ context 'when not configured for file output' do
+ it 'reregisters the client and prints the key' do
+ Chef::ApiClient.should_receive(:reregister).with('adam').and_return(@client_mock)
+ @knife.run
+ @stdout.string.should match( /foo_key/ )
+ end
+ end
- describe 'with -f or --file' do
- it 'should write the private key to a file' do
- @knife.config[:file] = '/tmp/monkeypants'
- filehandle = mock('Filehandle')
- filehandle.should_receive(:print).with('foo_key')
- File.should_receive(:open).with('/tmp/monkeypants', 'w').and_yield(filehandle)
- @knife.run
- end
+ context 'when configured for file output' do
+ it 'should write the private key to a file' do
+ Chef::ApiClient.should_receive(:reregister).with('adam').and_return(@client_mock)
+
+ @knife.config[:file] = '/tmp/monkeypants'
+ filehandle = StringIO.new
+ File.should_receive(:open).with('/tmp/monkeypants', 'w').and_yield(filehandle)
+ @knife.run
+ filehandle.string.should == "foo_key"
end
end
+
end