use revocatio::error::RevocatioError; use revocatio::{run, BackupResult, Config}; use crate::get_test_path; #[test] fn files_too_small() -> Result<(), RevocatioError> { let config = format!( "backups: - name: file-test options: kind: file path: \"{}\" file_format: file\\d min_size: 1024 ok_days: 100 ", get_test_path(&vec!["file-backups", "files-too-small"]) .to_str() .unwrap() ); let config: Config = serde_yaml::from_str(&config).unwrap(); let result = run(config)?; assert_eq!(1, result.len()); let result = result.get(0).unwrap(); assert_eq!("file-test", result.name); match &result.result { BackupResult::Success => assert!(false), BackupResult::Failure(msg) => assert_eq!("all matching files are too small", msg), } Ok(()) } #[test] fn files_too_old() -> Result<(), RevocatioError> { let config = format!( "backups: - name: file-test options: kind: file path: \"{}\" file_format: file\\d ok_days: 2 ok_days: 10 ", get_test_path(&vec!["file-backups", "files-too-old"]) .to_str() .unwrap() ); let config: Config = serde_yaml::from_str(&config).unwrap(); let result = run(config)?; assert_eq!(1, result.len()); let result = result.get(0).unwrap(); assert_eq!("file-test", result.name); match &result.result { BackupResult::Success => assert!(false), BackupResult::Failure(msg) => assert_eq!("all matching files are too old", msg), } Ok(()) } #[test] fn no_matching_files() -> Result<(), RevocatioError> { let config = format!( "backups: - name: file-test options: kind: file path: \"{}\" file_format: file\\d ok_days: 2 ok_days: 10 ", get_test_path(&vec!["file-backups", "no-matching"]) .to_str() .unwrap() ); let config: Config = serde_yaml::from_str(&config).unwrap(); let result = run(config)?; assert_eq!(1, result.len()); let result = result.get(0).unwrap(); assert_eq!("file-test", result.name); match &result.result { BackupResult::Success => assert!(false), BackupResult::Failure(msg) => assert_eq!("no files matched format", msg), } Ok(()) } #[test] fn only_large_enough_too_old() -> Result<(), RevocatioError> { let config = format!( "backups: - name: file-test options: kind: file path: \"{}\" file_format: file\\d ok_days: 4 min_size: 512 ok_days: 10 ", get_test_path(&vec!["file-backups", "large-enough-too-old"]) .to_str() .unwrap() ); let config: Config = serde_yaml::from_str(&config).unwrap(); let result = run(config)?; assert_eq!(1, result.len()); let result = result.get(0).unwrap(); assert_eq!("file-test", result.name); match &result.result { BackupResult::Success => assert!(false), BackupResult::Failure(msg) => assert_eq!("all matching files are too small", msg), } Ok(()) } #[test] fn working_check() -> Result<(), RevocatioError> { let config = format!( "backups: - name: file-test options: kind: file path: \"{}\" file_format: file\\d ok_days: 3 min_size: 1024 ok_days: 10 ", get_test_path(&vec!["file-backups", "working"]) .to_str() .unwrap() ); let config: Config = serde_yaml::from_str(&config).unwrap(); let result = run(config)?; assert_eq!(1, result.len()); let result = result.get(0).unwrap(); assert_eq!("file-test", result.name); match &result.result { BackupResult::Success => {} BackupResult::Failure(_) => assert!(false), } Ok(()) }