From ebc459f96a8f827b87f52117e7c4cc4209c18e5d Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 24 Feb 2019 17:13:28 +0200 Subject: [PATCH] Error out if trying to extract images from a file without any --- src/lib.rs | 6 ++++-- tests/test_processing.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0024f99..e0e7497 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,9 +39,11 @@ pub fn extract_first_image(music_filename: &Path, image_filename: &Path) -> Resu }, Err(e) => return Err(format!("Couldn't load image: {}", e).into()), }; - } - Ok(()) + Ok(()) + } else { + Err("No image found in music file".into()) + } } pub fn remove_images(music_filename: &Path) -> Result<(), Box> { diff --git a/tests/test_processing.rs b/tests/test_processing.rs index 2c04c9a..1f1f647 100644 --- a/tests/test_processing.rs +++ b/tests/test_processing.rs @@ -163,3 +163,17 @@ fn test_overwriting_an_existing_image() { assert!(image.exists()); } + +#[test] +fn test_extracting_an_image_with_no_pictures() { + let song = Fixture::copy("attempt_1_no_image.mp3"); + let image = Fixture::blank("attempt_1.jpg"); + + let tag = read_tag(&song); + assert!(tag.pictures().count() == 0); + assert!(!image.exists()); + + assert!(extract_first_image(&song, &image).is_err()); + + assert!(!image.exists()); +}