Skip to content

Commit f65b789

Browse files
author
KernelErr
committed
[Test] Add simple test
Signed-off-by: KernelErr <[email protected]>
1 parent 7358ee1 commit f65b789

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

.github/workflows/build.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ jobs:
2323
- name: build examples on WASI
2424
run: |
2525
export PATH="$HOME/.cargo/bin:$PATH"
26-
cargo build --examples
26+
cargo build --examples
27+
- name: install WasmEdge
28+
run: |
29+
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash
30+
- name: run unit tests
31+
run: |
32+
source /home/runner/.wasmedge/env
33+
cargo test

src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,3 +630,34 @@ impl UdpSocket {
630630
Ok(sent)
631631
}
632632
}
633+
634+
#[cfg(test)]
635+
mod tests {
636+
use super::*;
637+
638+
#[test]
639+
fn test_dns_query() {
640+
let node = String::from("www.rust-lang");
641+
let service = String::from("http");
642+
let hints: WasiAddrinfo = WasiAddrinfo::default();
643+
let mut sockaddr = Vec::new();
644+
let mut sockbuff = Vec::new();
645+
let mut ai_canonname = Vec::new();
646+
let addrinfo = WasiAddrinfo::get_addrinfo(
647+
&node,
648+
&service,
649+
&hints,
650+
10,
651+
&mut sockaddr,
652+
&mut sockbuff,
653+
&mut ai_canonname,
654+
)
655+
.unwrap();
656+
assert!(addrinfo.len() > 0);
657+
}
658+
659+
#[test]
660+
fn test_tcp_listen() {
661+
let _ = TcpListener::bind("127.0.0.1:52222", true).unwrap();
662+
}
663+
}

0 commit comments

Comments
 (0)