arti-example-config.toml: Re-un-comment the example settings in test

This commit is contained in:
Ian Jackson 2022-05-12 14:48:36 +01:00
parent f18373a7d6
commit bb166c14da
3 changed files with 27 additions and 4 deletions

1
Cargo.lock generated
View File

@ -86,6 +86,7 @@ dependencies = [
"libc",
"notify",
"once_cell",
"regex",
"rlimit",
"safelog",
"serde",

View File

@ -50,6 +50,9 @@ tracing-journald = { version = "0.3.0", optional = true }
tracing-appender = "0.2.0"
trust-dns-proto = "0.21.1"
[dev-dependencies]
regex = { version = "1", default-features = false, features = ["std"] }
[target.'cfg(unix)'.dependencies]
libc = { version = "0.2", default-features = false }

View File

@ -193,23 +193,42 @@ mod test {
#![allow(clippy::unwrap_used)]
use arti_client::config::dir;
use regex::Regex;
use std::time::Duration;
use super::*;
fn uncomment_example_settings(template: &str) -> String {
let re = Regex::new(r#"(?m)^\#([^ \n])"#).unwrap();
re.replace(template, |cap: &regex::Captures<'_>| -> _ {
cap.get(1).unwrap().as_str().to_string()
})
.into()
}
#[test]
fn default_config() {
let empty_config = config::Config::builder().build().unwrap();
let empty_config: ArtiConfig = empty_config.try_into().unwrap();
let example = uncomment_example_settings(ARTI_EXAMPLE_CONFIG);
let cfg = config::Config::builder()
.add_source(config::File::from_str(
ARTI_EXAMPLE_CONFIG,
config::FileFormat::Toml,
))
.add_source(config::File::from_str(&example, config::FileFormat::Toml))
.build()
.unwrap();
// This tests that the example settings do not *contradict* the defaults.
// But it does not prove that the example template file does not contain misspelled
// (and therefore ignored) items - which might even contradict the defaults if
// their spelling was changed.
//
// Really we should test that too, but that's dependent on a fix for
// https://gitlab.torproject.org/tpo/core/arti/-/issues/417
// which is blocked on serde-ignored not handling serde(flatten).
//
// Also we should ideally test that every setting from the config appears here in
// the file. Possibly that could be done with some kind of stunt Deserializer,
// but it's not trivial.
let parsed: ArtiConfig = cfg.try_into().unwrap();
let default = ArtiConfig::default();
assert_eq!(&parsed, &default);