mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
is_connected method
This commit is contained in:
@@ -80,6 +80,11 @@ pub trait FileTransfer {
|
|||||||
|
|
||||||
fn disconnect(&mut self) -> Result<(), FileTransferError>;
|
fn disconnect(&mut self) -> Result<(), FileTransferError>;
|
||||||
|
|
||||||
|
/// ### is_connected
|
||||||
|
///
|
||||||
|
/// Indicates whether the client is connected to remote
|
||||||
|
fn is_connected(&self) -> bool;
|
||||||
|
|
||||||
/// ### pwd
|
/// ### pwd
|
||||||
///
|
///
|
||||||
/// Print working directory
|
/// Print working directory
|
||||||
|
|||||||
@@ -177,6 +177,13 @@ impl FileTransfer for SftpFileTransfer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ### is_connected
|
||||||
|
///
|
||||||
|
/// Indicates whether the client is connected to remote
|
||||||
|
fn is_connected(&self) -> bool {
|
||||||
|
self.session.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
/// ### pwd
|
/// ### pwd
|
||||||
///
|
///
|
||||||
/// Print working directory
|
/// Print working directory
|
||||||
@@ -487,11 +494,13 @@ mod tests {
|
|||||||
assert!(client.session.is_none());
|
assert!(client.session.is_none());
|
||||||
assert!(client.sftp.is_none());
|
assert!(client.sftp.is_none());
|
||||||
assert_eq!(client.wrkdir, PathBuf::from("~"));
|
assert_eq!(client.wrkdir, PathBuf::from("~"));
|
||||||
|
assert_eq!(client.is_connected(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_filetransfer_sftp_connect() {
|
fn test_filetransfer_sftp_connect() {
|
||||||
let mut client: SftpFileTransfer = SftpFileTransfer::new();
|
let mut client: SftpFileTransfer = SftpFileTransfer::new();
|
||||||
|
assert_eq!(client.is_connected(), false);
|
||||||
assert!(client
|
assert!(client
|
||||||
.connect(
|
.connect(
|
||||||
String::from("test.rebex.net"),
|
String::from("test.rebex.net"),
|
||||||
@@ -504,8 +513,10 @@ mod tests {
|
|||||||
assert!(client.session.is_some());
|
assert!(client.session.is_some());
|
||||||
assert!(client.sftp.is_some());
|
assert!(client.sftp.is_some());
|
||||||
assert_eq!(client.wrkdir, PathBuf::from("/"));
|
assert_eq!(client.wrkdir, PathBuf::from("/"));
|
||||||
|
assert_eq!(client.is_connected(), true);
|
||||||
// Disconnect
|
// Disconnect
|
||||||
assert!(client.disconnect().is_ok());
|
assert!(client.disconnect().is_ok());
|
||||||
|
assert_eq!(client.is_connected(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user