use rand::{thread_rng, Rng};
use std::{env, fs, io::Write};
pub fn random_bytes(n: usize) -> Vec<u8> {
let mut result = vec![];
let mut rng = thread_rng();
for _ in 0..n {
result.push(rng.gen_range(0, 255) & 0xFF);
}
result
}
pub fn get_temp_file(file_name: &str, content: &[u8]) -> fs::File {
let mut path_buf = env::current_dir().unwrap();
path_buf.push("target");
path_buf.push("debug");
path_buf.push("testdata");
fs::create_dir_all(&path_buf).unwrap();
path_buf.push(file_name);
let mut tmp_file = fs::File::create(path_buf.as_path()).unwrap();
tmp_file.write_all(content).unwrap();
tmp_file.sync_all().unwrap();
let file = fs::OpenOptions::new()
.read(true)
.write(true)
.open(path_buf.as_path());
assert!(file.is_ok());
file.unwrap()
}