Adding initial tests of ssh connection code.

Reviewed-by: Jeff McCune

Signed-off-by: Dan Bode <d...@puppetlabs.com>
---
 spec/unit/puppet/cloudpack_spec.rb |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/spec/unit/puppet/cloudpack_spec.rb 
b/spec/unit/puppet/cloudpack_spec.rb
index 985a3e1..5cd4d3c 100644
--- a/spec/unit/puppet/cloudpack_spec.rb
+++ b/spec/unit/puppet/cloudpack_spec.rb
@@ -111,6 +111,25 @@ describe Puppet::CloudPack do
         @ssh_mock = Fog::SSH::Mock.new('address', 'username', 'options')
         @scp_mock = Fog::SCP::Mock.new('local', 'remote', {})
       end
+      describe '#ssh_connect' do
+        it 'should use the correct options to make a connection' do
+          Fog::SSH.expects(:new).with('server', 'root', {:key_data => 
['FOO']}).returns(@ssh_mock)
+          Fog::SCP.expects(:new).with('server', 'root', {:key_data => 
['FOO']}).returns(@scp_mock)
+          @ssh_mock.expects(:run).with(['hostname'])
+          subject.ssh_connect('server', 'root', @keyfile.path)
+        end
+        it 'should be tolerant of exceptions' do
+          Fog::SSH.expects(:new).with('server', 'root', {:key_data => 
['FOO']}).returns(@ssh_mock)
+          Fog::SCP.expects(:new).with('server', 'root', {:key_data => 
['FOO']}).returns(@scp_mock)
+          @ssh_mock.expects(:run).with do |var| 
raise(Net::SSH::AuthenticationFailed, 'fails') end.with(['hostname'])
+          subject.ssh_connect('server', 'root', @keyfile.path)
+        end
+        it 'Exceptions eventually cause a failure' do
+          Fog::SSH.expects(:new).with('server', 'root', {:key_data => 
['FOO']}).returns(@ssh_mock)
+          @ssh_mock.stubs(:run).with do |var| raise(Exception, 'fails') end
+          expect { subject.ssh_connect('server', 'root', @keyfile.path) 
}.should raise_error
+        end
+      end
     end
     describe '#terminate' do
       describe 'with valid arguments' do
-- 
1.7.5.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to