diff options
author | Toby Vincent <tobyv13@gmail.com> | 2022-03-18 15:31:09 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-03-18 15:31:09 -0500 |
commit | 0074718ecdb2f576f8c17c112e576168b392ea0e (patch) | |
tree | bf40686aa254007c43bdc61f1476a61191e3898d /zone_zfs/src | |
parent | b068c57e1264a876d6f7c8d40b6cd1a043979d90 (diff) |
test: write tests for zone_zfs config
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(()) + }); + } +} |