From f65b78916d4a44954d5aba4af033e98cc6b3f3e6 Mon Sep 17 00:00:00 2001 From: KernelErr Date: Fri, 18 Feb 2022 18:03:48 +0800 Subject: [PATCH] [Test] Add simple test Signed-off-by: KernelErr --- .github/workflows/build.yml | 9 ++++++++- src/lib.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3da6ce4f..acade412 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,4 +23,11 @@ jobs: - name: build examples on WASI run: | export PATH="$HOME/.cargo/bin:$PATH" - cargo build --examples \ No newline at end of file + cargo build --examples + - name: install WasmEdge + run: | + curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash + - name: run unit tests + run: | + source /home/runner/.wasmedge/env + cargo test \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 38eeead3..32daedd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -630,3 +630,34 @@ impl UdpSocket { Ok(sent) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_dns_query() { + let node = String::from("www.rust-lang"); + let service = String::from("http"); + let hints: WasiAddrinfo = WasiAddrinfo::default(); + let mut sockaddr = Vec::new(); + let mut sockbuff = Vec::new(); + let mut ai_canonname = Vec::new(); + let addrinfo = WasiAddrinfo::get_addrinfo( + &node, + &service, + &hints, + 10, + &mut sockaddr, + &mut sockbuff, + &mut ai_canonname, + ) + .unwrap(); + assert!(addrinfo.len() > 0); + } + + #[test] + fn test_tcp_listen() { + let _ = TcpListener::bind("127.0.0.1:52222", true).unwrap(); + } +}