From fa8643e73abc3c4678a7f12dd918c150bdd9ee1c Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 14:08:20 -0400 Subject: [PATCH 01/10] Added function to save song to the filesystem --- src/song.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/song.rs b/src/song.rs index 2fbd3d9..107e547 100644 --- a/src/song.rs +++ b/src/song.rs @@ -1,4 +1,4 @@ -use std::io::Read; +use std::io::{Read,Write}; use crate::constants; use crate::init; @@ -150,4 +150,27 @@ impl Song { filename } + + pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> { + match self.song_path() { + Ok(song_path) => { + match std::fs::File::create(&song_path) { + Ok(mut file) => { + match file.write_all(&self.data) { + Ok(_res) => { + Ok(()) + } + Err(err) => { + Err(err) + } + } + } + Err(err) => { + Err(err) + } + } + } + Err(err) => Err(err) + } + } } From 73c8fd2634df0b106d4101729d48dc04c2e2c842 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 14:17:32 -0400 Subject: [PATCH 02/10] Tweaked some changes --- src/song.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/song.rs b/src/song.rs index 107e547..25aef4d 100644 --- a/src/song.rs +++ b/src/song.rs @@ -90,6 +90,7 @@ impl Song { } } + // TODO: Make this available as a function pub fn to_data(&self) -> Result, std::io::Error> { let path_result = self.song_path(); @@ -109,6 +110,7 @@ impl Song { } } + // TODO: Make this available as a function pub fn generate_filename(&self, typ: types::MusicTypes, randomize: bool) -> String { let mut filename: String = String::new(); let filename_len = 10; From 0b53eb8208c94b5b98342e1f4947b4af952958f8 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 14:19:21 -0400 Subject: [PATCH 03/10] Added more todos --- src/coverart.rs | 3 +++ src/song.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/coverart.rs b/src/coverart.rs index 35c607b..edb5de4 100644 --- a/src/coverart.rs +++ b/src/coverart.rs @@ -37,6 +37,9 @@ impl CoverArt { Err(err) => Err(err), } } + + // TODO: Add method to save to filesystem + // TODO: Add method to remove from filesystem } #[cfg(test)] diff --git a/src/song.rs b/src/song.rs index 25aef4d..b5b5366 100644 --- a/src/song.rs +++ b/src/song.rs @@ -175,4 +175,6 @@ impl Song { Err(err) => Err(err) } } + + // TODO: Add function to remove file from the filesystem } From 16f633d56360f64c6c17802387fab90948d2489d Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 14:19:30 -0400 Subject: [PATCH 04/10] Added test --- tests/tests.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/tests.rs b/tests/tests.rs index f281ea7..b310f64 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -150,6 +150,42 @@ mod song_tests { } } } + + #[test] + fn test_save_song_to_filesystem() { + let mut song = song::Song::default(); + song.directory = utils::get_tests_directory(); + song.filename = String::from("track02.flac"); + + match song.song_path() { + Ok(song_path) => { + match utils::extract_data_from_file(&song_path) { + Ok(data) => { + let copied_song = song::Song { + directory: utils::get_tests_directory(), + filename: String::from("track02-coppied.flac"), + data: data, + ..Default::default() + }; + + match copied_song.save_to_filesystem() { + Ok(_) => { + } + Err(err) => { + assert!(false, "Error: {err:?}") + } + } + } + Err(err) => { + assert!(false, "Error: {err:?}") + } + } + } + Err(err) => { + assert!(false, "Error: {err:?}"); + } + } + } } #[cfg(test)] From 85d8f839f146d6fb9fb7622e05d1a12ff1c20b2c Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 14:19:45 -0400 Subject: [PATCH 05/10] Code formatting --- src/song.rs | 28 +++++++++------------------- tests/tests.rs | 35 ++++++++++++++++------------------- 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/song.rs b/src/song.rs index b5b5366..4034b7b 100644 --- a/src/song.rs +++ b/src/song.rs @@ -1,4 +1,4 @@ -use std::io::{Read,Write}; +use std::io::{Read, Write}; use crate::constants; use crate::init; @@ -155,24 +155,14 @@ impl Song { pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> { match self.song_path() { - Ok(song_path) => { - match std::fs::File::create(&song_path) { - Ok(mut file) => { - match file.write_all(&self.data) { - Ok(_res) => { - Ok(()) - } - Err(err) => { - Err(err) - } - } - } - Err(err) => { - Err(err) - } - } - } - Err(err) => Err(err) + Ok(song_path) => match std::fs::File::create(&song_path) { + Ok(mut file) => match file.write_all(&self.data) { + Ok(_res) => Ok(()), + Err(err) => Err(err), + }, + Err(err) => Err(err), + }, + Err(err) => Err(err), } } diff --git a/tests/tests.rs b/tests/tests.rs index b310f64..c6ae428 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -158,29 +158,26 @@ mod song_tests { song.filename = String::from("track02.flac"); match song.song_path() { - Ok(song_path) => { - match utils::extract_data_from_file(&song_path) { - Ok(data) => { - let copied_song = song::Song { - directory: utils::get_tests_directory(), - filename: String::from("track02-coppied.flac"), - data: data, - ..Default::default() - }; + Ok(song_path) => match utils::extract_data_from_file(&song_path) { + Ok(data) => { + let copied_song = song::Song { + directory: utils::get_tests_directory(), + filename: String::from("track02-coppied.flac"), + data: data, + ..Default::default() + }; - match copied_song.save_to_filesystem() { - Ok(_) => { - } - Err(err) => { - assert!(false, "Error: {err:?}") - } + match copied_song.save_to_filesystem() { + Ok(_) => {} + Err(err) => { + assert!(false, "Error: {err:?}") } } - Err(err) => { - assert!(false, "Error: {err:?}") - } } - } + Err(err) => { + assert!(false, "Error: {err:?}") + } + }, Err(err) => { assert!(false, "Error: {err:?}"); } From 9436c9033a2c0cd4bb168475be56a1fd82a85cad Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 14:23:23 -0400 Subject: [PATCH 06/10] Added todo --- src/song.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/song.rs b/src/song.rs index 4034b7b..7e56349 100644 --- a/src/song.rs +++ b/src/song.rs @@ -168,3 +168,5 @@ impl Song { // TODO: Add function to remove file from the filesystem } + +// TODO: Add function to copy song From 00cada74e29f15e289055fe89fe6bfca483fa137 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 18:53:13 +0000 Subject: [PATCH 07/10] Copy song (#61) Reviewed-on: https://git.kundeng.us/phoenix/icarus_models/pulls/61 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/song.rs | 40 ++++++++++++++++++++--- tests/tests.rs | 89 +++++++++++++------------------------------------- 4 files changed, 60 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3354901..4ac3d21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" [[package]] name = "icarus_models" -version = "0.5.6" +version = "0.6.0" dependencies = [ "josekit", "rand", diff --git a/Cargo.toml b/Cargo.toml index 3ddb8f5..122c8ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_models" -version = "0.5.6" +version = "0.6.0" edition = "2024" rust-version = "1.88" description = "models used for the icarus project" diff --git a/src/song.rs b/src/song.rs index 7e56349..a389f2b 100644 --- a/src/song.rs +++ b/src/song.rs @@ -1,12 +1,12 @@ use std::io::{Read, Write}; +use rand::Rng; +use serde::{Deserialize, Serialize}; + use crate::constants; use crate::init; use crate::types; -use rand::Rng; -use serde::{Deserialize, Serialize}; - #[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)] pub struct Song { #[serde(skip_serializing_if = "init::is_uuid_nil")] @@ -153,6 +153,7 @@ impl Song { filename } + /// Saves the song to the filesystem using the song's data pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> { match self.song_path() { Ok(song_path) => match std::fs::File::create(&song_path) { @@ -169,4 +170,35 @@ impl Song { // TODO: Add function to remove file from the filesystem } -// TODO: Add function to copy song +/// I/O operations for songs +pub mod io { + /// Copies a song using the source song's data + pub fn copy_song( + song_source: &super::Song, + song_target: &mut super::Song, + ) -> Result<(), std::io::Error> { + match song_target.song_path() { + Ok(songpath) => { + let p = std::path::Path::new(&songpath); + if p.exists() { + Err(std::io::Error::other( + "Cannot copy song over to one that already exists", + )) + } else { + if song_target.data.is_empty() { + song_target.data = song_source.data.clone(); + } else { + song_target.data.clear(); + song_target.data = song_source.data.clone(); + } + + match song_target.save_to_filesystem() { + Ok(_) => Ok(()), + Err(err) => Err(err), + } + } + } + Err(err) => Err(err), + } + } +} diff --git a/tests/tests.rs b/tests/tests.rs index c6ae428..7692afa 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -30,16 +30,12 @@ mod utils { #[cfg(test)] mod song_tests { - use std::fs::File; - use std::io::Write; - use tempfile::tempdir; + use crate::utils; use icarus_models::song; use icarus_models::types; - use crate::utils; - #[test] fn test_song_to_data() { println!("Test"); @@ -103,50 +99,22 @@ mod song_tests { song.directory = utils::get_tests_directory(); song.filename = String::from("track01.flac"); - match song.song_path() { - Ok(songpath) => match utils::extract_data_from_file(&songpath) { - Ok(buffer) => { - let mut song_cpy = song.clone(); - let temp_dir = tempdir().expect("Failed to create temp dir"); - song_cpy.directory = match temp_dir.path().to_str() { - Some(s) => String::from(s), - None => String::new(), - }; + let mut song_cpy = song.clone(); + let temp_dir = tempdir().expect("Failed to create temp dir"); + song_cpy.directory = match temp_dir.path().to_str() { + Some(s) => String::from(s), + None => String::new(), + }; - assert_eq!(song.directory.is_empty(), false); - song_cpy.filename = - song.generate_filename(types::MusicTypes::FlacExtension, true); - println!("Directory: {:?}", song_cpy.directory); - println!("File to be created: {:?}", song_cpy.filename); + assert_eq!(song.directory.is_empty(), false); + song_cpy.filename = song.generate_filename(types::MusicTypes::FlacExtension, true); + println!("Directory: {:?}", song_cpy.directory); + println!("File to be created: {:?}", song_cpy.filename); - let path = match song_cpy.song_path() { - Ok(s_path) => s_path, - Err(err) => { - assert!(false, "Error: {:?}", err); - String::new() - } - }; - - match File::create(path) { - Ok(mut file_cpy) => match file_cpy.write_all(&buffer) { - Ok(success) => { - println!("Success: {:?}", success); - } - Err(err) => { - assert!(false, "Error saving file: {:?}", err); - } - }, - Err(err) => { - assert!(false, "Error: {:?}", err); - } - }; - } - Err(err) => { - assert!(false, "Error: {:?}", err); - } - }, + match song::copy_song(&song, &mut song_cpy) { + Ok(_) => {} Err(err) => { - assert!(false, "Error extracting song data: {:?}", err); + assert!(false, "Error copying song: Error: {err:?}") } } } @@ -157,29 +125,16 @@ mod song_tests { song.directory = utils::get_tests_directory(); song.filename = String::from("track02.flac"); - match song.song_path() { - Ok(song_path) => match utils::extract_data_from_file(&song_path) { - Ok(data) => { - let copied_song = song::Song { - directory: utils::get_tests_directory(), - filename: String::from("track02-coppied.flac"), - data: data, - ..Default::default() - }; + let mut copied_song = song::Song { + directory: utils::get_tests_directory(), + filename: String::from("track02-coppied.flac"), + ..Default::default() + }; - match copied_song.save_to_filesystem() { - Ok(_) => {} - Err(err) => { - assert!(false, "Error: {err:?}") - } - } - } - Err(err) => { - assert!(false, "Error: {err:?}") - } - }, + match song::copy_song(&song, &mut copied_song) { + Ok(_) => {} Err(err) => { - assert!(false, "Error: {err:?}"); + assert!(false, "Error: {err:?}") } } } From d7c078d95aef64bce8e48dc7fc73b5d642735086 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 19:02:01 +0000 Subject: [PATCH 08/10] Song to_data change (#62) Reviewed-on: https://git.kundeng.us/phoenix/icarus_models/pulls/62 Co-authored-by: phoenix Co-committed-by: phoenix --- src/song.rs | 42 +++++++++++++++++++++--------------------- tests/tests.rs | 6 +++--- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/song.rs b/src/song.rs index a389f2b..f5488fe 100644 --- a/src/song.rs +++ b/src/song.rs @@ -1,4 +1,4 @@ -use std::io::{Read, Write}; +use std::io::Write; use rand::Rng; use serde::{Deserialize, Serialize}; @@ -90,26 +90,6 @@ impl Song { } } - // TODO: Make this available as a function - pub fn to_data(&self) -> Result, std::io::Error> { - let path_result = self.song_path(); - - match path_result { - Ok(path) => { - let mut file = std::fs::File::open(path)?; - let mut buffer: Vec = Vec::new(); - file.read_to_end(&mut buffer)?; - - if buffer.is_empty() { - Err(std::io::Error::other("File is empty")) - } else { - Ok(buffer) - } - } - Err(er) => Err(er), - } - } - // TODO: Make this available as a function pub fn generate_filename(&self, typ: types::MusicTypes, randomize: bool) -> String { let mut filename: String = String::new(); @@ -172,6 +152,8 @@ impl Song { /// I/O operations for songs pub mod io { + use std::io::Read; + /// Copies a song using the source song's data pub fn copy_song( song_source: &super::Song, @@ -201,4 +183,22 @@ pub mod io { Err(err) => Err(err), } } + + /// Gets the raw file data of a song from the filesystem + pub fn to_data(song: &super::Song) -> Result, std::io::Error> { + match song.song_path() { + Ok(path) => { + let mut file = std::fs::File::open(path)?; + let mut buffer: Vec = Vec::new(); + file.read_to_end(&mut buffer)?; + + if buffer.is_empty() { + Err(std::io::Error::other("File is empty")) + } else { + Ok(buffer) + } + } + Err(er) => Err(er), + } + } } diff --git a/tests/tests.rs b/tests/tests.rs index 7692afa..d0a04df 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -61,7 +61,7 @@ mod song_tests { Ok(buffer) => { assert_eq!(buffer.is_empty(), false); - match song.to_data() { + match song::io::to_data(&song) { Ok(song_data) => { println!("Both files match"); assert_eq!(buffer, song_data); @@ -111,7 +111,7 @@ mod song_tests { println!("Directory: {:?}", song_cpy.directory); println!("File to be created: {:?}", song_cpy.filename); - match song::copy_song(&song, &mut song_cpy) { + match song::io::copy_song(&song, &mut song_cpy) { Ok(_) => {} Err(err) => { assert!(false, "Error copying song: Error: {err:?}") @@ -131,7 +131,7 @@ mod song_tests { ..Default::default() }; - match song::copy_song(&song, &mut copied_song) { + match song::io::copy_song(&song, &mut copied_song) { Ok(_) => {} Err(err) => { assert!(false, "Error: {err:?}") From 0637a9432e9f7148a7c77d1e00a24a6d6682d040 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 19:20:57 +0000 Subject: [PATCH 09/10] Changes to how song filenames are generated (#63) Reviewed-on: https://git.kundeng.us/phoenix/icarus_models/pulls/63 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/song.rs | 83 +++++++++++++++++++++++++------------------------- tests/tests.rs | 2 +- 4 files changed, 44 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ac3d21..89c15e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" [[package]] name = "icarus_models" -version = "0.6.0" +version = "0.6.2" dependencies = [ "josekit", "rand", diff --git a/Cargo.toml b/Cargo.toml index 122c8ac..16eb4de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_models" -version = "0.6.0" +version = "0.6.2" edition = "2024" rust-version = "1.88" description = "models used for the icarus project" diff --git a/src/song.rs b/src/song.rs index f5488fe..5735ee6 100644 --- a/src/song.rs +++ b/src/song.rs @@ -7,6 +7,8 @@ use crate::constants; use crate::init; use crate::types; +const FILENAME_LENGTH: i32 = 16; + #[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)] pub struct Song { #[serde(skip_serializing_if = "init::is_uuid_nil")] @@ -90,48 +92,6 @@ impl Song { } } - // TODO: Make this available as a function - pub fn generate_filename(&self, typ: types::MusicTypes, randomize: bool) -> String { - let mut filename: String = String::new(); - let filename_len = 10; - - let file_extension = match typ { - types::MusicTypes::DefaultMusicExtension => { - String::from(constants::file_extensions::audio::DEFAULTMUSICEXTENSION) - } - - types::MusicTypes::WavExtension => { - String::from(constants::file_extensions::audio::WAVEXTENSION) - } - types::MusicTypes::FlacExtension => { - String::from(constants::file_extensions::audio::FLACEXTENSION) - } - types::MusicTypes::MPThreeExtension => { - String::from(constants::file_extensions::audio::MPTHREEEXTENSION) - } - }; - - if randomize { - let some_chars: String = String::from("abcdefghij0123456789"); - let mut rng = rand::rng(); - - for _i in 0..filename_len { - let random_number: i32 = rng.random_range(0..=19); - let index = random_number as usize; - let rando_char = some_chars.chars().nth(index); - - if let Some(c) = rando_char { - filename.push(c); - } - } - } else { - filename += "track-output"; - } - - filename += &file_extension; - - filename - } /// Saves the song to the filesystem using the song's data pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> { @@ -150,6 +110,45 @@ impl Song { // TODO: Add function to remove file from the filesystem } + +/// Generates a filename. In order to save a song to the filesystem, the song must have +/// a directory and filename +pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String { + let file_extension = match typ { + types::MusicTypes::DefaultMusicExtension => { + String::from(constants::file_extensions::audio::DEFAULTMUSICEXTENSION) + } + + types::MusicTypes::WavExtension => { + String::from(constants::file_extensions::audio::WAVEXTENSION) + } + types::MusicTypes::FlacExtension => { + String::from(constants::file_extensions::audio::FLACEXTENSION) + } + types::MusicTypes::MPThreeExtension => { + String::from(constants::file_extensions::audio::MPTHREEEXTENSION) + } + }; + + if randomize { + let mut filename: String = String::new(); + let some_chars: String = String::from("abcdefghij0123456789"); + let mut rng = rand::rng(); + + for _ in 0..FILENAME_LENGTH { + let index = rng.random_range(0..=19); + let rando_char = some_chars.chars().nth(index); + + if let Some(c) = rando_char { + filename.push(c); + } + } + filename + &file_extension + } else { + "track-output".to_string() + &file_extension + } +} + /// I/O operations for songs pub mod io { use std::io::Read; diff --git a/tests/tests.rs b/tests/tests.rs index d0a04df..aeff5fb 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -107,7 +107,7 @@ mod song_tests { }; assert_eq!(song.directory.is_empty(), false); - song_cpy.filename = song.generate_filename(types::MusicTypes::FlacExtension, true); + song_cpy.filename = song::generate_filename(types::MusicTypes::FlacExtension, true); println!("Directory: {:?}", song_cpy.directory); println!("File to be created: {:?}", song_cpy.filename); From c263cedf28b5ec13ec8cf8fc4902eadb1425ea9f Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 19:46:00 +0000 Subject: [PATCH 10/10] Remove song (#64) Reviewed-on: https://git.kundeng.us/phoenix/icarus_models/pulls/64 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/song.rs | 21 ++++++++++++++++++--- tests/tests.rs | 10 +++++++--- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89c15e7..5bd15fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,7 +142,7 @@ checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" [[package]] name = "icarus_models" -version = "0.6.2" +version = "0.6.3" dependencies = [ "josekit", "rand", diff --git a/Cargo.toml b/Cargo.toml index 16eb4de..6379891 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_models" -version = "0.6.2" +version = "0.6.3" edition = "2024" rust-version = "1.88" description = "models used for the icarus project" diff --git a/src/song.rs b/src/song.rs index 5735ee6..183d08b 100644 --- a/src/song.rs +++ b/src/song.rs @@ -7,6 +7,7 @@ use crate::constants; use crate::init; use crate::types; +/// Length of characters of a filename to be generated const FILENAME_LENGTH: i32 = 16; #[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)] @@ -92,7 +93,6 @@ impl Song { } } - /// Saves the song to the filesystem using the song's data pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> { match self.song_path() { @@ -107,10 +107,25 @@ impl Song { } } - // TODO: Add function to remove file from the filesystem + /// Removes the song from the filesystem + pub fn remove_from_filesystem(&self) -> Result<(), std::io::Error> { + match self.song_path() { + Ok(song_path) => { + let p = std::path::Path::new(&song_path); + if p.exists() { + match std::fs::remove_file(&p) { + Ok(_) => Ok(()), + Err(err) => Err(err), + } + } else { + Ok(()) + } + } + Err(err) => Err(err), + } + } } - /// Generates a filename. In order to save a song to the filesystem, the song must have /// a directory and filename pub fn generate_filename(typ: types::MusicTypes, randomize: bool) -> String { diff --git a/tests/tests.rs b/tests/tests.rs index aeff5fb..386940b 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -120,7 +120,7 @@ mod song_tests { } #[test] - fn test_save_song_to_filesystem() { + fn test_save_song_to_filesystem_and_remove() { let mut song = song::Song::default(); song.directory = utils::get_tests_directory(); song.filename = String::from("track02.flac"); @@ -132,7 +132,12 @@ mod song_tests { }; match song::io::copy_song(&song, &mut copied_song) { - Ok(_) => {} + Ok(_) => match copied_song.remove_from_filesystem() { + Ok(_) => {} + Err(err) => { + assert!(false, "Error: {err:?}") + } + }, Err(err) => { assert!(false, "Error: {err:?}") } @@ -142,7 +147,6 @@ mod song_tests { #[cfg(test)] mod album_tests { - use crate::utils; use icarus_models::album;