Added basic unit test

This commit is contained in:
Antoine Gersant 2016-08-21 21:19:52 -07:00
parent 6c81cad85e
commit 96d12c7517

View file

@ -10,10 +10,9 @@ pub struct Vfs {
impl Vfs { impl Vfs {
pub fn new() -> Vfs { pub fn new() -> Vfs {
let mut instance = Vfs { let instance = Vfs {
mount_points: HashMap::new(), mount_points: HashMap::new(),
}; };
instance.mount( "root", Path::new("samplemusic") );
instance instance
} }
@ -51,3 +50,28 @@ impl Vfs {
Err(CollectionError::PathNotInVfs) Err(CollectionError::PathNotInVfs)
} }
} }
#[test]
fn test_mount() {
let mut vfs = Vfs::new();
assert!(vfs.mount("root", Path::new("test_dir")).is_ok());
assert!(vfs.mount("root", Path::new("another_dir")).is_err());
}
#[test]
fn test_virtual_to_real() {
let mut vfs = Vfs::new();
assert!(vfs.mount("root", Path::new("test_dir")).is_ok());
let correct_path = Path::new("test_dir/somewhere/something.png");
let found_path = vfs.virtual_to_real(Path::new("root/somewhere/something.png")).unwrap();
assert!(found_path == correct_path);
}
#[test]
fn test_real_to_virtual() {
let mut vfs = Vfs::new();
assert!(vfs.mount("root", Path::new("test_dir")).is_ok());
let correct_path = Path::new("root/somewhere/something.png");
let found_path = vfs.real_to_virtual(Path::new("test_dir/somewhere/something.png")).unwrap();
assert!(found_path == correct_path);
}