2 releases
Uses old Rust 2015
0.1.1 | Sep 2, 2018 |
---|---|
0.1.0 | Aug 30, 2018 |
#53 in #fake
Used in http-codec
5KB
63 lines
fake-stream
This is a fake stream for testing.
It writes and reads from the same buffer.
Example
extern crate fake_stream;
use fake_stream::FakeStream;
fn main() {
let mut fake = FakeStream::new();
let wl = fake.write(b"something").unwrap();
assert_eq!(9, wl);
let mut buf = [0; 5];
let rl = fake.read(&mut buf).unwrap();
assert_eq!(5, rl);
assert_eq!(buf, *b"somet");
let mut buf = *b" ";
let rl = fake.read(&mut buf).unwrap();
assert_eq!(4, rl);
assert_eq!(buf, *b"hing ");
}
tokio-codec Example
fn main() {
let mut fake = FakeStream::new();
let res = b"\
HTTP/1.1 200 OK\r\n\
Date: Mon, 27 Jul 2009 12:28:53 GMT\r\n\
Server: Apache/2.2.14 (Win32)\r\n\
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT\r\n\
Content-Length: 9\r\n\
Content-Type: text/html\r\n\r\n\
something";
let wl = fake.write(res).unwrap();
assert_eq!(res.len(), wl);
let mut framed = HttpCodec::new().framed(fake);
let response = match framed.poll().unwrap() {
Async::Ready(Some(response)) => response,
_ => panic!("no response"),
};
assert_eq!(response.status().as_u16(), 200);
assert_eq!(response.headers().len(), 5);
assert_eq!(response.body(), &Bytes::from_static(b"something"));
}
Dependencies
~620KB
~11K SLoC