2 unstable releases
0.1.0 | Sep 7, 2019 |
---|---|
0.0.1 | Aug 13, 2019 |
#473 in Testing
Used in 2 crates
12KB
156 lines
tcp-test - Test your TCP code
tcp-test
is a Rust testing library to programmatically use real TCP in your tests.
Usage
Cargo.toml
[dev-dependencies]
tcp-test = "0.1"
Then simply use channel()
in every test:
use tcp_test::channel;
use std::io::{self, Read, Write};
#[test]
fn some_test() {
let (mut local, mut remote) = channel();
// both streams point to each other
let local_addr = remote.local_addr().unwrap();
let peer_addr = local.peer_addr().unwrap();
assert_eq!(local_addr, peer_addr);
let data = b"Hello, dear listener!";
local.write_all(data).unwrap();
let mut buf = Vec::new();
remote.read_to_end(&mut buf).unwrap();
assert_eq!(&buf, data);
}
#[test]
fn other_test() {
let (mut local, mut remote) = channel();
// ...
}
Dependencies
~10KB