Skip to content

Instantly share code, notes, and snippets.

@dmerejkowsky
Created September 27, 2018 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmerejkowsky/36a5fe4e2b8aaf0ef6b60ab2cb704383 to your computer and use it in GitHub Desktop.
Save dmerejkowsky/36a5fe4e2b8aaf0ef6b60ab2cb704383 to your computer and use it in GitHub Desktop.
actix unit test
fn body_contains(response: &HttpResponse, fragment: &str) -> bool {
// TODO: this looks really complicated. I must be missing something here :/
let body = response.body();
if let Binary(b) = body {
if let Bytes(bytes) = b {
let text = str::from_utf8(&bytes).unwrap();
return text.contains(fragment);
}
}
panic!("Expecting a binary response");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment