Error out if trying to extract images from a file without any

This commit is contained in:
Andrew Radev 2019-02-24 17:13:28 +02:00
parent f00d77d99b
commit ebc459f96a
2 changed files with 18 additions and 2 deletions

View File

@ -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(())
} else {
Err("No image found in music file".into())
}
}
pub fn remove_images(music_filename: &Path) -> Result<(), Box<Error>> {

View File

@ -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());
}