more realistic test of ssh channel

This commit is contained in:
Adrian Cole 2012-03-08 16:51:33 -08:00
parent e39fc48901
commit d67aa3bbf5
2 changed files with 20 additions and 8 deletions

View File

@ -27,6 +27,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress; import java.net.InetAddress;
import org.jclouds.compute.domain.ExecChannel; import org.jclouds.compute.domain.ExecChannel;
@ -169,12 +170,17 @@ public class JschSshClientLiveTest {
: sshHost); : sshHost);
} }
public void testExecChannelHostname() throws IOException { public void testExecChannelTakesStdinAndEchosBack() throws IOException {
ExecChannel response = setupClient().execChannel("hostname"); ExecChannel response = setupClient().execChannel("cat <<EOF");
assertEquals(response.getExitStatus().get(), null);
try { try {
PrintStream printStream = new PrintStream(response.getInput());
printStream.append("foo\n");
printStream.append("EOF\n");
printStream.close();
assertEquals(Strings2.toStringAndClose(response.getError()), ""); assertEquals(Strings2.toStringAndClose(response.getError()), "");
assertEquals(Strings2.toStringAndClose(response.getOutput()).trim(), "localhost".equals(sshHost) ? InetAddress // local echo
.getLocalHost().getHostName() : sshHost); assertEquals(Strings2.toStringAndClose(response.getOutput()), "foo\r\nEOF\r\n");
} finally { } finally {
Closeables.closeQuietly(response); Closeables.closeQuietly(response);
} }

View File

@ -27,6 +27,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress; import java.net.InetAddress;
import org.jclouds.compute.domain.ExecChannel; import org.jclouds.compute.domain.ExecChannel;
@ -169,12 +170,17 @@ public class SshjSshClientLiveTest {
: sshHost); : sshHost);
} }
public void testExecChannelHostname() throws IOException { public void testExecChannelTakesStdinAndEchosBack() throws IOException {
ExecChannel response = setupClient().execChannel("hostname"); ExecChannel response = setupClient().execChannel("cat <<EOF");
assertEquals(response.getExitStatus().get(), null);
try { try {
PrintStream printStream = new PrintStream(response.getInput());
printStream.append("foo\n");
printStream.append("EOF\n");
printStream.close();
assertEquals(Strings2.toStringAndClose(response.getError()), ""); assertEquals(Strings2.toStringAndClose(response.getError()), "");
assertEquals(Strings2.toStringAndClose(response.getOutput()).trim(), "localhost".equals(sshHost) ? InetAddress // local echo
.getLocalHost().getHostName() : sshHost); assertEquals(Strings2.toStringAndClose(response.getOutput()), "foo\r\nEOF\r\n");
} finally { } finally {
Closeables.closeQuietly(response); Closeables.closeQuietly(response);
} }