test(rust): add tests for `ockam_transport_tcp`
@@ -51,3 +51,60 @@ fn parse_socket_addr<S: AsRef<str>>(s: S) -> Result<SocketAddr> {
.parse()
.map_err(|_| TransportError::InvalidAddress)?)
}
+
+#[cfg(test)]
+mod test {
+ use core::fmt::Debug;
+ use ockam_core::{Error, Result};
+
+ use crate::parse_socket_addr;
+ use crate::TransportError;
+
+ fn assert_transport_error<T>(result: Result<T>, error: TransportError)
+ where
+ T: Debug,
+ {
+ let invalid_address_error: Error = error.into();
+ assert_eq!(result.unwrap_err().code(), invalid_address_error.code())
+ }
+
+ #[test]
+ fn test_parse_socket_address() {
+ let result = parse_socket_addr("hostname:port");
+ assert!(result.is_err());
+ assert_transport_error(result, TransportError::InvalidAddress);
+
+ let result = parse_socket_addr("example.com");
+ assert!(result.is_err());
+ assert_transport_error(result, TransportError::InvalidAddress);
+
+ let result = parse_socket_addr("example.com:80");
+ assert!(result.is_err());
+ assert_transport_error(result, TransportError::InvalidAddress);
+
+ let result = parse_socket_addr("127.0.0.1");
+ assert!(result.is_err());
+ assert_transport_error(result, TransportError::InvalidAddress);
+
+ let result = parse_socket_addr("127.0.0.1:port");
+ assert!(result.is_err());
+ assert_transport_error(result, TransportError::InvalidAddress);
+
+ let result = parse_socket_addr("127.0.1:80");
+ assert!(result.is_err());
+ assert_transport_error(result, TransportError::InvalidAddress);
+
+ let result = parse_socket_addr("127.0.0.1:65536");
+ assert!(result.is_err());
+ assert_transport_error(result, TransportError::InvalidAddress);
+
+ let result = parse_socket_addr("127.0.0.1:0");
+ assert!(result.is_ok());
+
+ let result = parse_socket_addr("127.0.0.1:80");
+ assert!(result.is_ok());
+
+ let result = parse_socket_addr("127.0.0.1:8080");
+ assert!(result.is_ok());
+ }
+}
