Adding test for readline failing on err
This commit is contained in:
parent
d5e8877eaf
commit
bebcfab52c
2 changed files with 25 additions and 2 deletions
|
|
@ -338,6 +338,15 @@ mod tests {
|
|||
client.read_greeting().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn readline_err() {
|
||||
// TODO Check the error test
|
||||
let mock_stream = MockStream::new_err();
|
||||
let mut client = create_client_with_mock_stream(mock_stream);
|
||||
client.readline().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_command() {
|
||||
let base_command = "CHECK";
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ use std::io::{Read, Result, Write, Error, ErrorKind};
|
|||
pub struct MockStream {
|
||||
read_buf: Vec<u8>,
|
||||
read_pos: usize,
|
||||
pub written_buf: Vec<u8>
|
||||
pub written_buf: Vec<u8>,
|
||||
err_on_read: bool
|
||||
}
|
||||
|
||||
impl MockStream {
|
||||
|
|
@ -11,13 +12,26 @@ impl MockStream {
|
|||
MockStream{
|
||||
read_buf: read_buf,
|
||||
read_pos: 0,
|
||||
written_buf: Vec::new()
|
||||
written_buf: Vec::new(),
|
||||
err_on_read: false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_err() -> MockStream {
|
||||
MockStream{
|
||||
read_buf: Vec::new(),
|
||||
read_pos: 0,
|
||||
written_buf: Vec::new(),
|
||||
err_on_read: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for MockStream {
|
||||
fn read(&mut self, buf: &mut[u8]) -> Result<usize> {
|
||||
if self.err_on_read {
|
||||
return Err(Error::new(ErrorKind::Other, "MockStream Error"))
|
||||
}
|
||||
if self.read_pos >= self.read_buf.len() {
|
||||
return Err(Error::new(ErrorKind::UnexpectedEof, "EOF"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue