tsk-44: Updating tests
This commit is contained in:
21
src/lib.rs
21
src/lib.rs
@@ -7,6 +7,8 @@ pub mod test_util {
|
|||||||
pub mod util {
|
pub mod util {
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
// Function to save a Vec<u8> to a file
|
// Function to save a Vec<u8> to a file
|
||||||
pub fn save_bytes_to_file(bytes: &[u8], file_path: &String) -> io::Result<()> {
|
pub fn save_bytes_to_file(bytes: &[u8], file_path: &String) -> io::Result<()> {
|
||||||
let file = std::path::Path::new(file_path);
|
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(
|
fn path_buf(
|
||||||
directory: &String,
|
directory: &String,
|
||||||
filename: &String,
|
filename: &String,
|
||||||
|
Reference in New Issue
Block a user