use common::request::Request; use std::io::Cursor; const SAMPLE: [u8; 26] = [ 0x0, 0x3, b'F', b'o', b'o', 0x0, 0x4, b'B', b'a', b'z', b'0', 0x0, 0x5, b'x', b'x', b'x', b'y', b'y', 0x0, 0x6, b'1', b'7', b'0', b'1', b'-', b'a', ]; #[test] fn it_reads_requests() { let request = Request::from_stream(&mut Cursor::new(SAMPLE)).unwrap(); assert_eq!(request, Request::new("Foo", "Baz0", "xxxyy", "1701-a")); } #[test] fn it_writes_requests() { let request = Request::new("Foo", "Baz0", "xxxyy", "1701-a"); let mut buffer = Cursor::new(Vec::new()); request.write_to_stream(&mut buffer).unwrap(); // Should have written exactly 5 bytes assert_eq!(buffer.get_ref().len(), 26usize); assert_eq!(&buffer.get_ref()[0..26], SAMPLE); }