some endpoint tests.

Signed-off-by: Erik Hollensbe <git@hollensbe.org>
This commit is contained in:
Erik Hollensbe 2022-06-24 09:55:35 -07:00
parent 0e52da77f9
commit 040e130666
No known key found for this signature in database
GPG key ID: 4BB0E241A863B389

View file

@ -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::<u64>() + 1).unwrap(), hash);
let mut buf = Buffer::<72>::new();
assert!(zte.marshal(&mut buf).is_ok());
}
}