diff options
Diffstat (limited to 'zone_zfs/src')
-rw-r--r-- | zone_zfs/src/config.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/zone_zfs/src/config.rs b/zone_zfs/src/config.rs index 4c0a8b5..e8f2be0 100644 --- a/zone_zfs/src/config.rs +++ b/zone_zfs/src/config.rs @@ -46,3 +46,92 @@ impl Provider for Config { Serialized::defaults(Config::default()).data() } } + +#[cfg(test)] +mod tests { + use std::path::PathBuf; + + use figment::providers::{Format, Serialized, Toml}; + + use super::*; + + #[test] + fn defaults() { + figment::Jail::expect_with(|jail| { + jail.create_file( + "Config.toml", + r#" + quota = "16G" + pool_name = "pool" + mountpoint = "/srv" + "#, + )?; + + let config: Config = Figment::from(Serialized::defaults(Config::default())) + .merge(Toml::file("Config.toml")) + .extract()?; + + assert_eq!(config, Config::default()); + + Ok(()) + }); + } + + #[test] + fn quota_unit() { + figment::Jail::expect_with(|jail| { + jail.create_file( + "Config.toml", + r#" + quota = "8G" + pool_name = "fool" + mountpoint = "/mnt" + "#, + )?; + + let config: Config = Figment::from(Serialized::defaults(Config::default())) + .merge(Toml::file("Config.toml")) + .extract()?; + + assert_eq!( + config, + Config { + quota: 8_000_000_000u64.into(), + pool_name: String::from("fool"), + mountpoint: PathBuf::from("/mnt"), + } + ); + + Ok(()) + }); + } + + #[test] + fn quota_u64() { + figment::Jail::expect_with(|jail| { + jail.create_file( + "Config.toml", + r#" + quota = 42000000 + pool_name = "fool" + mountpoint = "/mnt" + "#, + )?; + + let config: Config = Figment::from(Serialized::defaults(Config::default())) + .merge(Toml::file("Config.toml")) + .extract()?; + + assert_eq!( + config, + Config { + quota: 42_000_000u64.into(), + pool_name: String::from("fool"), + mountpoint: PathBuf::from("/mnt"), + } + ); + + Ok(()) + }); + } +} |