tor-circmgr: Provide testing feature and TestConfig

Like the similar thing in tor-guardmgr.
This commit is contained in:
Ian Jackson 2023-02-23 17:24:43 +00:00
parent 9ebe22756e
commit feab6faa9e
4 changed files with 52 additions and 0 deletions

1
Cargo.lock generated
View File

@ -3731,6 +3731,7 @@ dependencies = [
"async-trait",
"bounded-vec-deque",
"derive_builder_fork_arti",
"derive_more",
"downcast-rs",
"dyn-clone",
"educe",

View File

@ -17,6 +17,10 @@ default = []
full = ["specific-relay"]
specific-relay = []
# Enable testing-only APIs. APIs under this feature are not
# covered by semver.
testing = []
# Enable experimental APIs that are not yet officially supported.
#
# These APIs are not covered by semantic versioning. Using this
@ -31,6 +35,7 @@ hs-common = ["tor-hscrypto"]
async-trait = "0.1.2"
bounded-vec-deque = "0.1"
derive_builder = { version = "0.11.2", package = "derive_builder_fork_arti" }
derive_more = "0.99.3"
downcast-rs = "1.2.0"
dyn-clone = "1.0.4"
educe = "0.4.6"

View File

@ -292,6 +292,49 @@ define_accessor_trait! {
}
}
/// Testing configuration, with public fields
#[cfg(feature = "testing")]
pub(crate) mod test_config {
use super::*;
use crate::*;
use tor_guardmgr::bridge::BridgeConfig;
/// Testing configuration, with public fields
#[derive(Default)]
#[derive(derive_more::AsRef)]
#[allow(clippy::exhaustive_structs)]
pub struct TestConfig {
///
pub path_rules: PathConfig,
///
pub circuit_timing: CircuitTiming,
///
pub preemptive_circuits: PreemptiveCircuitConfig,
///
pub guardmgr: tor_guardmgr::TestConfig,
}
impl AsRef<[BridgeConfig]> for TestConfig {
fn as_ref(&self) -> &[BridgeConfig] {
&self.guardmgr.bridges
}
}
impl AsRef<FallbackList> for TestConfig {
fn as_ref(&self) -> &FallbackList {
&self.guardmgr.fallbacks
}
}
impl GuardMgrConfig for TestConfig {
fn bridges_enabled(&self) -> bool {
self.guardmgr.bridges_enabled()
}
}
impl CircMgrConfig for TestConfig {
fn path_rules(&self) -> &PathConfig { &self.path_rules }
fn circuit_timing(&self) -> &CircuitTiming { &self.circuit_timing }
fn preemptive_circuits(&self) -> &PreemptiveCircuitConfig { &self.preemptive_circuits }
}
}
#[cfg(test)]
mod test {
// @@ begin test lint list maintained by maint/add_warning @@

View File

@ -55,6 +55,9 @@ use std::sync::{Arc, Mutex, Weak};
use std::time::{Duration, Instant};
use tracing::{debug, error, info, trace, warn};
#[cfg(feature = "testing")]
pub use config::test_config::TestConfig;
pub mod build;
mod config;
mod err;