#![allow(dead_code)] use std::{ fs, path::{Path, PathBuf}, }; pub const LOGO_BYTES: &[u8] = b"pretend png"; pub fn path(value: &str) -> Option { Some(PathBuf::from(value)) } pub fn env_of(pairs: &[(&str, &str)]) -> impl Fn(&str) -> Option + 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 }