Skip to content

Commit

Permalink
test: add a chunk test
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrs committed Nov 15, 2023
1 parent 4c4680e commit ec12263
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,47 @@ mod test {

assert_eq!(q.len(), 2);
}

#[test]
fn emit_valid_chunks() {
struct Mock {
acc: RefCell<Vec<(Vec<u8>, String)>>,
}

impl Mock {
pub fn new() -> Mock {
Mock {
acc: RefCell::new(Vec::new()),
}
}
}

impl WriteRead for Mock {
fn write_and_read(&mut self, buf: &[u8], chunk: &str) -> Result<(), Error> {
let mut acc = self.acc.borrow_mut();
let args = (buf.to_vec(), chunk.to_string());
acc.push(args);
Ok(())
}
}

let emitter = Emitter::new("x".to_string());

for i in 1..1000 {
emitter.push((SystemTime::now(), vec![0x00, (i as u8).into()]));
}

let rw = &mut Mock::new();
emitter.emit(rw, Some(2)).unwrap();

let acc = rw.acc.borrow();
let chunks = acc
.iter()
.map(|(_, v)| general_purpose::STANDARD.decode(v).unwrap())
.collect::<Vec<Vec<u8>>>();

for chunk in chunks.iter() {
let _ = Uuid::parse_str(&String::from_utf8(chunk.clone()).unwrap()).unwrap();
}
}
}

0 comments on commit ec12263

Please sign in to comment.