summaryrefslogtreecommitdiff
path: root/crates/utils/tcp_connection/tcp_connection_test/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/utils/tcp_connection/tcp_connection_test/src')
-rw-r--r--crates/utils/tcp_connection/tcp_connection_test/src/example_handle.rs18
-rw-r--r--crates/utils/tcp_connection/tcp_connection_test/src/lib.rs4
-rw-r--r--crates/utils/tcp_connection/tcp_connection_test/src/test_tcp_target_build.rs30
3 files changed, 52 insertions, 0 deletions
diff --git a/crates/utils/tcp_connection/tcp_connection_test/src/example_handle.rs b/crates/utils/tcp_connection/tcp_connection_test/src/example_handle.rs
new file mode 100644
index 0000000..95eb5ea
--- /dev/null
+++ b/crates/utils/tcp_connection/tcp_connection_test/src/example_handle.rs
@@ -0,0 +1,18 @@
+use tokio::net::TcpStream;
+use tcp_connection::handle::{ClientHandle, ServerHandle};
+
+pub(crate) struct ExampleClientHandle;
+
+impl ClientHandle<ExampleServerHandle> for ExampleClientHandle {
+ fn process(stream: TcpStream) {
+
+ }
+}
+
+pub(crate) struct ExampleServerHandle;
+
+impl ServerHandle<ExampleClientHandle> for ExampleServerHandle {
+ fn process(stream: TcpStream) {
+
+ }
+} \ No newline at end of file
diff --git a/crates/utils/tcp_connection/tcp_connection_test/src/lib.rs b/crates/utils/tcp_connection/tcp_connection_test/src/lib.rs
new file mode 100644
index 0000000..2b72a15
--- /dev/null
+++ b/crates/utils/tcp_connection/tcp_connection_test/src/lib.rs
@@ -0,0 +1,4 @@
+#[cfg(test)]
+pub mod test_tcp_target_build;
+
+pub(crate) mod example_handle; \ No newline at end of file
diff --git a/crates/utils/tcp_connection/tcp_connection_test/src/test_tcp_target_build.rs b/crates/utils/tcp_connection/tcp_connection_test/src/test_tcp_target_build.rs
new file mode 100644
index 0000000..4ef91cb
--- /dev/null
+++ b/crates/utils/tcp_connection/tcp_connection_test/src/test_tcp_target_build.rs
@@ -0,0 +1,30 @@
+use tcp_connection::target::TcpServerTarget;
+use crate::example_handle::{ExampleClientHandle, ExampleServerHandle};
+
+#[test]
+fn test_tcp_test_target_build() {
+
+ let host = "127.0.0.1:8080";
+
+ // Test build target by string
+ let Ok(target) =
+ TcpServerTarget::<ExampleClientHandle, ExampleServerHandle>::from_str(host) else {
+ panic!("Test target built from a target addr `{}`", host);
+ };
+ assert_eq!(target.to_string(), "127.0.0.1:8080");
+}
+
+#[tokio::test]
+async fn test_tcp_test_target_build_domain() {
+
+ let host = "localhost";
+
+ // Test build target by DomainName and Connection
+ let Ok(target) =
+ TcpServerTarget::<ExampleClientHandle, ExampleServerHandle>::from_domain(host).await else {
+ panic!("Test target built from a domain named `{}`", host);
+ };
+
+ // Test into string
+ assert_eq!(target.to_string(), "127.0.0.1:8080");
+} \ No newline at end of file