2 unstable releases

0.1.0 Sep 7, 2019
0.0.1 Aug 13, 2019

#519 in Testing

Download history 10/week @ 2024-02-19 23/week @ 2024-02-26 13/week @ 2024-03-04 5/week @ 2024-03-11 9/week @ 2024-03-18

52 downloads per month
Used in 2 crates

MIT license

12KB
156 lines

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

    // ...
}

Dependencies

~11KB