summaryrefslogtreecommitdiffstats
path: root/tests/defaults.rs
blob: c50dd658d81b52213a0f0789b8304aa69060609c (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
extern crate config_maint;

#[macro_use]
extern crate serde_derive;

use config_maint::*;

#[derive(Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct Settings {
    pub db_host: String,
}

impl Default for Settings {
    fn default() -> Self {
        Settings {
            db_host: String::from("default"),
        }
    }
}

#[test]
fn set_defaults() {
    let c = Config::new();
    let s: Settings = c.try_into().expect("Deserialization failed");

    assert_eq!(s.db_host, "default");
}

#[test]
fn try_from_defaults() {
    let c = Config::try_from(&Settings::default()).expect("Serialization failed");
    let s: Settings = c.try_into().expect("Deserialization failed");
    assert_eq!(s.db_host, "default");
}