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 mut c = Config::default();
8 let res = c.merge(File::new("tests/NoSettings", FileFormat::Yaml).required(false));
9
10 assert!(res.is_ok());
11 }
12
13 #[test]
test_file_required_not_found()14 fn test_file_required_not_found() {
15 let mut c = Config::default();
16 let res = c.merge(File::new("tests/NoSettings", FileFormat::Yaml));
17
18 assert!(res.is_err());
19 assert_eq!(
20 res.unwrap_err().to_string(),
21 "configuration file \"tests/NoSettings\" not found".to_string()
22 );
23 }
24
25 #[test]
test_file_auto()26 fn test_file_auto() {
27 let mut c = Config::default();
28 c.merge(File::with_name("tests/Settings-production"))
29 .unwrap();
30
31 assert_eq!(c.get("debug").ok(), Some(false));
32 assert_eq!(c.get("production").ok(), Some(true));
33 }
34
35 #[test]
test_file_auto_not_found()36 fn test_file_auto_not_found() {
37 let mut c = Config::default();
38 let res = c.merge(File::with_name("tests/NoSettings"));
39
40 assert!(res.is_err());
41 assert_eq!(
42 res.unwrap_err().to_string(),
43 "configuration file \"tests/NoSettings\" not found".to_string()
44 );
45 }
46
47 #[test]
test_file_ext()48 fn test_file_ext() {
49 let mut c = Config::default();
50 c.merge(File::with_name("tests/Settings.json")).unwrap();
51
52 assert_eq!(c.get("debug").ok(), Some(true));
53 assert_eq!(c.get("production").ok(), Some(false));
54 }
55