Skip to content

Commit ad53d89

Browse files
committed
Add tests for OverSsh's with_session
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
1 parent 354506e commit ad53d89

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

tests/openssh.rs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
net::IpAddr,
77
path::PathBuf,
88
process,
9-
time::Duration,
9+
time::Duration, ffi::OsStr, os::unix::prelude::OsStrExt,
1010
};
1111
use tempfile::tempdir;
1212
use tokio::{
@@ -292,6 +292,69 @@ async fn stdout() {
292292
}
293293
}
294294

295+
296+
#[tokio::test]
297+
#[cfg_attr(not(ci), ignore)]
298+
async fn with_session() {
299+
for session in connects().await {
300+
let mut command =
301+
std::process::Command::new("echo")
302+
.arg("foo")
303+
.with_session(&session)
304+
.expect("Expected valid utf-8 command.");
305+
306+
let child = command.output().await.unwrap();
307+
assert_eq!(child.stdout, b"foo\n");
308+
309+
let child = session
310+
.command("echo")
311+
.arg("foo")
312+
.raw_arg(">")
313+
.arg("/dev/stderr")
314+
.output()
315+
.await
316+
.unwrap();
317+
assert!(child.stdout.is_empty());
318+
319+
session.close().await.unwrap();
320+
}
321+
}
322+
323+
324+
#[tokio::test]
325+
#[cfg_attr(not(ci), ignore)]
326+
async fn with_session_err() {
327+
328+
for session in connects().await {
329+
let bad_string = OsStr::from_bytes(b"foo\xFF");
330+
let command =
331+
std::process::Command::new("echo")
332+
.arg(bad_string)
333+
.with_session(&session);
334+
335+
let expected_error = openssh::Error::InvalidUtf8String(bad_string.to_owned());
336+
assert!(command.is_err());
337+
let err = command.unwrap_err();
338+
assert_eq!(err.to_string(), expected_error.to_string());
339+
340+
// let child = command.output().await.unwrap();
341+
// assert_eq!(child.stdout, b"foo\n");
342+
343+
// let child = session
344+
// .command("echo")
345+
// .arg("foo")
346+
// .raw_arg(">")
347+
// .arg("/dev/stderr")
348+
// .output()
349+
// .await
350+
// .unwrap();
351+
// assert!(child.stdout.is_empty());
352+
353+
session.close().await.unwrap();
354+
}
355+
}
356+
357+
295358
#[tokio::test]
296359
#[cfg_attr(not(ci), ignore)]
297360
async fn shell() {

0 commit comments

Comments
 (0)