use crate::{PathBoundary, VirtualRoot};
#[test]
fn test_path_boundary_root_helpers_read_and_remove() {
let tmp = tempfile::tempdir().unwrap();
let root_path = tmp.path().join("rootdir");
let test_dir: PathBoundary = PathBoundary::try_new_create(&root_path).unwrap();
let file = test_dir.strict_join("file.txt").unwrap();
file.write("x").unwrap();
let sub = test_dir.strict_join("sub").unwrap();
sub.create_dir_all().unwrap();
let mut names: Vec<String> = test_dir
.read_dir()
.unwrap()
.map(|e| e.unwrap().file_name().to_string_lossy().into_owned())
.collect();
names.sort();
assert_eq!(names, vec!["file.txt", "sub"]);
assert!(test_dir.remove_dir().is_err());
test_dir.remove_dir_all().unwrap();
assert!(!root_path.exists());
}
#[test]
fn test_virtual_root_root_helpers_read_and_remove() {
let tmp = tempfile::tempdir().unwrap();
let root_path = tmp.path().join("vrootdir");
let vroot: VirtualRoot = VirtualRoot::try_new_create(&root_path).unwrap();
let file = vroot.virtual_join("file.txt").unwrap();
file.write("y").unwrap();
let sub = vroot.virtual_join("sub").unwrap();
sub.create_dir_all().unwrap();
let mut names: Vec<String> = vroot
.read_dir()
.unwrap()
.map(|e| e.unwrap().file_name().to_string_lossy().into_owned())
.collect();
names.sort();
assert_eq!(names, vec!["file.txt", "sub"]);
assert!(vroot.remove_dir().is_err());
vroot.remove_dir_all().unwrap();
assert!(!root_path.exists());
}