Skip to content

Commit b59d410

Browse files
committed
Split tests to one test per case
Signed-off-by: Matthias Beyer <[email protected]>
1 parent b4984bb commit b59d410

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

tests/log.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ struct Settings {
1313
}
1414

1515
fn config(s: &str) -> Config {
16-
Config::default()
17-
.merge(File::from_str(s, FileFormat::Json))
16+
Config::builder()
17+
.add_source(File::from_str(s, FileFormat::Json))
18+
.build()
1819
.unwrap()
19-
.clone()
2020
}
2121

2222
#[test]
@@ -28,25 +28,42 @@ fn test_load_level_uppercase() {
2828
}
2929

3030
#[test]
31-
fn test_load_level_lowercase() {
31+
fn test_case_sensitivity_log_level_from_str() {
3232
// to verify that this works
33-
{
34-
use std::str::FromStr;
35-
let l = log::Level::from_str("error").unwrap();
36-
assert_eq!(l, log::Level::Error);
37-
}
3833

39-
let s = r#"{ "log": "error" }"#;
34+
use std::str::FromStr;
35+
let l = log::Level::from_str("error").unwrap();
36+
assert_eq!(l, log::Level::Error);
37+
}
4038

39+
#[test]
40+
fn test_case_sensitivity_json_from_str() {
4141
// to confirm serde_json works as expected
42-
{
43-
let j: Settings = serde_json::from_str(s).unwrap();
44-
assert_eq!(j.log, log::Level::Error);
45-
}
42+
let s = r#"{ "log": "error" }"#;
43+
44+
let j: Settings = serde_json::from_str(s).unwrap();
45+
assert_eq!(j.log, log::Level::Error);
46+
}
4647

48+
#[test]
49+
#[should_panic(expected = "Expected Ok(_) for Err(enum Level does not have variant constructor error)")]
50+
fn test_load_level_lowercase_failing() {
51+
// The following should fail because case sensitivity is not disabled
52+
53+
let s = r#"{ "log": "error" }"#;
4754
let c = config(s);
48-
assert_eq!(c.get_str("log").unwrap(), "error");
55+
assert_eq!(c.get_string("log").unwrap(), "error");
4956
let l = c.get::<log::Level>("log");
5057
assert!(l.is_ok(), "Expected Ok(_) for {:?}", l);
5158
assert_eq!(l.unwrap(), log::Level::Error);
5259
}
60+
61+
#[test]
62+
fn test_load_level_lowercase_succeeding() {
63+
let s = r#"{ "log": "error" }"#;
64+
let c = config(s);
65+
assert_eq!(c.get_string("log").unwrap(), "error");
66+
let s = c.try_deserialize::<Settings>();
67+
assert!(s.is_ok(), "Expected Ok(_) for {:?}", s);
68+
assert_eq!(s.unwrap().log, log::Level::Error);
69+
}

0 commit comments

Comments
 (0)