summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAidan Hobson Sayers <aidanhs@cantab.net>2016-04-28 23:44:24 +0100
committerAidan Hobson Sayers <aidanhs@cantab.net>2016-04-28 23:44:24 +0100
commita40586d4ff5936b901918f6e5fc3b51a5af0af2d (patch)
tree4c23d1f38d1e932fcf8b87c2b4ba2d0767e1e86f /tests
parentff42317cbd9b5e206d5460e15cc9f426efc1f459 (diff)
downloadssh2-rs-a40586d4ff5936b901918f6e5fc3b51a5af0af2d.zip
Add tests for errors before exit_status()
Diffstat (limited to 'tests')
-rw-r--r--tests/channel.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/channel.rs b/tests/channel.rs
index 9cced14..33292b4 100644
--- a/tests/channel.rs
+++ b/tests/channel.rs
@@ -124,3 +124,43 @@ fn drop_nonblocking() {
t.join().unwrap();
}
+
+const LIBSSH2_ERROR_EAGAIN: i32 = -37; // from libssh2-sys
+#[test]
+fn nonblocking_before_exit_code() {
+ let (_tcp, sess) = ::authed_session();
+ let mut channel = sess.channel_session().unwrap();
+ channel.send_eof().unwrap();
+ let mut output = String::new();
+
+ channel.exec("sleep 1; echo foo").unwrap();
+ sess.set_blocking(false);
+ assert!(channel.read_to_string(&mut output).is_err());
+ {
+ use std::time::Duration;
+ use std::thread;
+ thread::sleep(Duration::from_millis(1500));
+ }
+ sess.set_blocking(true);
+ assert!(channel.read_to_string(&mut output).is_ok());
+
+ channel.wait_eof().unwrap();
+ channel.close().unwrap();
+ channel.wait_close().unwrap();
+ assert_eq!(output, "foo\n");
+ assert!(::ssh2::Error::last_error(&sess).unwrap().code() == LIBSSH2_ERROR_EAGAIN);
+ assert!(channel.exit_status().unwrap() == 0);
+}
+
+#[test]
+fn exit_code_ignores_other_errors() {
+ let (_tcp, sess) = ::authed_session();
+ let mut channel = sess.channel_session().unwrap();
+ channel.exec("true").unwrap();
+ channel.wait_eof().unwrap();
+ channel.close().unwrap();
+ channel.wait_close().unwrap();
+ let longdescription: String = ::std::iter::repeat('a').take(300).collect();
+ assert!(sess.disconnect(None, &longdescription, None).is_err()); // max len == 256
+ assert!(channel.exit_status().unwrap() == 0);
+}