use revocatio::error::RevocatioError; use revocatio::{run, BackupResult, Config}; use crate::get_test_path; #[test] fn all_too_old() -> Result<(), RevocatioError> { // Note that we filter on the 'important-' prefix // The test repository is configured with an archive from // 1 day ago, but it doesn't have this prefix, // so we shouldn't find it let config = format!( "backups: - name: borg-test options: kind: borg glob: important-* password: \"\" path: \"{}\" ok_days: 2 ", get_test_path(&vec!["borg"]).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!("borg-test", result.name); match &result.result { BackupResult::Success => assert!(false), BackupResult::Failure(msg) => assert!(msg.starts_with("latest archive is from")), } Ok(()) } #[test] fn missing_repository() -> Result<(), RevocatioError> { let config = "backups: - name: borg-test options: kind: borg password: \"\" path: \"/this/path/dne\" ok_days: 3 "; let config: Config = serde_yaml::from_str(&config).unwrap(); let result = run(config)?; assert_eq!(1, result.len()); let result = result.get(0).unwrap(); match &result.result { BackupResult::Success => assert!(false), BackupResult::Failure(_) => {} } Ok(()) } #[test] fn working_check() -> Result<(), RevocatioError> { let config = format!( "backups: - name: borg-test options: kind: borg glob: important-* password: password path: \"{}\" ok_days: 4 ", get_test_path(&vec!["borg"]).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!("borg-test", result.name); match &result.result { BackupResult::Success => {} BackupResult::Failure(_) => assert!(false), } Ok(()) } #[test] fn working_without_glob() -> Result<(), RevocatioError> { let config = format!( "backups: - name: borg-test options: kind: borg password: password path: \"{}\" ok_days: 1 ", get_test_path(&vec!["borg"]).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!("borg-test", result.name); match &result.result { BackupResult::Success => {} BackupResult::Failure(_) => assert!(false), } Ok(()) }