use std::path::Path;
use ddmw_client::conf;
use serde::Deserialize;
#[test]
fn no_conf() {
let fname = Path::new("nonexistent.toml");
let Ok(None) = conf::load(Some(fname)) else {
panic!("Unexpectedly noy Ok(None)");
};
}
#[test]
fn load_default() {
let Ok(Some(_fig)) = conf::load(None) else {
panic!("Load default ddmwapp.toml unexpectedly failed");
};
}
#[test]
fn load_fname() {
let fname = Path::new("ddmwapp.toml");
let Ok(Some(_fig)) = conf::load(Some(fname)) else {
panic!("Load explicit ddmwapp.toml unexpectedly failed");
};
}
#[test]
fn extract_custom_field() {
let Ok(Some(fig)) = conf::load(None) else {
panic!("Load explicit ddmwapp.toml unexpectedly failed");
};
let s: String = fig.extract_inner("custom-string").unwrap();
assert_eq!(s, "my-string");
let i: u32 = fig.extract_inner("custom-int").unwrap();
assert_eq!(i, 7);
let s: String = fig
.extract_inner("custom-app.another-custom-string")
.unwrap();
assert_eq!(s, "string-too");
let i: u32 = fig.extract_inner("custom-app.another-custom-int").unwrap();
assert_eq!(i, 11);
}
#[derive(Debug, Default, Deserialize)]
pub struct CustomChild {
#[serde(rename = "another-custom-string")]
pub mystr: String,
#[serde(rename = "another-custom-int")]
pub myint: u32
}
#[test]
fn extract_custom_child_struct() {
let Ok(Some(fig)) = conf::load(None) else {
panic!("Load explicit ddmwapp.toml unexpectedly failed");
};
let conf: CustomChild = fig.extract_inner("custom-app").unwrap();
assert_eq!(conf.mystr, "string-too");
assert_eq!(conf.myint, 11);
}
#[derive(Debug, Default, Deserialize)]
pub struct CustomApp {
#[serde(rename = "channel")]
pub ch: Option<String>,
pub auth: ddmw_client::auth::Auth,
#[serde(rename = "custom-app")]
pub chld: CustomChild
}
#[test]
fn extract_custom_app() {
let Ok(Some(fig)) = conf::load(None) else {
panic!("Load explicit ddmwapp.toml unexpectedly failed");
};
let appconf: CustomApp = fig.extract().unwrap();
assert_eq!(appconf.ch, Some(String::from("42")));
assert_eq!(appconf.chld.mystr, "string-too");
assert_eq!(appconf.chld.myint, 11);
}