From 04c52a4ddb26ac2b27352446376d793c01c15f94 Mon Sep 17 00:00:00 2001 From: Teknique Date: Wed, 31 May 2023 16:16:57 -0700 Subject: [PATCH] Added tunnel.rs tests. --- .../veilid_api/tests/test_serialize_json.rs | 61 +++++++++++++++++++ veilid-core/src/veilid_api/types/tunnel.rs | 26 +++++++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/veilid-core/src/veilid_api/tests/test_serialize_json.rs b/veilid-core/src/veilid_api/tests/test_serialize_json.rs index 8e3a9109..d2829df6 100644 --- a/veilid-core/src/veilid_api/tests/test_serialize_json.rs +++ b/veilid-core/src/veilid_api/tests/test_serialize_json.rs @@ -133,6 +133,61 @@ pub async fn test_peerstats() { assert_eq!(orig, copy); } +pub async fn test_tunnelmode() { + let orig = TunnelMode::Raw; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} +pub async fn test_tunnelerror() { + let orig = TunnelError::NoCapacity; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_tunnelendpoint() { + let orig = TunnelEndpoint { + mode: TunnelMode::Raw, + description: "Here there be tygers.".to_string(), + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_fulltunnel() { + let orig = FullTunnel { + id: AlignedU64::from(42), + timeout: AlignedU64::from(3_000_000), + local: TunnelEndpoint { + mode: TunnelMode::Turn, + description: "Left end.".to_string(), + }, + remote: TunnelEndpoint { + mode: TunnelMode::Turn, + description: "Right end.".to_string(), + }, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + +pub async fn test_partialtunnel() { + let orig = PartialTunnel { + id: AlignedU64::from(42), + timeout: AlignedU64::from(3_000_000), + local: TunnelEndpoint { + mode: TunnelMode::Turn, + description: "I'm so lonely.".to_string(), + }, + }; + let copy = deserialize_json(&serialize_json(&orig)).unwrap(); + + assert_eq!(orig, copy); +} + pub async fn test_all() { test_round_trip_peerinfo().await; test_alignedu64().await; @@ -143,4 +198,10 @@ pub async fn test_all() { test_transferstatsdownup().await; test_rpcstats().await; test_peerstats().await; + test_tunnelmode().await; + test_tunnelmode().await; + test_tunnelerror().await; + test_tunnelendpoint().await; + test_fulltunnel().await; + test_partialtunnel().await; } diff --git a/veilid-core/src/veilid_api/types/tunnel.rs b/veilid-core/src/veilid_api/types/tunnel.rs index 968c7695..bdea8a1c 100644 --- a/veilid-core/src/veilid_api/types/tunnel.rs +++ b/veilid-core/src/veilid_api/types/tunnel.rs @@ -45,7 +45,9 @@ pub enum TunnelError { NoCapacity, // Endpoint is full } -#[derive(Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)] +#[derive( + Clone, Debug, PartialEq, Eq, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, +)] #[archive_attr(repr(C), derive(CheckBytes))] pub struct TunnelEndpoint { pub mode: TunnelMode, @@ -62,7 +64,16 @@ impl Default for TunnelEndpoint { } #[derive( - Clone, Debug, Default, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, + Clone, + Debug, + Default, + PartialEq, + Eq, + Serialize, + Deserialize, + RkyvArchive, + RkyvSerialize, + RkyvDeserialize, )] #[archive_attr(repr(C), derive(CheckBytes))] pub struct FullTunnel { @@ -73,7 +84,16 @@ pub struct FullTunnel { } #[derive( - Clone, Debug, Default, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, + Clone, + Debug, + Default, + PartialEq, + Eq, + Serialize, + Deserialize, + RkyvArchive, + RkyvSerialize, + RkyvDeserialize, )] #[archive_attr(repr(C), derive(CheckBytes))] pub struct PartialTunnel {