From a40586d4ff5936b901918f6e5fc3b51a5af0af2d Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Thu, 28 Apr 2016 23:44:24 +0100 Subject: Add tests for errors before exit_status() --- tests/channel.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests') 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); +} -- cgit v1.2.3