//! Testing utils to help with unit tests and integration tests.
use std::fs;
use std::path::PathBuf;

use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};

/// Creates a temporary directory with a random string.
///
/// # Notes
/// This is mainly used for creating a temp directory for the RockeDB storage in the server
/// when testing the server.
///
/// # Returns
/// * `PathBuf`: The path to the temporary directory
pub fn create_temp_dir_with_random_string() -> PathBuf {
	// Generate a random string
	let rand_string: String =
		thread_rng().sample_iter(&Alphanumeric).take(10).map(char::from).collect();

	// Create a path with the random string
	let mut temp_dir = std::env::temp_dir();
	temp_dir.push(rand_string);

	// Create the directory
	fs::create_dir(&temp_dir).expect("Failed to create temporary directory");

	temp_dir
}
