summaryrefslogtreecommitdiff
path: root/crates/utils
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-09-14 12:40:02 +0800
committer魏曹先生 <1992414357@qq.com>2025-09-14 12:40:02 +0800
commit74b7dff67681191d580f663a866a84cdb4554be4 (patch)
tree3ba1223f9b7aa5da44a50b56b407a68cb17e79da /crates/utils
parent6812fc363ba8cdf452327664cfae6c69cf82b980 (diff)
Update module `tcp_connection_test`
Diffstat (limited to 'crates/utils')
-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