Testing ssh connection

an important part of my project is logging on to a remote server using ssh and doing something with the files on it:

Net::SSH.start(@host, @username, :password => @password) do |ssh|  
  ssh.exec!(rename_files_on_remote_server) 
end

How to check it? I think I can turn on the local ssh server and check the file names on it (maybe it could be in my test / spec directory). Or maybe someone can point me to a better solution?

+3
source share
2 answers

I think this is enough to verify that you are sending the correct commands to the ssh server. You apparently are not using the server, so you need to believe that the server is working properly and is being tested.

, , , SSH, ( RSpec 2):

describe "SSH Access" do
  let (:ssh_connection) { mock("SSH Connection") }
  before (:each) do
    Net::SSH.stub(:start) { ssh_connection }
  end
  it "should send rename commands to the connection" do
    ssh_connection.should_receive(:exec!).ordered.with("expected command")
    ssh_connection.should_receive(:exec!).ordered.with("next expected command")
    SSHAccessClass.rename_files!
  end
end
+5

, :

. "localhost" "127.0.0.1", . Mac OS Linux , :

`hostname`

require 'socket'
hostname = Socket.gethostname

.

, .

+1

Source: https://habr.com/ru/post/1768587/


All Articles