niom-turn/tests/config/helpers.rs

25 lines
684 B
Rust

//! Helpers for config parsing tests.
use serde_json::json;
use std::io::Write;
use tempfile::NamedTempFile;
pub fn minimal_config_json() -> String {
json!({
"server": { "bind": "127.0.0.1:0", "tls_cert": null, "tls_key": null },
"credentials": [],
"auth": { "realm": "niom-turn.test", "nonce_ttl_seconds": 300 }
})
.to_string()
}
pub fn malformed_config_json() -> String {
"{ server: }".to_string()
}
pub fn write_temp_config(body: &str) -> NamedTempFile {
let mut file = NamedTempFile::new().expect("temp file");
file.write_all(body.as_bytes()).expect("write temp config");
file.flush().expect("flush temp config");
file
}