summaryrefslogtreecommitdiffstats
path: root/tests/file.rs
blob: 6ad554aa151c5a8a47d7b2095e302626256d11f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#![cfg(feature = "yaml")]

use config::*;

#[test]
fn test_file_not_required() {
    let res = Config::builder()
        .add_source(File::new("tests/NoSettings", FileFormat::Yaml).required(false))
        .build();

    assert!(res.is_ok());
}

#[test]
fn test_file_required_not_found() {
    let res = Config::builder()
        .add_source(File::new("tests/NoSettings", FileFormat::Yaml))
        .build();

    assert!(res.is_err());
    assert_eq!(
        res.unwrap_err().to_string(),
        "configuration file \"tests/NoSettings\" not found".to_string()
    );
}

#[test]
fn test_file_auto() {
    let c = Config::builder()
        .add_source(File::with_name("tests/Settings-production"))
        .build()
        .unwrap();

    assert_eq!(c.get("debug").ok(), Some(false));
    assert_eq!(c.get("production").ok(), Some(true));
}

#[test]
fn test_file_auto_not_found() {
    let res = Config::builder()
        .add_source(File::with_name("tests/NoSettings"))
        .build();

    assert!(res.is_err());
    assert_eq!(
        res.unwrap_err().to_string(),
        "configuration file \"tests/NoSettings\" not found".to_string()
    );
}

#[test]
fn test_file_ext() {
    let c = Config::builder()
        .add_source(File::with_name("tests/Settings.json"))
        .build()
        .unwrap();

    assert_eq!(c.get("debug").ok(), Some(true));
    assert_eq!(c.get("production").ok(), Some(false));
}