From 62b8bdd46b0db05e74d278d0236249b7cc9b46cb Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 14 Apr 2025 20:58:06 -0400 Subject: [PATCH 1/7] Added dependency --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 60c2c90..a68cd0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,6 @@ rust-version = "1.86" [dependencies] lofty = { version = "0.22.3" } icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.3" } + +[dev-dependencies] +tempfile = { version = "3.19.1" } \ No newline at end of file -- 2.43.0 From 583ea6846fbfdabc41f4f301495e858e168e664a Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 14 Apr 2025 21:21:45 -0400 Subject: [PATCH 2/7] Filled out function Add tests --- src/meta.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/meta.rs b/src/meta.rs index c015c10..4d8a59a 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -1,4 +1,4 @@ -use lofty::file::AudioFile; +use lofty::{file::AudioFile, tag::Accessor}; use crate::types; @@ -46,6 +46,61 @@ pub fn get_meta(t: types::Type, filepath: &String) -> Result Result { + match std::fs::File::open(filepath) { + Ok(mut content) => { + match lofty::flac::FlacFile::read_from(&mut content, lofty::config::ParseOptions::new()) + { + Ok(mut flac_file) => match flac_file.vorbis_comments_mut() { + Some(vb) => { + match t { + types::Type::Album => { + vb.set_album(value.clone()); + } + types::Type::AlbumArtist => { + vb.insert(get_type(t).unwrap(), value.clone()); + } + types::Type::Artist => { + vb.set_artist(value.clone()); + } + types::Type::Date => { + vb.insert(get_type(t).unwrap(), value.clone()); + } + types::Type::Disc => { + vb.set_disk(value.clone().parse().unwrap()); + } + types::Type::Genre => { + vb.set_genre(value.clone()); + } + types::Type::Title => { + vb.set_title(value.clone()); + } + types::Type::Track => { + vb.set_track(value.clone().parse().unwrap()); + } + }; + + Ok(value.clone()) + } + None => Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, + "No tags found", + )), + }, + Err(err) => Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, + err.to_string(), + )), + } + } + Err(err) => Err(err), + } +} + #[cfg(test)] mod tests { use util::{file_exists, get_full_path}; -- 2.43.0 From cae296f484754b1e33a3edde61cca6ae17fd5dda Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 14 Apr 2025 21:30:17 -0400 Subject: [PATCH 3/7] Fixing warnings --- src/meta.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/meta.rs b/src/meta.rs index 4d8a59a..182cad9 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -57,34 +57,35 @@ pub fn set_meta( { Ok(mut flac_file) => match flac_file.vorbis_comments_mut() { Some(vb) => { + let pre_value = value.clone(); match t { types::Type::Album => { - vb.set_album(value.clone()); + vb.set_album(pre_value); } types::Type::AlbumArtist => { - vb.insert(get_type(t).unwrap(), value.clone()); + vb.insert(get_type(t).unwrap(), pre_value); } types::Type::Artist => { - vb.set_artist(value.clone()); + vb.set_artist(pre_value); } types::Type::Date => { - vb.insert(get_type(t).unwrap(), value.clone()); + vb.insert(get_type(t).unwrap(), pre_value); } types::Type::Disc => { - vb.set_disk(value.clone().parse().unwrap()); + vb.set_disk(pre_value.parse().unwrap()); } types::Type::Genre => { - vb.set_genre(value.clone()); + vb.set_genre(pre_value); } types::Type::Title => { - vb.set_title(value.clone()); + vb.set_title(pre_value); } types::Type::Track => { - vb.set_track(value.clone().parse().unwrap()); + vb.set_track(pre_value.parse().unwrap()); } }; - Ok(value.clone()) + Ok(value.to_owned()) } None => Err(std::io::Error::new( std::io::ErrorKind::InvalidData, -- 2.43.0 From 9a293cdb7f1b4fd08102f4cd7e64ea87911d1f61 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Apr 2025 21:43:25 -0400 Subject: [PATCH 4/7] Got it working --- src/meta.rs | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/meta.rs b/src/meta.rs index 182cad9..50840a7 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -119,6 +119,23 @@ mod tests { } } + pub fn copy_file( + source_path: &String, + destination_path: &String, + ) -> Result { + println!("Copying file"); + let src_path = std::path::Path::new(source_path); + let dest_path = std::path::Path::new(destination_path); + + println!("Src: {:?}", src_path); + println!("Dest: {:?}", dest_path); + + match std::fs::copy(src_path, dest_path) { + Ok(bytes) => Ok(bytes), + Err(err) => Err(err), + } + } + pub fn file_exists(directory: &String, filename: &String) -> Result { match path_buf(directory, filename) { Ok(pf) => Ok(pf.exists()), @@ -350,4 +367,62 @@ mod tests { } }; } + + mod set { + use super::*; + + #[test] + fn test_set_title() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); + + let temp_file = tempfile::tempdir().expect("Could not create test directory"); + let mut test_dir = String::from(temp_file.path().to_str().unwrap()); + // test_dir = String::from("tests/sample_tracks3"); + let test_filename = String::from("track08.flac"); + let new_filepath = test_dir + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::Title, &filepath) { + Ok(title) => { + let found = title == "Just roll it"; + assert!(found, "Meta information was not found {:?}", title); + let new_title = String::from("The wind burned her"); + + match set_meta(types::Type::Title, &new_filepath, &new_title) { + Ok(m) => { + assert_eq!( + new_title, m, + "New title does not match {:?}", + m + ); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + } } -- 2.43.0 From c463bb3fb424e5f5df723e5222c947bb5b3fa5a2 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Apr 2025 22:01:30 -0400 Subject: [PATCH 5/7] Added tests --- src/meta.rs | 365 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 363 insertions(+), 2 deletions(-) diff --git a/src/meta.rs b/src/meta.rs index 50840a7..29a1fa2 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -377,8 +377,7 @@ mod tests { let dir = String::from(util::TESTFILEDIRECTORY); let temp_file = tempfile::tempdir().expect("Could not create test directory"); - let mut test_dir = String::from(temp_file.path().to_str().unwrap()); - // test_dir = String::from("tests/sample_tracks3"); + let test_dir = String::from(temp_file.path().to_str().unwrap()); let test_filename = String::from("track08.flac"); let new_filepath = test_dir + "/" + &test_filename; @@ -424,5 +423,367 @@ mod tests { } }; } + + #[test] + fn test_set_artist() { + 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 + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::Artist, &filepath) { + Ok(artist) => { + let found = artist == "KD"; + assert!(found, "Meta information was not found {:?}", artist); + let new_artist = String::from("Pilot"); + + match set_meta(types::Type::Artist, &new_filepath, &new_artist) { + Ok(m) => { + assert_eq!( + new_artist, m, + "New artist does not match {:?}", + m + ); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + + #[test] + fn test_set_album() { + 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 + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::Album, &filepath) { + Ok(title) => { + let found = title == "Sample Tracks 3"; + assert!(found, "Meta information was not found {:?}", title); + let new_album = String::from("Sample Tracks 3 Remastered"); + + match set_meta(types::Type::Album, &new_filepath, &new_album) { + Ok(m) => { + assert_eq!( + new_album, m, + "New album does not match {:?}", + m + ); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + #[test] + fn test_set_album_artist() { + 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 + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::AlbumArtist, &filepath) { + Ok(album_artist) => { + let found = album_artist == "KD"; + assert!(found, "Meta information was not found {:?}", album_artist); + let new_album_artist = String::from("Bob"); + + match set_meta( + types::Type::AlbumArtist, + &new_filepath, + &new_album_artist, + ) { + Ok(m) => { + assert_eq!( + new_album_artist, m, + "New album artist does not match {:?}", + m + ); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + #[test] + fn test_set_date() { + 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 + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::Date, &filepath) { + Ok(date) => { + let found = date == "2025-04-11"; + assert!(found, "Meta information was not found {:?}", date); + let new_date = String::from("2025-02-01"); + + match set_meta(types::Type::Date, &new_filepath, &new_date) { + Ok(m) => { + assert_eq!(new_date, m, "New date does not match {:?}", m); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + #[test] + fn test_set_track() { + 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 + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::Track, &filepath) { + Ok(track) => { + let found = track == "1"; + assert!(found, "Meta information was not found {:?}", track); + let new_track = String::from("5"); + + match set_meta(types::Type::Track, &new_filepath, &new_track) { + Ok(m) => { + assert_eq!( + new_track, m, + "New track does not match {:?}", + m + ); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + #[test] + fn test_set_disc() { + 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 + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::Disc, &filepath) { + Ok(disc) => { + let found = disc == "1"; + assert!(found, "Meta information was not found {:?}", disc); + let new_disc = String::from("2"); + + match set_meta(types::Type::Disc, &new_filepath, &new_disc) { + Ok(m) => { + assert_eq!(new_disc, m, "New disc does not match {:?}", m); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + #[test] + fn test_set_genre() { + 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 + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::Genre, &filepath) { + Ok(genre) => { + let found = genre == "Metal"; + assert!(found, "Meta information was not found {:?}", genre); + let new_genre = String::from("Blues"); + + match set_meta(types::Type::Genre, &new_filepath, &new_genre) { + Ok(m) => { + assert_eq!( + new_genre, m, + "New genre does not match {:?}", + m + ); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } } } -- 2.43.0 From 9db6a4010abf9308606f2fb8fa062bb97a5930b0 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Apr 2025 22:03:19 -0400 Subject: [PATCH 6/7] Refactored tests --- src/meta.rs | 323 ++++++++++++++++++++++++++-------------------------- 1 file changed, 164 insertions(+), 159 deletions(-) diff --git a/src/meta.rs b/src/meta.rs index 29a1fa2..8d5bf80 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -169,203 +169,208 @@ mod tests { } } - #[test] - fn test_get_title() { - let filename = util::get_filename(1); - let dir = String::from(util::TESTFILEDIRECTORY); + mod get { + use super::*; + use crate::types; - match file_exists(&dir, &filename) { - Ok(_) => { - let filepath = get_full_path(&dir, &filename).unwrap(); + #[test] + fn test_get_title() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); - match get_meta(types::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); + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match get_meta(types::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: File does not exist {:?}", err.to_string()); - } - }; - } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } - #[test] - fn test_get_artist() { - let filename = util::get_filename(1); - let dir = String::from(util::TESTFILEDIRECTORY); + #[test] + fn test_get_artist() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); - match file_exists(&dir, &filename) { - Ok(_) => { - let filepath = get_full_path(&dir, &filename).unwrap(); + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); - match get_meta(types::Type::Artist, &filepath) { - Ok(artist) => { - let found = artist == "KD"; - assert!(found, "Meta information was not found {:?}", artist); - } - Err(err) => { - assert!(false, "Error: {:?}", err); + match get_meta(types::Type::Artist, &filepath) { + Ok(artist) => { + let found = artist == "KD"; + assert!(found, "Meta information was not found {:?}", artist); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } } } - } - Err(err) => { - assert!(false, "Error: File does not exist {:?}", err.to_string()); - } - }; - } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } - #[test] - fn test_get_album() { - let filename = util::get_filename(1); - let dir = String::from(util::TESTFILEDIRECTORY); + #[test] + fn test_get_album() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); - match file_exists(&dir, &filename) { - Ok(_) => { - let filepath = get_full_path(&dir, &filename).unwrap(); + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); - match get_meta(types::Type::Album, &filepath) { - Ok(album) => { - let found = album == "Sample Tracks 3"; - assert!(found, "Meta information was not found {:?}", album); - } - Err(err) => { - assert!(false, "Error: {:?}", err); + match get_meta(types::Type::Album, &filepath) { + Ok(album) => { + let found = album == "Sample Tracks 3"; + assert!(found, "Meta information was not found {:?}", album); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } } } - } - Err(err) => { - assert!(false, "Error: File does not exist {:?}", err.to_string()); - } - }; - } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } - #[test] - fn test_get_album_artist() { - let filename = util::get_filename(1); - let dir = String::from(util::TESTFILEDIRECTORY); + #[test] + fn test_get_album_artist() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); - match file_exists(&dir, &filename) { - Ok(_) => { - let filepath = get_full_path(&dir, &filename).unwrap(); + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); - match get_meta(types::Type::AlbumArtist, &filepath) { - Ok(album_artist) => { - let found = album_artist == "KD"; - assert!(found, "Meta information was not found {:?}", album_artist); - } - Err(err) => { - assert!(false, "Error: {:?}", err); + match get_meta(types::Type::AlbumArtist, &filepath) { + Ok(album_artist) => { + let found = album_artist == "KD"; + assert!(found, "Meta information was not found {:?}", album_artist); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } } } - } - Err(err) => { - assert!(false, "Error: File does not exist {:?}", err.to_string()); - } - }; - } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } - #[test] - fn test_get_genre() { - let filename = util::get_filename(1); - let dir = String::from(util::TESTFILEDIRECTORY); + #[test] + fn test_get_genre() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); - match file_exists(&dir, &filename) { - Ok(_) => { - let filepath = get_full_path(&dir, &filename).unwrap(); + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); - match get_meta(types::Type::Genre, &filepath) { - Ok(genre) => { - let found = genre == "Metal"; - assert!(found, "Meta information was not found {:?}", genre); - } - Err(err) => { - assert!(false, "Error: {:?}", err); + match get_meta(types::Type::Genre, &filepath) { + Ok(genre) => { + let found = genre == "Metal"; + assert!(found, "Meta information was not found {:?}", genre); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } } } - } - Err(err) => { - assert!(false, "Error: File does not exist {:?}", err.to_string()); - } - }; - } - #[test] - fn test_get_year() { - let filename = util::get_filename(1); - let dir = String::from(util::TESTFILEDIRECTORY); + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + #[test] + fn test_get_year() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); - match file_exists(&dir, &filename) { - Ok(_) => { - let filepath = get_full_path(&dir, &filename).unwrap(); + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); - match get_meta(types::Type::Date, &filepath) { - Ok(date) => { - let found = date == "2025-04-11"; - assert!(found, "Meta information was not found {:?}", date); - } - Err(err) => { - assert!(false, "Error: {:?}", err); + match get_meta(types::Type::Date, &filepath) { + Ok(date) => { + let found = date == "2025-04-11"; + assert!(found, "Meta information was not found {:?}", date); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } } } - } - Err(err) => { - assert!(false, "Error: File does not exist {:?}", err.to_string()); - } - }; - } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } - #[test] - fn test_get_track() { - let filename = util::get_filename(1); - let dir = String::from(util::TESTFILEDIRECTORY); + #[test] + fn test_get_track() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); - match file_exists(&dir, &filename) { - Ok(_) => { - let filepath = get_full_path(&dir, &filename).unwrap(); + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); - match get_meta(types::Type::Track, &filepath) { - Ok(track) => { - let found = track == "1"; - assert!(found, "Meta information was not found {:?}", track); - } - Err(err) => { - assert!(false, "Error: {:?}", err); + match get_meta(types::Type::Track, &filepath) { + Ok(track) => { + let found = track == "1"; + assert!(found, "Meta information was not found {:?}", track); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } } } - } - Err(err) => { - assert!(false, "Error: File does not exist {:?}", err.to_string()); - } - }; - } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } - #[test] - fn test_get_disc() { - let filename = util::get_filename(1); - let dir = String::from(util::TESTFILEDIRECTORY); + #[test] + fn test_get_disc() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); - match file_exists(&dir, &filename) { - Ok(_) => { - let filepath = get_full_path(&dir, &filename).unwrap(); + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); - match get_meta(types::Type::Disc, &filepath) { - Ok(disc) => { - let found = disc == "1"; - assert!(found, "Meta information was not found {:?}", disc); - } - Err(err) => { - assert!(false, "Error: {:?}", err); + match get_meta(types::Type::Disc, &filepath) { + Ok(disc) => { + let found = disc == "1"; + assert!(found, "Meta information was not found {:?}", disc); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } } } - } - Err(err) => { - assert!(false, "Error: File does not exist {:?}", err.to_string()); - } - }; + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } } mod set { -- 2.43.0 From d3795c8277aa6f98a8156dd369a80076dd907183 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 15 Apr 2025 22:05:15 -0400 Subject: [PATCH 7/7] Removed println macros --- src/meta.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/meta.rs b/src/meta.rs index 8d5bf80..234ff50 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -123,13 +123,9 @@ mod tests { source_path: &String, destination_path: &String, ) -> Result { - println!("Copying file"); let src_path = std::path::Path::new(source_path); let dest_path = std::path::Path::new(destination_path); - println!("Src: {:?}", src_path); - println!("Dest: {:?}", dest_path); - match std::fs::copy(src_path, dest_path) { Ok(bytes) => Ok(bytes), Err(err) => Err(err), -- 2.43.0