From f097dbd78e2535707655fe00cdeee419ade6ea0c Mon Sep 17 00:00:00 2001 From: Brandon LeBlanc Date: Thu, 15 Jun 2023 23:21:08 +0000 Subject: [PATCH] ssh2-rs: add test for channel_direct_streamlocal --- tests/all/channel.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/all/channel.rs b/tests/all/channel.rs index 75ece4eb4..2df3a581c 100644 --- a/tests/all/channel.rs +++ b/tests/all/channel.rs @@ -1,6 +1,7 @@ use ssh2::Channel; use std::io::prelude::*; use std::net::{TcpListener, TcpStream}; +use std::os::unix::net::UnixListener; use std::thread; /// Consume all available stdout and stderr data. @@ -170,6 +171,29 @@ fn direct() { t.join().ok().unwrap(); } +#[test] +fn direct_stream_local() { + let d = tempfile::tempdir().unwrap(); + let path = d.path().join("ssh2-rs-test.sock"); + let a = UnixListener::bind(&path).unwrap(); + let t = thread::spawn(move || { + let mut s = a.accept().unwrap().0; + let mut b = [0, 0, 0]; + s.read(&mut b).unwrap(); + assert_eq!(b, [1, 2, 3]); + s.write_all(&[4, 5, 6]).unwrap(); + }); + let sess = ::authed_session(); + let mut channel = sess + .channel_direct_streamlocal(path.to_str().unwrap(), None) + .unwrap(); + channel.write_all(&[1, 2, 3]).unwrap(); + let mut r = [0, 0, 0]; + channel.read(&mut r).unwrap(); + assert_eq!(r, [4, 5, 6]); + t.join().ok().unwrap(); +} + #[test] fn forward() { let sess = ::authed_session();