From 00eb7439dbf6e0556089bc0435d7d585411340a1 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 27 Mar 2021 11:02:38 +0100 Subject: Add test for log::Level deserialization Signed-off-by: Matthias Beyer --- Cargo.toml | 1 + tests/log.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/log.rs diff --git a/Cargo.toml b/Cargo.toml index 34e5532..586730b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,3 +53,4 @@ glob = "0.3" lazy_static = "1" notify = "^5.0.0" temp-env = "0.3.0" +log = { version = "0.4", features = ["serde"] } diff --git a/tests/log.rs b/tests/log.rs new file mode 100644 index 0000000..41ca98b --- /dev/null +++ b/tests/log.rs @@ -0,0 +1,28 @@ +extern crate config; +extern crate log; + +#[macro_use] +extern crate serde_derive; + +use config::*; + +#[derive(Debug, Deserialize)] +struct Settings { + log: log::Level, +} + +fn config(s: &str) -> Config { + Config::default() + .merge(File::from_str(s, FileFormat::Json)) + .unwrap() + .clone() +} + +#[test] +fn test_load_level_uppercase() { + let s = r#"{ "log": "ERROR" }"#; + let c = config(s); + let l = c.get::("log").unwrap(); + assert_eq!(l, log::Level::Error); +} + -- cgit v1.2.3