From b1438bd27d32e4e2530825026cc39a8ac5456f68 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sun, 20 Nov 2022 13:35:45 -0600 Subject: test: impl test for `logging::Config` and add `pretty_assertions` --- src/logging/config.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/logging') diff --git a/src/logging/config.rs b/src/logging/config.rs index 2f7be0f..1663f13 100644 --- a/src/logging/config.rs +++ b/src/logging/config.rs @@ -47,3 +47,39 @@ impl Default for Config { } } } + +#[cfg(test)] +mod tests { + use super::*; + use figment::providers::{Format, Serialized, Toml}; + use pretty_assertions::assert_eq; + + #[test] + fn test_extract() { + figment::Jail::expect_with(|jail| { + jail.create_file( + "tmuxr.toml", + r#" + stdout = "warn" + level = "info" + path = "/path/to/logfile.log" + "#, + )?; + + let config: Config = Figment::from(Serialized::defaults(Config::default())) + .merge(Toml::file("tmuxr.toml")) + .extract()?; + + assert_eq!( + config, + Config { + stdout: Some(Level::WARN), + level: Some(Level::INFO), + path: "/path/to/logfile.log".into() + } + ); + + Ok(()) + }); + } +} -- cgit v1.2.3-70-g09d2