Crates.io | tcp-test |
lib.rs | tcp-test |
version | 0.1.0 |
source | src |
created_at | 2019-08-13 18:13:23.174111 |
updated_at | 2019-09-07 18:44:47.610355 |
description | Test your TCP code |
homepage | |
repository | https://github.com/Draphar/tcp-test |
max_upload_size | |
id | 156524 |
size | 15,622 |
tcp-test
is a Rust testing library to programmatically use real TCP in your tests.
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();
// ...
}