use serde::Deserialize;
use std::path::PathBuf;
#[derive(Debug, Clone, Deserialize)]
pub struct StorageConfig {
#[serde(default)]
pub driver: String,
#[serde(default)]
pub root: PathBuf,
#[serde(default)]
pub run_root: PathBuf,
#[serde(default)]
pub image_stores: Vec<PathBuf>,
#[serde(default)]
pub layer_stores: Vec<AdditionalLayerStore>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct AdditionalLayerStore {
pub path: PathBuf,
#[serde(default)]
pub with_reference: bool,
}
impl StorageConfig {
pub fn from_toml(content: &str) -> Result<Self, toml::de::Error> {
toml::from_str(content)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_basic_config() {
let config_str = r#"
driver = "overlay"
root = "/var/lib/containers/storage"
"#;
let config = StorageConfig::from_toml(config_str).unwrap();
assert_eq!(config.driver, "overlay");
assert_eq!(config.root, PathBuf::from("/var/lib/containers/storage"));
}
#[test]
fn test_parse_with_layer_stores() {
let config_str = r#"
driver = "overlay"
root = "/var/lib/containers/storage"
[[layer_stores]]
path = "/mnt/layers"
with_reference = true
"#;
let config = StorageConfig::from_toml(config_str).unwrap();
assert_eq!(config.layer_stores.len(), 1);
assert_eq!(config.layer_stores[0].path, PathBuf::from("/mnt/layers"));
assert!(config.layer_stores[0].with_reference);
}
}