Environment parsing done with Serde Envy #5

Merged
quentin merged 3 commits from adrien/diplonat:feature/config-handling into main 2021-08-19 06:32:55 +00:00
2 changed files with 6 additions and 3 deletions
Showing only changes of commit 0f114f2134 - Show all commits

View file

@ -59,6 +59,8 @@ impl ConfigOpts {
}) })
} }
// Currently only used in tests
#[allow(dead_code)]
pub fn from_iter<Iter: Clone>(iter: Iter) -> Result<RuntimeConfig> pub fn from_iter<Iter: Clone>(iter: Iter) -> Result<RuntimeConfig>
where Iter: IntoIterator<Item = (String, String)> { where Iter: IntoIterator<Item = (String, String)> {
let base: ConfigOptsBase = envy::prefixed("DIPLONAT_").from_iter(iter.clone())?; let base: ConfigOptsBase = envy::prefixed("DIPLONAT_").from_iter(iter.clone())?;

View file

@ -1,5 +1,4 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::env;
use std::time::Duration; use std::time::Duration;
use crate::config::*; use crate::config::*;
@ -30,7 +29,9 @@ fn all_valid_options() -> HashMap<String, String> {
#[test] #[test]
#[should_panic] #[should_panic]
fn err_empty_env() { fn err_empty_env() {
ConfigOpts::from_env(); std::env::remove_var("DIPLONAT_PRIVATE_IP");
std::env::remove_var("DIPLONAT_CONSUL_NODE_NAME");
ConfigOpts::from_env().unwrap();
} }
#[test] #[test]
@ -71,7 +72,7 @@ fn err_from_iter_invalid_refresh_time() {
let mut opts = minimal_valid_options(); let mut opts = minimal_valid_options();
opts.insert("DIPLONAT_EXPIRATION_TIME".to_string(), "60".to_string()); opts.insert("DIPLONAT_EXPIRATION_TIME".to_string(), "60".to_string());
opts.insert("DIPLONAT_REFRESH_TIME".to_string(), "60".to_string()); opts.insert("DIPLONAT_REFRESH_TIME".to_string(), "60".to_string());
let rt_config = ConfigOpts::from_iter(opts.clone()).unwrap(); ConfigOpts::from_iter(opts).unwrap();
} }
#[test] #[test]