ssh testing with new messaging system

This commit is contained in:
Nick Gauthier 2010-01-27 15:42:53 -05:00
parent 33b9885bc0
commit b8c7472f5e
3 changed files with 12 additions and 25 deletions

View File

@ -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

6
test/echo_the_dolphin.rb Normal file → Executable file
View File

@ -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

View File

@ -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