empty method sshkey_storage

This commit is contained in:
ChristianVisintin
2020-12-24 16:57:04 +01:00
parent 1449b5a524
commit 841db02b30

View File

@@ -57,6 +57,15 @@ impl SshKeyStorage {
SshKeyStorage { hosts } SshKeyStorage { hosts }
} }
/// ### empty
///
/// Create an empty ssh key storage; used in case `ConfigClient` is not available
pub fn empty() -> Self {
SshKeyStorage {
hosts: HashMap::new(),
}
}
/// ### resolve /// ### resolve
/// ///
/// Return RSA key path from host and username /// Return RSA key path from host and username
@@ -97,11 +106,20 @@ mod tests {
// Verify key exists // Verify key exists
let mut exp_key_path: PathBuf = key_path.clone(); let mut exp_key_path: PathBuf = key_path.clone();
exp_key_path.push("pi@192.168.1.31.key"); exp_key_path.push("pi@192.168.1.31.key");
assert_eq!(*storage.resolve("192.168.1.31", "pi").unwrap(), exp_key_path); assert_eq!(
*storage.resolve("192.168.1.31", "pi").unwrap(),
exp_key_path
);
// Verify unexisting key // Verify unexisting key
assert!(storage.resolve("deskichup", "veeso").is_none()); assert!(storage.resolve("deskichup", "veeso").is_none());
} }
#[test]
fn test_system_sshkey_storage_empty() {
let storage: SshKeyStorage = SshKeyStorage::empty();
assert_eq!(storage.hosts.len(), 0);
}
/// ### get_paths /// ### get_paths
/// ///
/// Get paths for configuration and keys directory /// Get paths for configuration and keys directory