This commit is contained in:
veeso
2023-05-09 15:40:21 +02:00
parent 9009002b6e
commit c5eeae74b7
83 changed files with 398 additions and 358 deletions

View File

@@ -2,13 +2,12 @@
//!
//! Automatic update module. This module is used to upgrade the current version of termscp to the latest available on Github
use crate::utils::parser::parse_semver;
use self_update::backends::github::Update as GithubUpdater;
pub use self_update::errors::Error as UpdateError;
use self_update::{
backends::github::Update as GithubUpdater, cargo_crate_version, update::Release as UpdRelease,
Status,
};
use self_update::update::Release as UpdRelease;
use self_update::{cargo_crate_version, Status};
use crate::utils::parser::parse_semver;
/// The status of the update in case of success
#[derive(Debug, Eq, PartialEq)]
@@ -131,10 +130,10 @@ impl From<UpdRelease> for Release {
#[cfg(test)]
mod test {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn auto_update_default() {
let upd: Update = Update::default();

View File

@@ -3,9 +3,16 @@
//! `bookmarks_client` is the module which provides an API between the Bookmarks module and the system
// Crate
// Ext
use std::fs::OpenOptions;
use std::path::{Path, PathBuf};
use std::string::ToString;
use std::time::SystemTime;
use super::keys::filestorage::FileStorage;
#[cfg(feature = "with-keyring")]
use super::keys::keyringstorage::KeyringStorage;
use super::keys::{filestorage::FileStorage, KeyStorage, KeyStorageError};
use super::keys::{KeyStorage, KeyStorageError};
// Local
use crate::config::{
bookmarks::{Bookmark, UserHosts},
@@ -15,11 +22,6 @@ use crate::filetransfer::FileTransferParams;
use crate::utils::crypto;
use crate::utils::fmt::fmt_time;
use crate::utils::random::random_alphanumeric_with_len;
// Ext
use std::fs::OpenOptions;
use std::path::{Path, PathBuf};
use std::string::ToString;
use std::time::SystemTime;
/// BookmarksClient provides a layer between the host system and the bookmarks module
pub struct BookmarksClient {
@@ -370,15 +372,16 @@ impl BookmarksClient {
#[cfg(not(target_os = "macos"))] // CI/CD blocks
mod tests {
use std::thread::sleep;
use std::time::Duration;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
use super::*;
use crate::filetransfer::params::{AwsS3Params, GenericProtocolParams};
use crate::filetransfer::{FileTransferProtocol, ProtocolParams};
use pretty_assertions::assert_eq;
use std::thread::sleep;
use std::time::Duration;
use tempfile::TempDir;
#[test]
fn test_system_bookmarks_new() {

View File

@@ -3,12 +3,6 @@
//! `config_client` is the module which provides an API between the Config module and the system
// Locals
use crate::config::{
params::{UserConfig, DEFAULT_NOTIFICATION_TRANSFER_THRESHOLD},
serialization::{deserialize, serialize, SerializerError, SerializerErrorKind},
};
use crate::explorer::GroupDirs;
use crate::filetransfer::FileTransferProtocol;
// Ext
use std::fs::{create_dir, remove_file, File, OpenOptions};
use std::io::Write;
@@ -16,6 +10,11 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::string::ToString;
use crate::config::params::{UserConfig, DEFAULT_NOTIFICATION_TRANSFER_THRESHOLD};
use crate::config::serialization::{deserialize, serialize, SerializerError, SerializerErrorKind};
use crate::explorer::GroupDirs;
use crate::filetransfer::FileTransferProtocol;
// Types
pub type SshHost = (String, String, PathBuf); // 0: host, 1: username, 2: RSA key path
@@ -414,14 +413,15 @@ impl ConfigClient {
#[cfg(test)]
mod tests {
use std::io::Read;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
use super::*;
use crate::config::UserConfig;
use crate::utils::random::random_alphanumeric_with_len;
use pretty_assertions::assert_eq;
use std::io::Read;
use tempfile::TempDir;
#[test]
fn test_system_config_new() {
let tmp_dir: TempDir = TempDir::new().ok().unwrap();

View File

@@ -101,12 +101,13 @@ pub fn get_theme_path(config_dir: &Path) -> PathBuf {
#[cfg(test)]
mod tests {
use super::*;
use std::fs::{File, OpenOptions};
use std::io::Write;
use pretty_assertions::assert_eq;
use serial_test::serial;
use std::fs::{File, OpenOptions};
use std::io::Write;
use super::*;
#[test]
#[serial]

View File

@@ -3,12 +3,13 @@
//! `filestorage` provides an implementation of the `KeyStorage` trait using a file
// Local
use super::{KeyStorage, KeyStorageError};
// Ext
use std::fs::{OpenOptions, Permissions};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use super::{KeyStorage, KeyStorageError};
/// File storage is an implementation o the `KeyStorage` which uses a file to store the key
pub struct FileStorage {
dir_path: PathBuf,
@@ -90,10 +91,10 @@ impl KeyStorage for FileStorage {
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_system_keys_filestorage_make_dir() {
let storage: FileStorage = FileStorage::new(Path::new("/tmp/"));

View File

@@ -3,10 +3,11 @@
//! `keyringstorage` provides an implementation of the `KeyStorage` trait using the OS keyring
// Local
use super::{KeyStorage, KeyStorageError};
// Ext
use keyring::{Entry as Keyring, Error as KeyringError};
use super::{KeyStorage, KeyStorageError};
/// provides a `KeyStorage` implementation using the keyring crate
pub struct KeyringStorage {
username: String,
@@ -75,11 +76,11 @@ impl KeyStorage for KeyringStorage {
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use whoami::username;
use super::*;
#[test]
fn test_system_keys_keyringstorage() {
let username: String = username();

View File

@@ -7,10 +7,9 @@ pub mod filestorage;
#[cfg(feature = "with-keyring")]
pub mod keyringstorage;
// ext
use thiserror::Error;
#[cfg(feature = "with-keyring")]
use keyring::Error as KeyringError;
use thiserror::Error;
/// defines the error type for the `KeyStorage`
#[derive(Debug, Error)]
@@ -53,10 +52,10 @@ pub trait KeyStorage {
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_system_keys_mod_errors() {
#[cfg(feature = "with-keyring")]

View File

@@ -2,11 +2,12 @@
//!
//! `logging` is the module which initializes the logging system for termscp
use super::environment::{get_log_paths, init_cache_dir};
use crate::utils::file::open_file;
pub use simplelog::LevelFilter as LogLevel;
use simplelog::{ConfigBuilder, WriteLogger};
use super::environment::{get_log_paths, init_cache_dir};
use crate::utils::file::open_file;
/// Initialize logger
pub fn init(level: LogLevel) -> Result<(), String> {
// Init cache dir

View File

@@ -3,12 +3,14 @@
//! `SshKeyStorage` is the module which behaves a storage for ssh keys
// Locals
use super::config_client::ConfigClient;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
// Ext
use remotefs_ssh::SshKeyStorage as SshKeyStorageTrait;
use ssh2_config::SshConfig;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use super::config_client::ConfigClient;
#[derive(Default)]
pub struct SshKeyStorage {
@@ -117,13 +119,14 @@ impl From<&ConfigClient> for SshKeyStorage {
#[cfg(test)]
mod tests {
use std::path::Path;
use pretty_assertions::assert_eq;
use super::*;
use crate::system::config_client::ConfigClient;
use crate::utils::test_helpers;
use pretty_assertions::assert_eq;
use std::path::Path;
#[test]
fn test_system_sshkey_storage_new() {
let tmp_dir: tempfile::TempDir = tempfile::TempDir::new().ok().unwrap();

View File

@@ -3,15 +3,14 @@
//! `theme_provider` is the module which provides an API between the theme configuration and the system
// Locals
use crate::config::{
serialization::{deserialize, serialize, SerializerError, SerializerErrorKind},
themes::Theme,
};
// Ext
use std::fs::OpenOptions;
use std::path::{Path, PathBuf};
use std::string::ToString;
use crate::config::serialization::{deserialize, serialize, SerializerError, SerializerErrorKind};
use crate::config::themes::Theme;
/// ThemeProvider provides a high level API to communicate with the termscp theme
pub struct ThemeProvider {
theme: Theme, // Theme loaded
@@ -142,12 +141,12 @@ impl ThemeProvider {
#[cfg(test)]
mod test {
use super::*;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
use tuirealm::tui::style::Color;
use super::*;
#[test]
fn test_system_theme_provider_new() {
let tmp_dir: tempfile::TempDir = TempDir::new().ok().unwrap();

View File

@@ -2,10 +2,10 @@
//!
//! this module exposes the types to describe a change to sync on the remote file system
use crate::utils::path as path_utils;
use std::path::{Path, PathBuf};
use crate::utils::path as path_utils;
/// Describes an operation on the remote file system to sync
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum FsChange {
@@ -190,10 +190,10 @@ fn remote_relative_path(
#[cfg(test)]
mod test {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn should_get_remote_relative_path_from_subdir() {
assert_eq!(

View File

@@ -5,19 +5,19 @@
mod change;
// -- export
pub use change::FsChange;
use crate::utils::path as path_utils;
use notify::{
watcher, DebouncedEvent, Error as WatcherError, RecommendedWatcher, RecursiveMode, Watcher,
};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError};
use std::time::Duration;
pub use change::FsChange;
use notify::{
watcher, DebouncedEvent, Error as WatcherError, RecommendedWatcher, RecursiveMode, Watcher,
};
use thiserror::Error;
use crate::utils::path as path_utils;
type FsWatcherResult<T> = Result<T, FsWatcherError>;
/// Describes an error returned by the `FsWatcher`
@@ -172,14 +172,13 @@ impl FsWatcher {
#[cfg(test)]
mod test {
use super::*;
#[cfg(target_os = "macos")]
use crate::utils::test_helpers;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
use super::*;
#[cfg(target_os = "macos")]
use crate::utils::test_helpers;
#[test]
fn should_init_fswatcher() {
let watcher = FsWatcher::init(Duration::from_secs(5)).unwrap();