/
em-ssh_spec.rb
53 lines (49 loc) · 1.66 KB
/
em-ssh_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'em-ssh'
require_relative "spec_helper"
module EM::Ssh::Test
include Constants
describe "EM::Ssh" do
it "should be addressable through EM::P and EM::Protocols" do
EM::P.const_defined?(:Ssh).should be true
EM::Protocols.const_defined?(:Ssh).should be true
EM::P::Ssh.should == EM::Ssh
EM::Protocols::Ssh.should == EM::Ssh
end
it "should raise a ConnectionTimeout error when a connection can't be established before the given timeout" do
expect {
EM.run {
EM::Ssh.start(REMOTE1_IP, REMOTE1_USERNAME, :timeout => 1) do |ssh|
ssh.callback { EM.stop }
ssh.errback{|e| raise e }
end
}
}.to raise_error(EM::Ssh::ConnectionTimeout)
end # should raise a ConnectionTimeout error when a connection can't be established before the given timeout
it "should raise a ConnectionError when the address is invalid" do
expect {
EM.run {
EM::Ssh.start('0.0.0.1', 'caleb') do |ssh| # 0.0.0.1 is an invalid address
ssh.callback { EM.stop }
ssh.errback { |e| raise(e) }
end
}
}.to raise_error(EM::ConnectionError)
end # should raise a ConnectionFailed when the address is invalid
it "should run exec! succesfully" do
res = ""
EM.run {
EM::Ssh.start(REMOTE2_URL, REMOTE2_USERNAME) do |con|
con.errback do |err|
raise err
end
con.callback do |ssh|
res = ssh.exec!("uname -a")
ssh.close
EM.stop
end
end
}
res.should == REMOTE2_UNAME_A
end
end # EM::Ssh
end # module::EM::Ssh::Test