diff --git a/src/cmd_backup.rs b/src/cmd_backup.rs index 9d5e3aa..0809a78 100644 --- a/src/cmd_backup.rs +++ b/src/cmd_backup.rs @@ -89,10 +89,70 @@ fn new_backup( #[cfg(test)] mod test { + use std::path::{Component, PathBuf}; + use anyhow::Result; + + use crate::{ + cmd_args::BackupAddCommands, + devices::Device, + storages::{online_storage::OnlineStorage, Storage, Storages}, + }; + + use super::new_backup; #[test] fn test_new_backup() -> Result<()> { - todo!() + let device = Device::new("dev".to_string()); + let storage1 = Storage::Online(OnlineStorage::new( + "online".to_string(), + "provider".to_string(), + 1_000_000_000, + "alias".to_string(), + PathBuf::new() + .join(Component::RootDir) + .join("mnt") + .join("sample"), + &device, + )); + let storage2 = Storage::Online(OnlineStorage::new( + "online2".to_string(), + "provider".to_string(), + 1_000_000_000, + "alias".to_string(), + PathBuf::new() + .join(Component::RootDir) + .join("mnt") + .join("different"), + &device, + )); + let mut storages = Storages::new(); + storages.add(storage1)?; + storages.add(storage2)?; + let cmd = BackupAddCommands::External { + name: "sampple_backup".to_string(), + note: "This is jus.to_string()t for test.".to_string(), + }; + let backup = new_backup( + "new backup".to_string(), + PathBuf::new() + .join(Component::RootDir) + .join("mnt") + .join("sample") + .join("docs"), + PathBuf::new() + .join(Component::RootDir) + .join("mnt") + .join("sample") + .join("tmp"), + cmd, + &device, + &storages, + )?; + assert!(backup.source().storage == "online"); + assert_eq!(backup.source().path, PathBuf::from("docs")); + assert!(backup.destination().storage == "online"); + assert!(backup.destination().path == PathBuf::from("tmp")); + Ok(()) } } diff --git a/src/devices.rs b/src/devices.rs index d93b73c..6a93f7b 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -23,6 +23,7 @@ pub struct Device { impl Device { /// Create new `Device` of name `name`. Additional data is obtained via sysinfo. + /// Filling fields which one failed to get is filled with "unknown". pub fn new(name: String) -> Device { let sys = System::new(); Device {