use std::ops::Deref;
use std::path::{Path, PathBuf};
pub const TEST_ADMIN_KEY_BYTES: [u8; 32] = *b"0123456789abcdefghijklmnopqrstuv";
pub const TEST_ADMIN_KEY: &str = match std::str::from_utf8(&TEST_ADMIN_KEY_BYTES) {
Ok(key) => key,
Err(_) => panic!("the test administrator key is ASCII"),
};
pub static PROCESS_CREDENTIAL_TEST_LOCK: std::sync::LazyLock<tokio::sync::Mutex<()>> =
std::sync::LazyLock::new(|| tokio::sync::Mutex::new(()));
#[derive(Debug)]
pub struct TempPath(PathBuf);
impl TempPath {
pub fn new(label: &str) -> Self {
let suffix: u64 = rand::RngExt::random(&mut rand::rng());
Self(std::env::temp_dir().join(format!(
"pb-mapper-{label}-{}-{suffix:016x}",
std::process::id()
)))
}
pub fn path(&self) -> &Path {
&self.0
}
}
impl Deref for TempPath {
type Target = Path;
fn deref(&self) -> &Path {
&self.0
}
}
impl AsRef<Path> for TempPath {
fn as_ref(&self) -> &Path {
&self.0
}
}
impl Drop for TempPath {
fn drop(&mut self) {
if std::fs::remove_dir_all(&self.0).is_err() {
let _ = std::fs::remove_file(&self.0);
}
}
}