use camino::Utf8PathBuf;
#[derive(Debug, Clone)]
pub(super) struct TimezoneEnv {
pub(super) dir: Option<Utf8PathBuf>,
pub(super) zone: String,
}
#[derive(Debug, Clone)]
pub struct TestBootstrapEnvironment {
pub home: Utf8PathBuf,
pub xdg_cache_home: Utf8PathBuf,
pub xdg_runtime_dir: Utf8PathBuf,
pub pgpass_file: Utf8PathBuf,
pub tz_dir: Option<Utf8PathBuf>,
pub timezone: String,
}
impl TestBootstrapEnvironment {
pub(super) fn from_components(
xdg: XdgDirs,
pgpass_file: Utf8PathBuf,
timezone: TimezoneEnv,
) -> Self {
Self {
home: xdg.home,
xdg_cache_home: xdg.cache,
xdg_runtime_dir: xdg.runtime,
pgpass_file,
tz_dir: timezone.dir,
timezone: timezone.zone,
}
}
#[must_use]
pub fn to_env(&self) -> Vec<(String, Option<String>)> {
let mut env = vec![
("HOME".into(), Some(self.home.as_str().into())),
(
"XDG_CACHE_HOME".into(),
Some(self.xdg_cache_home.as_str().into()),
),
(
"XDG_RUNTIME_DIR".into(),
Some(self.xdg_runtime_dir.as_str().into()),
),
("PGPASSFILE".into(), Some(self.pgpass_file.as_str().into())),
];
env.push((
"TZDIR".into(),
self.tz_dir.as_ref().map(|dir| dir.as_str().into()),
));
env.push(("TZ".into(), Some(self.timezone.clone())));
env
}
}
#[derive(Debug, Clone)]
pub(super) struct XdgDirs {
pub(super) home: Utf8PathBuf,
pub(super) cache: Utf8PathBuf,
pub(super) runtime: Utf8PathBuf,
}