Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
41
crates/adapters/assets/tests/common/mod.rs
Normal file
41
crates/adapters/assets/tests/common/mod.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
#![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
|
||||
}
|
||||
Reference in New Issue
Block a user