use anyhow::Error;
-use pbs_api_types::PruneOptions;
+use pbs_api_types::PruneJobOptions;
use pbs_datastore::manifest::MANIFEST_BLOB_NAME;
use pbs_datastore::prune::compute_prune_info;
use pbs_datastore::{BackupDir, BackupInfo};
fn get_prune_list(
list: Vec<BackupInfo>,
return_kept: bool,
- options: &PruneOptions,
+ options: &PruneJobOptions,
) -> Vec<PathBuf> {
let mut prune_info = compute_prune_info(list, options).unwrap();
eprintln!("{:?}", orig_list);
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_last = Some(1);
let remove_list = get_prune_list(orig_list.clone(), false, &options);
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-11-15T10:39:15Z")];
assert_eq!(remove_list, expect);
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_hourly = Some(1);
let remove_list = get_prune_list(orig_list.clone(), false, &options);
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-11-15T10:39:15Z")];
orig_list.push(create_info("host/elsa/2019-11-15T11:59:15Z", false));
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_hourly = Some(3);
let remove_list = get_prune_list(list, false, &options);
let expect: Vec<PathBuf> = vec![
assert_eq!(remove_list, expect);
let list = orig_list;
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_hourly = Some(2);
let remove_list = get_prune_list(list, true, &options);
let expect: Vec<PathBuf> = vec![
orig_list.push(create_info("host/elsa/2019-12-04T11:59:15Z", false));
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_daily = Some(1);
let remove_list = get_prune_list(list, true, &options);
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-12-04T11:59:15Z")];
assert_eq!(remove_list, expect);
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_last = Some(1);
options.keep_daily = Some(1);
let remove_list = get_prune_list(list, true, &options);
assert_eq!(remove_list, expect);
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_daily = Some(1);
options.keep_weekly = Some(1);
let remove_list = get_prune_list(list, true, &options);
assert_eq!(remove_list, expect);
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_daily = Some(1);
options.keep_weekly = Some(1);
options.keep_monthly = Some(1);
assert_eq!(remove_list, expect);
let list = orig_list;
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_monthly = Some(1);
options.keep_yearly = Some(1);
let remove_list = get_prune_list(list, true, &options);
// keep-last tests
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_last = Some(4);
let remove_list = get_prune_list(list, false, &options);
let expect: Vec<PathBuf> = Vec::new();
assert_eq!(remove_list, expect);
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_last = Some(3);
let remove_list = get_prune_list(list, false, &options);
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-12-02T11:59:15Z")];
assert_eq!(remove_list, expect);
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_last = Some(2);
let remove_list = get_prune_list(list, false, &options);
let expect: Vec<PathBuf> = vec![
assert_eq!(remove_list, expect);
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_last = Some(1);
let remove_list = get_prune_list(list, false, &options);
let expect: Vec<PathBuf> = vec![
assert_eq!(remove_list, expect);
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_last = Some(0);
let remove_list = get_prune_list(list, false, &options);
let expect: Vec<PathBuf> = vec![
// keep-last, keep-daily mixed
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_last = Some(2);
options.keep_daily = Some(2);
let remove_list = get_prune_list(list, false, &options);
// keep-daily test
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_daily = Some(3);
let remove_list = get_prune_list(list, false, &options);
let expect: Vec<PathBuf> = vec![PathBuf::from("host/elsa/2019-12-04T11:59:15Z")];
// keep-daily test
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_daily = Some(2);
let remove_list = get_prune_list(list, false, &options);
let expect: Vec<PathBuf> = vec![
// keep-weekly
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_weekly = Some(5);
let remove_list = get_prune_list(list, false, &options);
// all backup are within the same week, so we only keep a single file
// keep-daily + keep-weekly
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_daily = Some(1);
options.keep_weekly = Some(5);
let remove_list = get_prune_list(list, false, &options);
// keep-monthly
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_monthly = Some(6);
let remove_list = get_prune_list(list, false, &options);
// all backup are within the same month, so we only keep a single file
// keep-yearly
let list = orig_list.clone();
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_yearly = Some(7);
let remove_list = get_prune_list(list, false, &options);
// all backup are within the same year, so we only keep a single file
// keep-weekly + keep-monthly + keep-yearly
let list = orig_list;
- let mut options = PruneOptions::default();
+ let mut options = PruneJobOptions::default();
options.keep_weekly = Some(5);
options.keep_monthly = Some(6);
options.keep_yearly = Some(7);