From 040e13066618989cf75920b1a72d58fe3133bb60 Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Fri, 24 Jun 2022 09:55:35 -0700 Subject: [PATCH] some endpoint tests. Signed-off-by: Erik Hollensbe --- .../src/vl1/endpoint.rs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/zerotier-network-hypervisor/src/vl1/endpoint.rs b/zerotier-network-hypervisor/src/vl1/endpoint.rs index e28777e8a..e46c6d1f5 100644 --- a/zerotier-network-hypervisor/src/vl1/endpoint.rs +++ b/zerotier-network-hypervisor/src/vl1/endpoint.rs @@ -425,3 +425,36 @@ impl<'de> Deserialize<'de> for Endpoint { } } } + +#[cfg(test)] +mod tests { + use zerotier_core_crypto::hash::SHA512_HASH_SIZE; + + use super::{Endpoint, MAX_MARSHAL_SIZE}; + use crate::{util::marshalable::Marshalable, vl1::Address}; + + #[test] + fn endpoint_default() { + let e: Endpoint = Default::default(); + assert!(matches!(e, Endpoint::Nil)) + } + + #[test] + fn endpoint_from_bytes() { + let v = [0u8; MAX_MARSHAL_SIZE]; + assert!(Endpoint::from_bytes(&v).is_none()); + } + + #[test] + fn endpoint_marshal() { + use crate::util::buffer::Buffer; + + let mut hash = [0u8; SHA512_HASH_SIZE]; + hash.fill_with(|| rand::random()); + let zte = Endpoint::ZeroTier(Address::from_u64(rand::random::() + 1).unwrap(), hash); + + let mut buf = Buffer::<72>::new(); + + assert!(zte.marshal(&mut buf).is_ok()); + } +}