Files
dvd-thing/crates/adapters/assets/tests/common/mod.rs
Gabriel Kaszewski 15fdace324
All checks were successful
CI / Check / Test (push) Successful in 3m40s
init v.1.0.0
Co-authored-by: Copilot <copilot@github.com>
2026-08-06 20:11:22 +02:00

42 lines
1022 B
Rust

#![allow(dead_code)]
use std::{
fs,
path::{Path, PathBuf},
};
pub const LOGO_BYTES: &[u8] = b"pretend png";
pub fn path(value: &str) -> Option<PathBuf> {
Some(PathBuf::from(value))
}
pub fn env_of(pairs: &[(&str, &str)]) -> impl Fn(&str) -> Option<PathBuf> + use<> {
let pairs: Vec<(String, PathBuf)> = pairs
.iter()
.map(|(key, value)| ((*key).to_owned(), PathBuf::from(value)))
.collect();
move |key| {
pairs
.iter()
.find(|(name, _)| name == key)
.map(|(_, value)| value.clone())
}
}
pub fn scratch(name: &str) -> PathBuf {
let directory = std::env::temp_dir().join(format!("dvd-thing-test-{name}"));
let _ = fs::remove_dir_all(&directory);
fs::create_dir_all(&directory).expect("temp directory must be creatable");
directory
}
pub fn write_logo(directory: &Path) -> PathBuf {
let file = directory.join("logo.png");
fs::write(&file, LOGO_BYTES).expect("temp file must be writable");
file
}