38 lines
977 B
Rust
38 lines
977 B
Rust
//! Config parsing unit scaffolding using mock sources.
|
|
|
|
#[path = "../support/mod.rs"]
|
|
mod support;
|
|
|
|
mod helpers;
|
|
|
|
use helpers::*;
|
|
use niom_turn::config::Config;
|
|
use support::mocks;
|
|
|
|
#[test]
|
|
fn config_source_mock_serves_payload() {
|
|
let mut source = mocks::MockConfigSource::new();
|
|
source
|
|
.expect_load()
|
|
.returning(|| Ok(minimal_config_json()));
|
|
|
|
let body = source.load().expect("config payload");
|
|
assert!(body.contains("niom-turn.test"));
|
|
}
|
|
|
|
#[test]
|
|
fn parsing_minimal_config_populates_defaults() {
|
|
let json = minimal_config_json();
|
|
let cfg: Config = serde_json::from_str(&json).expect("config parse");
|
|
assert_eq!(cfg.server.bind, "127.0.0.1:0");
|
|
assert_eq!(cfg.auth.realm, "niom-turn.test");
|
|
assert_eq!(cfg.auth.nonce_ttl_seconds, 300);
|
|
}
|
|
|
|
#[test]
|
|
fn malformed_config_fails_to_parse() {
|
|
let json = malformed_config_json();
|
|
let parsed: Result<Config, _> = serde_json::from_str(&json);
|
|
assert!(parsed.is_err());
|
|
}
|