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('user@server.com')
|
||||||
# Hydra::SSH.new('-p 3022 user@server.com')
|
# Hydra::SSH.new('-p 3022 user@server.com')
|
||||||
# etc..
|
# etc..
|
||||||
def initialize(connection_options)
|
def initialize(connection_options, directory, command)
|
||||||
@writer, @reader, @error = popen3("ssh #{connection_options}")
|
@writer, @reader, @error = popen3("ssh #{connection_options}")
|
||||||
|
@writer.write("cd #{directory}\n")
|
||||||
|
@writer.write(command+"\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# read lines from stdin
|
# Echoes back to the sender
|
||||||
# echo each line back
|
|
||||||
# on EOF, quit nicely
|
|
||||||
|
|
||||||
$stdout.sync = true
|
$stdout.sync = true
|
||||||
|
|
||||||
while line = $stdin.gets
|
while line = $stdin.gets
|
||||||
$stdout.write(line)
|
$stdout.write(line)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,27 +3,16 @@ require File.join(File.dirname(__FILE__), 'helper')
|
||||||
class TestSSH < Test::Unit::TestCase
|
class TestSSH < Test::Unit::TestCase
|
||||||
context "an ssh connection" do
|
context "an ssh connection" do
|
||||||
setup 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
|
end
|
||||||
should "be able to execute a command" do
|
should "be able to execute a command" do
|
||||||
@ssh.write "echo hi"
|
@ssh.write @message
|
||||||
assert_equal "hi", @ssh.gets
|
assert_equal @message.text, @ssh.gets.text
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue