Skip to content

Commit 00eb743

Browse files
committed
Add test for log::Level deserialization
Signed-off-by: Matthias Beyer <[email protected]>
1 parent f4c1193 commit 00eb743

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ glob = "0.3"
5353
lazy_static = "1"
5454
notify = "^5.0.0"
5555
temp-env = "0.3.0"
56+
log = { version = "0.4", features = ["serde"] }

tests/log.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
extern crate config;
2+
extern crate log;
3+
4+
#[macro_use]
5+
extern crate serde_derive;
6+
7+
use config::*;
8+
9+
#[derive(Debug, Deserialize)]
10+
struct Settings {
11+
log: log::Level,
12+
}
13+
14+
fn config(s: &str) -> Config {
15+
Config::default()
16+
.merge(File::from_str(s, FileFormat::Json))
17+
.unwrap()
18+
.clone()
19+
}
20+
21+
#[test]
22+
fn test_load_level_uppercase() {
23+
let s = r#"{ "log": "ERROR" }"#;
24+
let c = config(s);
25+
let l = c.get::<log::Level>("log").unwrap();
26+
assert_eq!(l, log::Level::Error);
27+
}
28+

0 commit comments

Comments
 (0)