is_connected method

This commit is contained in:
ChristianVisintin 2020-11-21 17:37:49 +01:00
parent 2d29dfeb33
commit 056f8c7c7f
2 changed files with 16 additions and 0 deletions

View file

@ -80,6 +80,11 @@ pub trait FileTransfer {
fn disconnect(&mut self) -> Result<(), FileTransferError>;
/// ### is_connected
///
/// Indicates whether the client is connected to remote
fn is_connected(&self) -> bool;
/// ### pwd
///
/// Print working directory

View file

@ -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
///
/// Print working directory
@ -487,11 +494,13 @@ mod tests {
assert!(client.session.is_none());
assert!(client.sftp.is_none());
assert_eq!(client.wrkdir, PathBuf::from("~"));
assert_eq!(client.is_connected(), false);
}
#[test]
fn test_filetransfer_sftp_connect() {
let mut client: SftpFileTransfer = SftpFileTransfer::new();
assert_eq!(client.is_connected(), false);
assert!(client
.connect(
String::from("test.rebex.net"),
@ -504,8 +513,10 @@ mod tests {
assert!(client.session.is_some());
assert!(client.sftp.is_some());
assert_eq!(client.wrkdir, PathBuf::from("/"));
assert_eq!(client.is_connected(), true);
// Disconnect
assert!(client.disconnect().is_ok());
assert_eq!(client.is_connected(), false);
}
#[test]