diff --git a/src/dns.rs b/src/dns.rs index c2c14e0..3fbcd0b 100644 --- a/src/dns.rs +++ b/src/dns.rs @@ -246,14 +246,9 @@ impl RequestHandler for IronDnsHandler { #[cfg(test)] mod tests { use super::*; - use iroh::SecretKey; + use crate::test_utils::test_endpoint_id; use std::str::FromStr; - fn test_endpoint_id(seed: u8) -> EndpointId { - let secret = SecretKey::from_bytes(&[seed; 32]); - secret.public() - } - #[test] fn test_dns_resolver_new() { let registry = Arc::new(Registry::new()); diff --git a/src/lib.rs b/src/lib.rs index 3833f6d..5340c1f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ pub mod keys; pub mod mapping; pub mod node; pub mod packet; +pub mod test_utils; pub mod protocol; pub mod tun; diff --git a/src/mapping.rs b/src/mapping.rs index c51cad2..bf1113c 100644 --- a/src/mapping.rs +++ b/src/mapping.rs @@ -274,13 +274,7 @@ impl Default for Registry { #[cfg(test)] mod tests { use super::*; - use iroh::SecretKey; - - /// Helper to create a test EndpointId from a seed value - fn test_endpoint_id(seed: u8) -> EndpointId { - let secret = SecretKey::from_bytes(&[seed; 32]); - secret.public() - } + use crate::test_utils::test_endpoint_id; #[test] fn test_registry_new() { diff --git a/src/protocol.rs b/src/protocol.rs index ed48587..c2b0ae9 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -383,11 +383,7 @@ mod tests { use iroh::endpoint::presets::N0; use std::net::Ipv6Addr; - /// Helper to create test EndpointIds - fn test_endpoint_id(seed: u8) -> EndpointId { - let secret = SecretKey::from_bytes(&[seed; 32]); - secret.public() - } + use crate::test_utils::test_endpoint_id; /// Helper to create a minimal valid IPv6 packet fn create_ipv6_packet(src: Ipv6Addr, dst: Ipv6Addr, payload_size: usize) -> Vec { diff --git a/src/test_utils.rs b/src/test_utils.rs new file mode 100644 index 0000000..345b0e3 --- /dev/null +++ b/src/test_utils.rs @@ -0,0 +1,9 @@ +use iroh::{EndpointId, SecretKey}; + +/// Create a test `EndpointId` from a seed byte. +/// The same seed always produces the same `EndpointId`, +/// making tests deterministic and reproducible. +pub fn test_endpoint_id(seed: u8) -> EndpointId { + let secret = SecretKey::from_bytes(&[seed; 32]); + secret.public() +} diff --git a/src/tun.rs b/src/tun.rs index fa342a4..3195dbf 100644 --- a/src/tun.rs +++ b/src/tun.rs @@ -484,12 +484,7 @@ impl TunInterface { #[cfg(test)] mod tests { use super::*; - use iroh::SecretKey; - - fn test_endpoint_id(seed: u8) -> iroh::EndpointId { - let secret = SecretKey::from_bytes(&[seed; 32]); - secret.public() - } + use crate::test_utils::test_endpoint_id; #[test] fn test_tun_interface_new() { diff --git a/tests/integration.rs b/tests/integration.rs index c743e42..a1d9e8e 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -16,11 +16,7 @@ use std::sync::Arc; use tempfile::TempDir; use tokio::sync::mpsc; -/// Helper to create test EndpointIds -fn test_endpoint_id(seed: u8) -> EndpointId { - let secret = SecretKey::from_bytes(&[seed; 32]); - secret.public() -} +use iron::test_utils::test_endpoint_id; /// Test that Registry provides consistent mappings across all components #[tokio::test]