in edgelet/edgelet-docker/src/image_prune_data.rs [548:621]
fn test_process_state() {
let (map1, map2) = process_state(
HashMap::new(),
HashSet::new(),
Duration::from_secs(60 * 60 * 24),
)
.unwrap();
assert!(map1.is_empty());
assert!(map2.is_empty());
let mut images_being_used: HashSet<String> = HashSet::new();
images_being_used.insert(
"sha256:670dcc86b69df89a9d5a9e1a7ae5b8f67619c1c74e19de8a35f57d6c06505fd4".to_string(),
);
images_being_used.insert(
"sha256:62aedd01bd8520c43d06b09f7a0f67ba9720bdc04631a8242c65ea995f3ecac8".to_string(),
);
images_being_used.insert(
"sha256:a4d112e0884bd2ba078ab8222e075bc656cc65cd433dfbb74d6de7cee188f2f2".to_string(),
);
images_being_used.insert(
"sha256:0884bd2ba078ab8222e075bc656cc65cd433dfbb74d6de7cee188f2f2a4d112e".to_string(),
);
images_being_used.insert(
"sha256:8222e075bc656cc65cd433dfbb74d6de7cee188f2f2a4d112e0884bd2ba078ab".to_string(),
);
let time = std::time::SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Could not get EPOCH time");
let mut all_iotedge_images: HashMap<String, Duration> = HashMap::new();
// currently used
all_iotedge_images.insert(
"sha256:670dcc86b69df89a9d5a9e1a7ae5b8f67619c1c74e19de8a35f57d6c06505fd4".to_string(),
time - Duration::from_secs(60 * 60 * 24),
);
all_iotedge_images.insert(
"sha256:62aedd01bd8520c43d06b09f7a0f67ba9720bdc04631a8242c65ea995f3ecac8".to_string(),
time - Duration::from_secs(60 * 60 * 24 * 5),
);
all_iotedge_images.insert(
"sha256:a4d112e0884bd2ba078ab8222e075bc656cc65cd433dfbb74d6de7cee188f2f2".to_string(),
time - Duration::from_secs(60 * 60 * 24 * 9),
);
// others
all_iotedge_images.insert(
"sha256:a40d3130a63918663f6e412178d2e83010994bb5a6bdb9ba314ca43013c05331".to_string(),
time - Duration::from_secs(60 * 60 * 12),
);
all_iotedge_images.insert(
"sha256:269d9943b0d310e1ab49a55e14752596567a74daa37270c6217abfc33f48f7f5".to_string(),
time - Duration::from_secs(60 * 60 * 24 * 12),
);
all_iotedge_images.insert(
"sha256:a1e6072c125f6102f410418ca0647841376982b460ab570916b01f264daf89af".to_string(),
time - Duration::from_secs(60 * 60 * 24 * 13),
);
all_iotedge_images.insert(
"sha256:a4d112e0884bd2ba078ab8222e075bc989cc65cd433dfbb74d6de7cee188g4g7".to_string(),
time - Duration::from_secs(60 * 60 * 24 * 8),
);
let (to_delete, carry_over) = process_state(
all_iotedge_images,
images_being_used,
Duration::from_secs(60 * 60 * 24),
)
.unwrap();
assert!(to_delete.len() == 3);
assert!(carry_over.len() == 4);
}