mirror of
https://github.com/agersant/polaris
synced 2024-12-11 13:56:24 +00:00
Added basic unit test
This commit is contained in:
parent
6c81cad85e
commit
96d12c7517
1 changed files with 26 additions and 2 deletions
28
src/vfs.rs
28
src/vfs.rs
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in a new issue