From a58e4e368813625ce8c04f5b9c5907cba2297b71 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 20 Jan 2022 09:57:19 -0500 Subject: [PATCH] Test for PathConfig::at_least_as_permissive_as(). This is totally not just an exercise to get combined test coverage for tor-circmgr over 90% because I needed something to do that wouldn't distract anybody else. :) --- crates/tor-circmgr/src/config.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/tor-circmgr/src/config.rs b/crates/tor-circmgr/src/config.rs index 9f0a64f31..def852c61 100644 --- a/crates/tor-circmgr/src/config.rs +++ b/crates/tor-circmgr/src/config.rs @@ -308,3 +308,32 @@ impl CircMgrConfig { CircMgrConfigBuilder::default() } } + +#[cfg(test)] +mod test { + #![allow(clippy::unwrap_used)] + use super::*; + + #[test] + fn path_config() { + let pc1 = PathConfig::default(); + // Because these configurations consider _fewer_ nodes to be in the same + // families, they are _more_ permissive about what circuits we can + // build. + let pc2 = PathConfig::builder() + .ipv4_subnet_family_prefix(32) + .build() + .unwrap(); + let pc3 = PathConfig::builder() + .ipv6_subnet_family_prefix(128) + .build() + .unwrap(); + + assert!(pc2.at_least_as_permissive_as(&pc1)); + assert!(pc3.at_least_as_permissive_as(&pc1)); + assert!(pc1.at_least_as_permissive_as(&pc1)); + assert!(!pc1.at_least_as_permissive_as(&pc2)); + assert!(!pc1.at_least_as_permissive_as(&pc3)); + assert!(!pc3.at_least_as_permissive_as(&pc2)); + } +}