tsk-44: Updating tests

This commit is contained in:
2025-10-20 20:54:36 -04:00
parent 4df6855ca4
commit ff3171d9e7

View File

@@ -7,6 +7,8 @@ pub mod test_util {
pub mod util {
use std::io::{self, Write};
use rand::Rng;
// Function to save a Vec<u8> to a file
pub fn save_bytes_to_file(bytes: &[u8], file_path: &String) -> io::Result<()> {
let file = std::path::Path::new(file_path);
@@ -44,6 +46,25 @@ pub mod test_util {
}
}
pub fn generate_filename() -> Result<String, std::io::Error> {
let mut filename = String::from("track-");
let length = 20;
let characters = "abcdef0123456789";
let amount_of_characters = characters.len() - 1;
let mut rng = rand::rng();
for _ in 0..length {
let index = rng.random_range(0..=amount_of_characters);
let random_c = characters.chars().nth(index);
if let Some(c) = random_c {
filename.push(c);
}
}
Ok(format!("{filename}.flac"))
}
fn path_buf(
directory: &String,
filename: &String,