Use insta for approval testing of binary output

29 Views Asked by At

I'm writing a library that will generate binary pdf-files based on some input. I'd like to use the insta crate since it seems to do basically what I want. However, it doesn't seem to support arbitrary binary files, just json/yaml and a few others.

This is what I have so far, which would technically work, but I can't review the actual pdf:

let mut content: Vec<u8> = vec![];
let Ok(x) = to_pdf(&document, &mut content) else { todo!() };

assert_eq!(x, ());
assert_debug_snapshot!("generated_document", &content)

Where to_pdf has this signature:

pub fn to_pdf(document: &Document, mut w: impl Write) -> Result<(), io::Error>

Is there a way to make it compare the content of generated pdf files while also outputting the pdf in a fairly easily reviewable form?

0

There are 0 best solutions below