From b8c7472f5e9101160c727ea70e52376cb67389e1 Mon Sep 17 00:00:00 2001 From: Nick Gauthier Date: Wed, 27 Jan 2010 15:42:53 -0500 Subject: [PATCH] ssh testing with new messaging system --- lib/hydra/ssh.rb | 4 +++- test/echo_the_dolphin.rb | 6 +----- test/test_ssh.rb | 27 ++++++++------------------- 3 files changed, 12 insertions(+), 25 deletions(-) mode change 100644 => 100755 test/echo_the_dolphin.rb diff --git a/lib/hydra/ssh.rb b/lib/hydra/ssh.rb index cb4acfe..470341e 100644 --- a/lib/hydra/ssh.rb +++ b/lib/hydra/ssh.rb @@ -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 diff --git a/test/echo_the_dolphin.rb b/test/echo_the_dolphin.rb old mode 100644 new mode 100755 index 0c67875..9d9d12e --- a/test/echo_the_dolphin.rb +++ b/test/echo_the_dolphin.rb @@ -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 diff --git a/test/test_ssh.rb b/test/test_ssh.rb index 2367a70..741aafb 100644 --- a/test/test_ssh.rb +++ b/test/test_ssh.rb @@ -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