ssh testing with new messaging system
This commit is contained in:
parent
33b9885bc0
commit
b8c7472f5e
|
@ -26,8 +26,10 @@ module Hydra #:nodoc:
|
|||
# Hydra::SSH.new('user@server.com')
|
||||
# Hydra::SSH.new('-p 3022 user@server.com')
|
||||
# etc..
|
||||
def initialize(connection_options)
|
||||
def initialize(connection_options, directory, command)
|
||||
@writer, @reader, @error = popen3("ssh #{connection_options}")
|
||||
@writer.write("cd #{directory}\n")
|
||||
@writer.write(command+"\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
#!/usr/bin/env ruby
|
||||
# read lines from stdin
|
||||
# echo each line back
|
||||
# on EOF, quit nicely
|
||||
|
||||
# Echoes back to the sender
|
||||
$stdout.sync = true
|
||||
|
||||
while line = $stdin.gets
|
||||
$stdout.write(line)
|
||||
end
|
||||
|
|
|
@ -3,27 +3,16 @@ require File.join(File.dirname(__FILE__), 'helper')
|
|||
class TestSSH < Test::Unit::TestCase
|
||||
context "an ssh connection" do
|
||||
setup do
|
||||
@ssh = Hydra::SSH.new('localhost')
|
||||
@ssh = Hydra::SSH.new(
|
||||
'localhost', # connect to this machine
|
||||
File.expand_path(File.join(File.dirname(__FILE__))), # move to the test directory
|
||||
"ruby ./echo_the_dolphin.rb"
|
||||
)
|
||||
@message = Hydra::Messages::TestMessage.new
|
||||
end
|
||||
should "be able to execute a command" do
|
||||
@ssh.write "echo hi"
|
||||
assert_equal "hi", @ssh.gets
|
||||
end
|
||||
should "be able to execute a command with a newline" do
|
||||
@ssh.write "echo hi\n"
|
||||
assert_equal "hi", @ssh.gets
|
||||
end
|
||||
should "be able to communicate with a process" do
|
||||
pwd = File.dirname(__FILE__)
|
||||
echo_the_dolphin = File.expand_path(
|
||||
File.join(File.dirname(__FILE__), 'echo_the_dolphin.rb')
|
||||
)
|
||||
@ssh.write('ruby -e "puts \'Hello\'"')
|
||||
assert_equal "Hello", @ssh.gets
|
||||
|
||||
@ssh.write("ruby #{echo_the_dolphin}")
|
||||
@ssh.write("Hello Echo!")
|
||||
assert_equal "Hello Echo!", @ssh.gets
|
||||
@ssh.write @message
|
||||
assert_equal @message.text, @ssh.gets.text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue