tcp-test

Crates.iotcp-test
lib.rstcp-test
version0.1.0
sourcesrc
created_at2019-08-13 18:13:23.174111
updated_at2019-09-07 18:44:47.610355
descriptionTest your TCP code
homepage
repositoryhttps://github.com/Draphar/tcp-test
max_upload_size
id156524
size15,622
(Draphar)

documentation

https://docs.rs/tcp-test

README

tcp-test - Test your TCP code

travis-badge appveyor-badge crates.io-badge docs-badge license-badge

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();

    // ...
}
Commit count: 5

cargo fmt