This commit is contained in:
2025-04-12 15:14:59 -04:00
parent e19e0bfe77
commit 8f2f88669d

View File

@@ -61,28 +61,65 @@ pub mod meta_next {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use util::{file_exists, get_full_path};
use super::*; use super::*;
mod util {
pub fn get_full_path(
directory: &String,
filename: &String,
) -> Result<String, std::io::Error> {
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<bool, std::io::Error> {
match path_buf(directory, filename) {
Ok(pf) => Ok(pf.exists()),
Err(err) => Err(err),
}
}
fn path_buf(
directory: &String,
filename: &String,
) -> Result<std::path::PathBuf, std::io::Error> {
let dir_path = std::path::Path::new(&directory);
Ok(dir_path.join(filename))
}
}
#[test] #[test]
fn test_get_title() { fn test_get_title() {
let filename = String::from("track01.flac"); let filename = String::from("track01.flac");
let dir = String::from("tests/sample_tracks3"); let dir = String::from("tests/sample_tracks3");
let dir_path = std::path::Path::new(&dir); // let dir_path = std::path::Path::new(&dir);
let full_path = dir_path.join(filename); // 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); // assert!(full_path.exists(), "Path does not exists {:?}", full_path);
let filepath = full_path.display().to_string(); 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) { match meta_next::get_meta(meta_type::Type::Title, &filepath) {
Ok(title) => { Ok(title) => {
let found = title == "Just roll it"; let found = title == "Just roll it";
assert!(found, "Meta information was not found {:?}", title); assert!(found, "Meta information was not found {:?}", title);
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
} }
Err(err) => { Err(err) => {
assert!(false, "Error: {:?}", err); assert!(false, "Error: File does not exist {:?}", err.to_string());
} }
} };
} }
} }