diff --git a/src/lib.rs b/src/lib.rs index 9c045db..d7ba937 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,28 +61,65 @@ pub mod meta_next { #[cfg(test)] mod tests { + use util::{file_exists, get_full_path}; + use super::*; + mod util { + pub fn get_full_path( + directory: &String, + filename: &String, + ) -> Result { + match path_buf(directory, filename) { + Ok(pf) => Ok(pf.display().to_string()), + Err(err) => Err(err), + } + } + + pub fn file_exists(directory: &String, filename: &String) -> Result { + match path_buf(directory, filename) { + Ok(pf) => Ok(pf.exists()), + Err(err) => Err(err), + } + } + + fn path_buf( + directory: &String, + filename: &String, + ) -> Result { + let dir_path = std::path::Path::new(&directory); + Ok(dir_path.join(filename)) + } + } + #[test] fn test_get_title() { let filename = String::from("track01.flac"); let dir = String::from("tests/sample_tracks3"); - let dir_path = std::path::Path::new(&dir); - let full_path = dir_path.join(filename); + // let dir_path = std::path::Path::new(&dir); + // let full_path = dir_path.join(filename); - println!("Path: {:?}", full_path); + // println!("Path: {:?}", full_path); - assert!(full_path.exists(), "Path does not exists {:?}", full_path); - let filepath = full_path.display().to_string(); + // assert!(full_path.exists(), "Path does not exists {:?}", full_path); + match file_exists(&dir, &filename) { + Ok(_) => { + // let filepath = full_path.display().to_string(); + let filepath = get_full_path(&dir, &filename).unwrap(); - match meta_next::get_meta(meta_type::Type::Title, &filepath) { - Ok(title) => { - let found = title == "Just roll it"; - assert!(found, "Meta information was not found {:?}", title); + match meta_next::get_meta(meta_type::Type::Title, &filepath) { + Ok(title) => { + let found = title == "Just roll it"; + assert!(found, "Meta information was not found {:?}", title); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } } Err(err) => { - assert!(false, "Error: {:?}", err); + assert!(false, "Error: File does not exist {:?}", err.to_string()); } - } + }; } }