Added tunnel.rs tests.

This commit is contained in:
Teknique 2023-05-31 16:16:57 -07:00
parent 4b14bbb4f4
commit 04c52a4ddb
2 changed files with 84 additions and 3 deletions

View File

@ -133,6 +133,61 @@ pub async fn test_peerstats() {
assert_eq!(orig, copy); 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() { pub async fn test_all() {
test_round_trip_peerinfo().await; test_round_trip_peerinfo().await;
test_alignedu64().await; test_alignedu64().await;
@ -143,4 +198,10 @@ pub async fn test_all() {
test_transferstatsdownup().await; test_transferstatsdownup().await;
test_rpcstats().await; test_rpcstats().await;
test_peerstats().await; test_peerstats().await;
test_tunnelmode().await;
test_tunnelmode().await;
test_tunnelerror().await;
test_tunnelendpoint().await;
test_fulltunnel().await;
test_partialtunnel().await;
} }

View File

@ -45,7 +45,9 @@ pub enum TunnelError {
NoCapacity, // Endpoint is full 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))] #[archive_attr(repr(C), derive(CheckBytes))]
pub struct TunnelEndpoint { pub struct TunnelEndpoint {
pub mode: TunnelMode, pub mode: TunnelMode,
@ -62,7 +64,16 @@ impl Default for TunnelEndpoint {
} }
#[derive( #[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))] #[archive_attr(repr(C), derive(CheckBytes))]
pub struct FullTunnel { pub struct FullTunnel {
@ -73,7 +84,16 @@ pub struct FullTunnel {
} }
#[derive( #[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))] #[archive_attr(repr(C), derive(CheckBytes))]
pub struct PartialTunnel { pub struct PartialTunnel {