Added test to set picture
Some checks failed
Rust Build / Check (pull_request) Successful in 34s
Rust Build / Test Suite (pull_request) Failing after 51s
Rust Build / Rustfmt (pull_request) Successful in 39s
Rust Build / Clippy (pull_request) Successful in 52s
Rust Build / build (pull_request) Successful in 55s

This commit is contained in:
2025-04-17 20:28:49 -04:00
parent 709b39081b
commit 088388ee0d

View File

@@ -37,8 +37,9 @@ pub mod coverart {
Ok(pic) => {
match lofty::picture::PictureInformation::from_picture(&pic) {
Ok(info) => {
flac_file.set_picture(0, pic, info);
Ok(Vec::new())
flac_file.set_picture(0, pic.clone(), info);
Ok(pic.into_data())
// Ok(Vec::new())
}
Err(err) => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
@@ -934,5 +935,58 @@ mod tests {
}
};
}
#[test]
fn test_set_picture() {
let filename = util::get_filename(1);
let dir = String::from(util::TESTFILEDIRECTORY);
let temp_file = tempfile::tempdir().expect("Could not create test directory");
let test_dir = String::from(temp_file.path().to_str().unwrap());
// let test_filename = String::from("track08.flac");
// let new_filepath = test_dir.clone() + "/" + &test_filename;
let new_coverart = String::from("Sample Tracks 3 - Other one.png");
let new_cover_art_path = get_full_path(&dir, &new_coverart).unwrap();
match file_exists(&dir, &filename) {
Ok(_) => {
let filepath = get_full_path(&dir, &filename).unwrap();
match coverart::set_coverart(&filepath, &new_cover_art_path) {
Ok(bytes) => {
assert_eq!(false, bytes.is_empty(), "This should not be empty");
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
/*
match coverart::get_coverart(&filepath) {
Ok(coverart) => {
let is_empty = coverart.is_empty();
assert_eq!(is_empty, false, "Should not be empty");
let mut new_coverart_path: String = test_dir.clone();
new_coverart_path += &String::from("/newcovvv.png");
let _ = util::save_bytes_to_file(&coverart, &new_coverart_path);
let created_file = std::path::Path::new(&new_coverart_path);
assert!(
created_file.exists(),
"Error: {:?} has not been created",
new_coverart_path
);
}
Err(err) => {
assert!(false, "Error: {:?}", err.to_string());
}
}
*/
}
Err(err) => {
assert!(false, "Error: File does not exist {:?}", err.to_string());
}
};
}
}
}