1 #![cfg(feature = "yaml")]
2
3 use config::{Config, File, FileFormat};
4
5 #[test]
test_file_not_required()6 fn test_file_not_required() {
7 let res = Config::builder()
8 .add_source(File::new("tests/NoSettings", FileFormat::Yaml).required(false))
9 .build();
10
11 assert!(res.is_ok());
12 }
13
14 #[test]
test_file_required_not_found()15 fn test_file_required_not_found() {
16 let res = Config::builder()
17 .add_source(File::new("tests/NoSettings", FileFormat::Yaml))
18 .build();
19
20 assert!(res.is_err());
21 assert_eq!(
22 res.unwrap_err().to_string(),
23 "configuration file \"tests/NoSettings\" not found".to_string()
24 );
25 }
26
27 #[test]
test_file_auto()28 fn test_file_auto() {
29 let c = Config::builder()
30 .add_source(File::with_name("tests/Settings-production"))
31 .build()
32 .unwrap();
33
34 assert_eq!(c.get("debug").ok(), Some(false));
35 assert_eq!(c.get("production").ok(), Some(true));
36 }
37
38 #[test]
test_file_auto_not_found()39 fn test_file_auto_not_found() {
40 let res = Config::builder()
41 .add_source(File::with_name("tests/NoSettings"))
42 .build();
43
44 assert!(res.is_err());
45 assert_eq!(
46 res.unwrap_err().to_string(),
47 "configuration file \"tests/NoSettings\" not found".to_string()
48 );
49 }
50
51 #[test]
test_file_ext()52 fn test_file_ext() {
53 let c = Config::builder()
54 .add_source(File::with_name("tests/Settings.json"))
55 .build()
56 .unwrap();
57
58 assert_eq!(c.get("debug").ok(), Some(true));
59 assert_eq!(c.get("production").ok(), Some(false));
60 }
61 #[test]
test_file_second_ext()62 fn test_file_second_ext() {
63 let c = Config::builder()
64 .add_source(File::with_name("tests/Settings2.default"))
65 .build()
66 .unwrap();
67
68 assert_eq!(c.get("debug").ok(), Some(true));
69 assert_eq!(c.get("production").ok(), Some(false));
70 }
71