use std::path::PathBuf;
const DEFAULT_MAX_VERSIONS: usize = 50;
const HISTORY_DIR_NAME: &str = "policy-history";
#[derive(Debug, Clone, PartialEq)]
pub struct HistoryConfig {
pub history_dir: PathBuf,
pub max_versions: usize,
}
impl HistoryConfig {
pub fn default_config() -> Self {
let base = std::env::var("AA_DATA_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")).join(".aa"));
Self {
history_dir: base.join(HISTORY_DIR_NAME),
max_versions: DEFAULT_MAX_VERSIONS,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_max_versions_is_50() {
let cfg = HistoryConfig {
history_dir: PathBuf::from("/tmp/test"),
max_versions: DEFAULT_MAX_VERSIONS,
};
assert_eq!(cfg.max_versions, 50);
}
#[test]
fn custom_construction() {
let cfg = HistoryConfig {
history_dir: PathBuf::from("/custom/path"),
max_versions: 100,
};
assert_eq!(cfg.history_dir, PathBuf::from("/custom/path"));
assert_eq!(cfg.max_versions, 100);
}
#[test]
fn default_config_ends_with_policy_history() {
let cfg = HistoryConfig::default_config();
assert!(cfg.history_dir.ends_with("policy-history"));
assert_eq!(cfg.max_versions, 50);
}
}